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[] :


Java source code:
------------------------------------------------------------------------------------------------------
 final ZipInputStream zis = new ZipInputStream(new FileInputStream
(file));


          ZipEntry ze;
          byte buf[];
             // on all the files from the zip.
             while (null != (ze = zis.getNextEntry())) {

               buf = new byte[(int)ze.getSize()];

               int off = 0;             // start writing
               int len = buf.length;    // number of byte to write
               int read = 0;            // number of read elements

               while ( (len>0) && (read = zis.read(buf, off, len))>0 )
{
                    off += read;
                    len -= read;
               }
                //then I store "buf" for each file I wanna keep in
memory
        }
------------------------------------------------------------------------------------------------------


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

I get my picture back using :
Java source code:
------------------------------------------------------------------------------------------------------
Bitmap bitmap = BitmapFactory.decodeByteArray(buf,0,buf.length);
------------------------------------------------------------------------------------------------------

but the resulting picture is altered. It looks like it miss some
pixels and the picture is leaning.
(if it miss 50 pixels on each lines, then the second line is 100
pixels moved, then 150 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 also tried to get my picture back through an InputStrem:

JAVA source code:
------------------------------------------------------------------------------------------------------
InputStream is = new ByteArrayInputStream(buf);
Bitmap bitmap = BitmapFactory.decodeStream(is);
------------------------------------------------------------------------------------------------------

but I got the same result.


My array of bytes is correct, I can get my picture  back by writing it
in an existing file "/data/tmp.jpg" using :

Java source code:
------------------------------------------------------------------------------------------------------

     File tmp = new File("/data/tmp.jpg");
     if(tmp.exists()) {
          FileOutputStream toto= new FileOutputStream(tmp);
          toto.write(buf);
     }
------------------------------------------------------------------------------------------------------


so the problem come probably from the "BitmapFactory.decode*()"
methods...

can somebody help me ?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to