I was able to create a 720x480 byte array containing a bitmap of the French flag, send the byte array to my server, which in turn converted it to a jpg file, which I then displayed on my screen.
Here's the PHP code:
<?php
$owner = $_GET['owner'];
$sizex = $_GET['sizew'];
$sizey = $_GET['sizeh'];
$file_name = "$owner.jpg";
$in = fopen('php://input', 'r');
$im = imagecreatetruecolor($sizex, $sizey);
$y=0;
while($y < $sizey) {
$x=0;
while($x < $sizex) {
$thiscolor = imagecolorallocate($im, ord (fgetc ($in)), ord (fgetc ($in)), ord (fgetc ($in)));
imagesetpixel($im, $x, $y, $thiscolor);
fgetc ($in);
$x++;
}
$y++;
}
imagejpeg($im, $file_name);
imagedestroy($im);
?>
And the BrightScript code:
Sub Main ()
width = 720
height = 480
owner = "sqwiril"
' Make an image of the French flag and convert to an roByteArray
byteArray = MakeByteArray (width, height)
' Send the byte array to the server for conversion to a jpg file
Convert (byteArray, owner, width, height)
' Display the image
Display (owner)
End Sub
Function MakeByteArray (width As Integer, height As Integer) As Object
byteArray = CreateObject ("roByteArray")
byteArray.SetResize (width * height * 4, False)
i = 0
For x = 0 To height - 1
For y = 0 To width - 1
If y < CInt (width / 3)
r = 0 : g = 0 : b = 255 : a = 255
Else If y < CInt (width * 2 / 3)
r = 255 : g = 255 : b = 255 : a = 255
Else
r = 255 : g = 0 : b = 0 : a = 255
EndIf
byteArray [i + 0] = r
byteArray [i + 1] = g
byteArray [i + 2] = b
byteArray [i + 3] = a
i = i + 4
End For
End For
Return byteArray
End Function
Function Convert (byteArray As Object, owner As String, width As Integer, height As Integer) As Void
' Convert the byte array to a file
byteArray.WriteFile ("tmp:/byteArray")
' Send file to server
ut = CreateObject ("roUrlTransfer")
port = CreateObject ("roMessagePort")
ut.SetPort (port)
ut.SetUrl ("http://belltown.tk/bigimage.php?owner=" + owner + "&sizew=" + width.ToStr () + "&sizeh=" + height.ToStr ())
If Not ut.AsyncPostFromFile ("tmp:/byteArray")
Print "AsyncPostFromFile failed"
Stop
EndIf
msg = Wait (0, port)
If msg = Invalid
Print "Image upload timed out"
Stop
Else If Type (msg) <> "roUrlEvent"
Print "Unknown event"
Stop
Else If msg.GetResponseCode () <> 200
Print "Http Failure"; msg.GetResponseCode ()
Stop
Else
Print "File upload successful"
EndIf
End Function
Function Display (owner As String) As Void
url = "http://belltown.tk/" + owner + ".jpg"
ui = CreateObject ("roImageCanvas")
port = CreateObject ("roMessagePort")
ui.SetMessagePort (port)
ui.SetRequireAllImagesToDraw (True)
ui.SetLayer (0, {Url: url})
ui.Show ()
Wait (0, port)
End Function