build a picture (bitmap) from an array of bytes (from .ZIP)

All your problems with Audio, Video and Images.

build a picture (bitmap) from an array of bytes (from .ZIP)

Postby guian » Wed Dec 03, 2008 9:38 am

Hi guys!

I'm looking for a way to build a picture from an array of bytes

here is the way I use to store my picture (read from a ZIP file) into a byte[] :


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  final ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
  3.  
  4.        
  5.  
  6.  
  7.  
  8.                 ZipEntry ze;
  9.  
  10.                 byte buf[];
  11.  
  12.                 // on all the files from the zip.
  13.  
  14.                 while (null != (ze = zis.getNextEntry())) {
  15.  
  16.  
  17.  
  18.                         buf = new byte[(int)ze.getSize()];
  19.  
  20.                        
  21.  
  22.                         int off = 0;                    // start writing
  23.  
  24.                         int len = buf.length;   // number of byte to write
  25.  
  26.                         int read = 0;                   // number of read elements
  27.  
  28.                        
  29.  
  30.                         while ( (len>0) && (read = zis.read(buf, off, len))>0 ) {
  31.  
  32.                                 off += read;
  33.  
  34.                                 len -= read;
  35.  
  36.                         }
  37.  
  38.                         //then I store "buf" for each file I wanna keep in memory
  39.  
  40.         }
  41.  
  42.  
  43.  
  44.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


This code works very well for a text file, I can read and display it...

I get my picture back using :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Bitmap bitmap = BitmapFactory.decodeByteArray(buf,0,buf.length);
  3.  
  4.  
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


but the resulting picture is altered. It looks like it miss some pixels and the picture is leaning.
(if it miss 3 pixels on each lines, then the second line is 6 pixels moved, then 9 etcaetera... so the picture is leaning and the last horizontal line of pixels is uncomplete (it finish with black))
Am I clear ?

Do you know the reason of this bug? I guess I do something wrong ...
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Top

Postby guian » Thu Dec 04, 2008 2:41 pm

new data:

I can get back my picture by writing it in an existing file "/data/tmp.jpg" using :


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.         File tmp = new File("/data/tmp.jpg");
  5.  
  6.         if(tmp.exists()) {
  7.  
  8.                 FileOutputStream toto= new FileOutputStream(tmp);
  9.  
  10.                 toto.write(AFAveGlobalDataStore.files.get(currentScene.getFileName()));
  11.  
  12.         }
  13.  
  14.  
  15.  
  16.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


so the problem come probably from the "BitmapFactory.decode" method...

can somebody help me ?
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Postby guian » Thu Dec 04, 2008 4:47 pm

the probleme was: I tried to use this picture as an OpenGL texture
but, its width was 1023 with is not a power of 2...
it works with the same picture, reSize to 1024.
guian
Developer
Developer
 
Posts: 35
Joined: Tue Nov 18, 2008 3:43 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 8 guests