The simplest way to send an image from Flash to PHP without user interaction

With the FileReference class, it is quite easy to send an image to the server. But it requires user interaction. What if you need to send an image the user has drawn or captured form the webcam? Then send the data as a ByteArray and let the PHP save the raw data.

The bitmapdata of the image must be encoded to jpg or png and Adobe has classes for that: com.adobe.images.PNGEncoder and com.adobe.images.JPGEncoder. The contentType of the request must be ”application/octet-stream” and if you want to send parameters (file format, username, etc.), add them to the url as parameters: ”simpleSaveImage.php?fileformat=png&filename=cheetach.png”.

In the source files I’m using my ContentLoader to send the data. The sendBytes method  handles everything for you, but here’s also a summary of how to do it without the ContentLoader:
Jatka lukemista ”The simplest way to send an image from Flash to PHP without user interaction”

Ignoring black frames while starting a webcam

While playing with motion detection with a Webcam, I ran into a surprising problem. First n frames are 100% black. The number of frames vary, so this problem wasn’t solved with ignoring first 10 frames or anything similar. So I used getColorBoundsRect to detect any non-black pixels and when found, the WebCam class would start to send an event. The video will be visible before dispatching events, but it could be hidden until the event is dispatched. Jatka lukemista ”Ignoring black frames while starting a webcam”