• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

load a jpg image from bytearray

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


I am trying to load a png image file from a byte array(from stream) and got this error :

01-09 12:01:24.664: E/AndroidRuntime(14031): java.lang.OutOfMemoryError
01-09 12:01:24.664: E/AndroidRuntime(14031): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
01-09 12:01:24.664: E/AndroidRuntime(14031): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)


My code is :
ByteArrayOutputStream out = new ByteArrayOutputStream(ByteWritten);
byte[] actual_bytes = new byte[1024];
long count = 1024;
long off = 0;

while((actual_bytes = solstream.readWithSeek(off,count))!=null) // this is virtual space stream where the image file is stored
{
off=off+actual_bytes.length;
out.write(actual_bytes,0,actual_bytes.length);
}

out.flush();
out.close();

byte[] final_ba = out.toByteArray();

bitmap = BitmapFactory.decodeByteArray(final_ba,0,final_ba.length);


image = (ImageView) findViewById(R.id.rtimageView);
image.setImageBitmap(bitmap);



Thanks in advance.
Swapna.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How big is the image? Does the exception occur during the toByteArray() call?
 
swapna nyathani
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Image details:

Dimensions: 250*158
Horizontal resolution: 72 dpi
Horizontal resolution: 72 dpi

size on disk: 24 kb


Exception occurs at this line
"out.write(actual_bytes,0,actual_bytes.length); "


Swapna.

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a small image. Have your tried adding up and logging the number of bytes you're reading from the image (in effect logging the value of "off" at each loop iteration)? After how many bytes does the OOME occur?
 
swapna nyathani
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

01-10 06:36:21.008: E/dalvikvm-heap(1386): Out of memory on a 25133072-byte allocation.





 
reply
    Bookmark Topic Watch Topic
  • New Topic