Results 1 to 4 of 4
Thread: Bufferedimage to Byte[]
- 03-06-2012, 10:55 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Bufferedimage to Byte[]
Hi,
i've found code by google to convert bufferedimage to byte[] :
and another one :Java Code:private byte[] image_byte_data(BufferedImage image) { WritableRaster raster = image.getRaster(); DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer(); return buffer.getData(); }
i want to get byte[] from bufferedimage, then do some process that may make values of byte[] changes.Java Code:BufferedImage originalImage = ImageIO.read(new File("c:\\image\\mypic.jpg")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write( originalImage, "jpg", baos ); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close();
after that process, i'ill get new byte[] values, then i want to create new bufferedimage from that image and show it as image.
which code is fit with my problem.
and what difference between both above.
- 03-06-2012, 11:53 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Bufferedimage to Byte[]
The former byte[] is the actual image.
The latter byte[] is the jpg (ie compressed) image.
The former is the one you want to use for manipulating an image.Please do not ask for code as refusal often offends.
- 03-06-2012, 03:54 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: Bufferedimage to Byte[]
thanks for reply,
when i try getting byte[] with the first code above,
i've got a huge byte[] in string.
* i write the byte[] to file text,
is it because with former code, i get raster data (contain Alpha, Red, Green, Blue color)?
one pixel will represent as block of 4 byte of color.
is it true?
actually, i want to do some encryption process that encrypt plain-image to cipher-image.
so i need convert plain-image to byte[].
but after i encrypt the byte[], i must get byte[] that can be represent as image.
is it possible right()?
Thanks in advance
- 03-06-2012, 04:01 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Bufferedimage to Byte[]
The former is the image data that the JVM uses to display, so it is uncompressed (as you say).
No point writing that to a file as it's not necessarily a recognised file format.
Don't know anything about creating cipher images.Please do not ask for code as refusal often offends.
Similar Threads
-
convertir byte array "byte[]" to an image in j2me
By skon in forum New To JavaReplies: 1Last Post: 10-21-2011, 11:55 AM -
Read a bitmap byte by byte
By cbr400aero in forum Java 2DReplies: 2Last Post: 10-18-2010, 11:42 PM -
Streaming an image byte by byte (and similtaneosly rendering it on screen)
By ea25 in forum New To JavaReplies: 1Last Post: 04-21-2010, 02:28 AM -
Convert Byte [] to BufferedImage
By Smily in forum Advanced JavaReplies: 3Last Post: 04-28-2008, 05:54 PM -
BufferedImage to Byte
By Java Tip in forum Java TipReplies: 0Last Post: 01-22-2008, 08:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks