Transfer images from .NET to Flash

View: New views
3 Messages — Rating Filter:   Alert me  

Transfer images from .NET to Flash

by Alexandre Silva-4 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hello.

 

I’ve been trying to transfer bitmap images between server<->client.

 

From Client to Server I was successful, following this website:

http://blog.bsoares.com.br/tag/fluorinefx

 

But from the Server to the Client, I always get a “Type Coercion failed: cannot convert (…) to flash.utils.ByteArray.”

 

The code in the server-side:

 

        private Byte[] BitmapToBytes(Bitmap bitmap)

        {

            try

            {

                Byte[] byteArray;

                using (MemoryStream ms = new MemoryStream())

                {

                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

                    byteArray = ms.ToArray();

                }

                return byteArray;

            }

            catch (Exception ex)

            {

                return new Byte[1];

            }

        }

 

And in client side I receive the exact same byte[] (I checked the length and some values and they matched), but I cannot cast it into a ByteArray object.

 

I tried several options, simply making a cast, or using the result already as a ByteArray but it always throws that exception.

Also I tried converting the object to ByteArray using:

 

bytes.writeObject( result.Image );

 

But then, I get another bytearray and the Loader does not recognize it as an image.

 

 

Can anyone help me?? I can’t find information on the internet about passing an image from .NET server to flash client!!

I’m using AMF3 in FlourineFX…

 

 

PS – Please moderators disregard my previous post, as this email account was not registered yet, so the post was waiting for approval…

 

 


_______________________________________________
fluorine mailing list
fluorine@...
http://fluorine.thesilentgroup.com/mailman/listinfo/fluorine_fluorine.thesilentgroup.com

Re: Transfer images from .NET to Flash

by philmk :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

You can try this:

 

        public static function toBitmapData( width : Number, height : Number, ba : ByteArray ) : BitmapData

        {

            if(ba == null) return null;

           

            var bd : BitmapData = new BitmapData( width, height, true);

            try

            {

                  ba.position = 0;

                  var u:uint;

                  for( var i:uint=0; i<bd.width ; i++ )

                    for( var j:uint=0; j<bd.height; j++ )

                      bd.setPixel32( i, j, ba.readUnsignedInt() );

                     

            } catch (err:Error)     {

                        trace("toBitmapData: " + err.message);

                  }

            return bd;

        }

 

 

You need to know the width and height of the image, and you recreate the image from the bytes like so:

                             

      var data:BitmapData = toBitmapData(width, height, imageData);

      return new Bitmap(data);

 

 

 

From: fluorine-bounces@... [mailto:fluorine-bounces@...] On Behalf Of Alexandre Silva
Sent: 04 November 2009 12:13
To: fluorine@...
Subject: [Fluorine] Transfer images from .NET to Flash

 

Hello.

 

I’ve been trying to transfer bitmap images between server<->client.

 

From Client to Server I was successful, following this website:

http://blog.bsoares.com.br/tag/fluorinefx

 

But from the Server to the Client, I always get a “Type Coercion failed: cannot convert (…) to flash.utils.ByteArray.”

 

The code in the server-side:

 

        private Byte[] BitmapToBytes(Bitmap bitmap)

        {

            try

            {

                Byte[] byteArray;

                using (MemoryStream ms = new MemoryStream())

                {

                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

                    byteArray = ms.ToArray();

                }

                return byteArray;

            }

            catch (Exception ex)

            {

                return new Byte[1];

            }

        }

 

And in client side I receive the exact same byte[] (I checked the length and some values and they matched), but I cannot cast it into a ByteArray object.

 

I tried several options, simply making a cast, or using the result already as a ByteArray but it always throws that exception.

Also I tried converting the object to ByteArray using:

 

bytes.writeObject( result.Image );

 

But then, I get another bytearray and the Loader does not recognize it as an image.

 

 

Can anyone help me?? I can’t find information on the internet about passing an image from .NET server to flash client!!

I’m using AMF3 in FlourineFX…

 

 

