Casting/Converting to JPEG

I’ve been modifying some basic web server code on my Spider to share out an image. I find the image load (BMP format) is painfully slow and decided to pump it out as a JPEG. So far I’m modifying the basic picture by creating a Microsoft.SPOT.Bitmap and drawing on it, then puttting it back into a Gadgeteer.Picture so that I can use the WebServer responder, I’ve attached the bulk of the code, but currently I get nothing back.


void camera_PictureCaptured(Camera sender, GT.Picture picture) //camera handler for post picture captured
        {
            bmap = picture.MakeBitmap();
            bmap.DrawText(strDateTime, MyFont, Color.Black, 1, 1); //draw DTG over the image
            bmap.DrawText(strDateTime, MyFont, Color.White, 0, 0);          
            display.SimpleGraphics.DisplayImage(bmap, 0, 0);
}


… some more code… This bit handles serving out the image


        void seePicture_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            if (bmap != null)
            {
                pic = new GT.Picture(bmap.GetBitmap(), GT.Picture.PictureEncoding.JPEG);
                responder.Respond(pic);
            }
            else
                responder.Respond("Take picture first");
        }

I’ve even tried the MIME type way with


responder.Respond(pic,"image/jpeg");

but all I get is the broken image icon in my web browser. If I revert to just showing the original captured GT.Picture everything works fine. I’ve debugged and looked at locals and they all look right but it would seem as though something is breaking within responder. No exceptions on running either.

You can send jpeg image that you already have but can’t encode it unless you implement this using RLP.

How about taking a Microsoft.SPOT.Bitmap and getting it out as a GT.Picture (GT=Gadgeteer). I tried to do that as well and got nothing. It’s like the responder doesn’t like the byte stream or something.

The code would have looked like this,


            bmap = picture.MakeBitmap();
            bmap.DrawText(strDateTime, MyFont, Color.Black, 1, 1); //draw DTG over the image
            bmap.DrawText(strDateTime, MyFont, Color.White, 0, 0);

At this point I’ve got a valid bitmap, now to the Picture part,


                pic = new GT.Picture(bmap.GetBitmap(), GT.Picture.PictureEncoding.BMP);
                responder.Respond(pic);

Shouldn’t that work? I get nothing on the output.

Never tried that function and not sure how it works. GHI premium library have a bitmap function you need

silly question, but how to I roll the premium libraries for my spider into the project? I’m assuming it’s just a reference but I can’t seem to find it. Looking at tutorials now.

EDIT - I see it’s in the GHIElectronics.NETMF libraries that are already in my project. It looks like the API set is bigger for the Spider and I see the Bitmap stuff in utils. Thanks for the tip.

Yes, if using spider you already have premium libs

Gus, I got em. I may port FJCore over to run on .NETMF I wouldn’t require RLP, but it looks like it would be pretty big compiled. Probably slow as heck. I’ll give it a few hours and see how far I get.

JPEG encoding in C# is a terrible idea :slight_smile: Will take long minutes (maybe hours) to encode on these small devices.

Jr see my post on PNG decompression in manage on a Hydra. More powerful than a Spider and take over 5 min for 160x160

thanks for the update. I’ll pass on doing it in C#. I’ll check your post.

UPDATE - looks like I’m going to try an RLP. I’ll post it once I’m done.