Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert bytearray to image or image to bytearray ?

How to assign bytearray value to panel background image. If anybody have idea or experiance plz help me to overcome the problem. BRIEF EXP:

I have panel control and want to load image getting from webservice as a backgroundimage. So i used setstyle() but its not accepting that image. so how to add that image into my panel background image.Plz tel me your ideas here.

like image 539
user57404 Avatar asked May 25 '09 13:05

user57404


People also ask

How do I convert an image to a ByteArray?

Read the image using the read() method of the ImageIO class. Create a ByteArrayOutputStream object. Write the image to the ByteArrayOutputStream object created above using the write() method of the ImageIO class. Finally convert the contents of the ByteArrayOutputStream to a byte array using the toByteArray() method.

How do you convert ByteArray?

There are two ways to convert byte array to String: By using String class constructor. By using UTF-8 encoding.

How do I create a ByteArray file?

In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file. Example: Java.

How do I convert a PDF to a ByteArray?

Convert PDF File to Byte Array using C#Load input PDF File. Initialize a Byte Array. Initialize FileStream object. Load the file contents in the byte array.


2 Answers

In Flex 3 or higher, you just need to do:

 yourImage.source = yourByteArray;

regards!

like image 75
Alex Rios Avatar answered Sep 28 '22 00:09

Alex Rios


uhm, well i presume, since it is an image, you have it in a BitmapData, let's say "myBmp" ... then use the following to extract all the data from BitmapData:

var bytes:ByteArray = myBmp.getPixels(myBmp.rect);

and the following to write:

myBmp.setPixels(myBmp.rect, bytes);

note that only the raw 32 bit pixel data is stored in the ByteArray, without compression, nor the dimensions of the original image.

for compression, you should refer to the corelib, as ozke said ...

like image 20
back2dos Avatar answered Sep 28 '22 00:09

back2dos