7 Replies Latest reply: Apr 14, 2013 10:43 PM by Flex harUI RSS

    Displaying an image with RGB data

    PastaPrimavera Community Member

      I am by far no pro with Flex 4.6.  Unfortunatly for me my image sourfce file only comes in .bmp format. Since Flex does not accept that format i need a work arround.

      I am using loader.load to get its source image from an embedded device so please dont tell me to convert it beforehand or why in the world am i using .bmp as i have seen in so many threads. I can however send up the RGB values of the .bmp image for every pixel to flex if that help in some way. 

      OR another way to put it, say i have an array of a 10x10 pixel image in RGB format. Can i display this somehow as an image ?

       

      Thank you

        • 1. Re: Displaying an image with RGB data
          Flex harUI Adobe Employee

          Create a BitmapData and set that as the bitmapData of a Bitmap.

          • 2. Re: Displaying an image with RGB data
            PastaPrimavera Community Member

            Thank you for the help.  This next part of it may be for another post. If not here goes.

            I have the following new code see below.

             

            I am not sure how to ask properly as i dont know the lingo. For example pourposes and to help me get a better understanding.

            My image in this code is 50x50. If i wanted to try it out using my RGB data, i am going to assume that i would have to put that data into an array.

            How would i take this array variable and tell img to use it ?

             

             

             

            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                           xmlns:s="library://ns.adobe.com/flex/spark"

                           xmlns:mx="library://ns.adobe.com/flex/mx"

                                         

                           creationComplete="handleCreationComplete();">

               

                <fx:Script>

             

                    <![CDATA[

                       

                        import mx.graphics.BitmapFillMode;

                       

                        private function handleCreationComplete():void

                           

                        {

                           

                            var loader:Loader = new Loader();

                           

                            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,handleLoadComplete);

                           

                            loader.load( new URLRequest('http://192.168.0.15/image.gif' ) );

                           

                        }

                       

                        private function handleLoadComplete( evt:Event ):void

                        {

                           

                            var bmp:Bitmap = ( evt.target as LoaderInfo ).content as Bitmap;

                           

                            img.source = bmp;

                           

                        }

                       

                    ]]>

                   

                </fx:Script>

               

                <s:Image id="img" x="37" y="34" width="50" height="50"/>

               

               

            </s:Application>

            • 3. Re: Displaying an image with RGB data
              Flex harUI Adobe Employee

              I’m not quite sure I understand this last question as it loads a .gif and I thought the issue is that you want to load a .bmp file.

               

              If that’s true, you have some choices:  You can load the entire bmp file as a Base64 encoded entity, and decode it in the app, parse the pixels out of the BMP file format, or you can pull the RGB values out of the  BMP file on the server and send a text blob of RGB encoded data.

               

              Let’s say you choose the latter, and the data is for a 2x2 icon and you send it in the order of (0,0), (1, 0), (0, 1), (1,1) and the text looks like: “0xFF0000,0x00FF00,0x0000FF,0xFF00FF”

               

              In the app, you would load that with URLLoader and not Loader and do something like:

               

              Var pixels:Array = urlLoader.data.split(“,”);

              Var pixelba:ByteArray = new ByteArray();

              For each (var p:String in pixels)

              {

                  var px:int = int(p);

                  pixelba.writeInt(px);

              }

              Pixelba.posiiton = 0;

              Var bm:Bitmap = new Bitmap();

              Var bmd:BitmapData = new BitmapData(2, 2);

              Bmd.setPixels(ba);

              Bm.bitmapdata = bmd;

              • 4. Re: Displaying an image with RGB data
                PastaPrimavera Community Member

                I got it working now, Thank you very much for your time.

                • 5. Re: Displaying an image with RGB data
                  Flex harUI Adobe Employee

                  Ah yes, forgot an argument.  Should be something like:

                   

                      bmd.setPixels(new Rectangle(0,0,2,2), ba);

                  • 6. Re: Displaying an image with RGB data
                    PastaPrimavera Community Member

                    Just curious, the "ba" is what threw me.

                    • 7. Re: Displaying an image with RGB data
                      Flex harUI Adobe Employee

                      Ah, sorry, should have been pixelba