PS – Please moderators disregard my previous post, as this email account was not registered yet, so the post was waiting for approval…

 

 


_______________________________________________
fluorine mailing list
fluorine@...
http://fluorine.thesilentgroup.com/mailman/listinfo/fluorine_fluorine.thesilentgroup.com

Parent Message unknown Re: Transfer images from .NET to Flash

by Alexandre Silva-4 :: Rate this Message:

Reply (Restricted by the Administrator) | Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Thank you Philip,

 

Actually I discovered that the problem is that the byte[] is not well converted no ByteArray. Meaning the problem is before the conversion to bitmap…

What I am doing now is receiving an Object (instead of ByteArray) and manually convert it to Bitmap using your method.

 

It’s good for now, but I have to come back to this issue later… I can’t understand why the byte[] is not well received (as a ByteArray) in Flash…

I also tried to transfer from server a FluorineFx.AMF3.ByteArray object, but I get an error in Flash NetConnecion upon receiving the result…

 

I found some examples in FluorineFX sample directory that transfer ByteArray so I’ll try to start from there…

 

Thanks anyway for the help!

 

Alexandre Silva

asilva@...

 


From: fluorine-bounces@... [mailto:fluorine-bounces@...] On Behalf Of Philip McKeown
Sent: quarta-feira, 4 de Novembro de 2009 12:37
To: 'Fluorine Mailing List'
Subject: Re: [Fluorine] Transfer images from .NET to Flash

 

You can try this:

 

        public static function toBitmapData( width : Number, height : Number, ba : ByteArray ) : BitmapData

        {

            if(ba == null) return null;

           

            var bd : BitmapData = new BitmapData( width, height, true);

            try

            {

                  ba.position = 0;

                  var u:uint;

                  for( var i:uint=0; i<bd.width ; i++ )

                    for( var j:uint=0; j<bd.height; j++ )

                      bd.setPixel32( i, j, ba.readUnsignedInt() );

                     

            } catch (err:Error)     {

                        trace("toBitmapData: " + err.message);

                  }

            return bd;

        }

 

 

You need to know the width and height of the image, and you recreate the image from the bytes like so:

                             

      var data:BitmapData = toBitmapData(width, height, imageData);

      return new Bitmap(data);

 

 

 

From: fluorine-bounces@... [mailto:fluorine-bounces@...] On Behalf Of Alexandre Silva
Sent: 04 November 2009 12:13
To: fluorine@...
Subject: [Fluorine] Transfer images from .NET to Flash

 

Hello.

 

I’ve been trying to transfer bitmap images between server<->client.

 

From Client to Server I was successful, following this website:

http://blog.bsoares.com.br/tag/fluorinefx

 

But from the Server to the Client, I always get a “Type Coercion failed: cannot convert (…) to flash.utils.ByteArray.”

 

The code in the server-side:

 

        private Byte[] BitmapToBytes(Bitmap bitmap)

        {

            try

            {

                Byte[] byteArray;

                using (MemoryStream ms = new MemoryStream())

                {

                    bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

                    byteArray = ms.ToArray();

                }

                return byteArray;

            }

            catch (Exception ex)

            {

                return new Byte[1];

            }

        }

 

And in client side I receive the exact same byte[] (I checked the length and some values and they matched), but I cannot cast it into a ByteArray object.

 

I tried several options, simply making a cast, or using the result already as a ByteArray but it always throws that exception.

Also I tried converting the object to ByteArray using:

 

bytes.writeObject( result.Image );

 

But then, I get another bytearray and the Loader does not recognize it as an image.

 

 

Can anyone help me?? I can’t find information on the internet about passing an image from .NET server to flash client!!

I’m using AMF3 in FlourineFX…

 

 

PS – Please moderators disregard my previous post, as this email account was not registered yet, so the post was waiting for approval…

 

 


_______________________________________________
fluorine mailing list
fluorine@...
http://fluorine.thesilentgroup.com/mailman/listinfo/fluorine_fluorine.thesilentgroup.com