This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

OutOfMemoryError... Whats the solution?  RSS feed

 
Ranch Hand
Posts: 48
1
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I am developing an application into which I had to capture an image from the camera and send that Image to a web-service for authentication in the form of byte[]. I got stuck with the camera orientation problem as the preview was coming only in landscape mode. Finally when I solved that, I found that the Image captured comes rotated anti-clockwise when clicked in Portrait mode.

So I thought to capture the image, rotate it, and reconvert it to byte[]. But finally when I am trying to convert the Image, I am getting an OutOfMemoryError, Bitmap exceeds VM budget.

Could you please help me to get out of this? How can I solve it? I have tried to free as much references as I could.

Here is the code below...


Here is the code of the method streamToBytes()...


I have attached the error message in 2 image files...

Waiting for help pals...

Thank you.

2.JPG
[Thumbnail for 2.JPG]
The error message
1.JPG
[Thumbnail for 1.JPG]
See the freed objects...
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might take a look at "http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/PurgeableBitmapView.html" and specifically how they handle the OutOfMemoryError exception.

Also, "http://developer.android.com/reference/java/lang/ref/SoftReference.html".

Honestly not sure if this will help your particular situation or not, but it seemed informative/worth a read.
 
Ranch Hand
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can reduce image size by using BitmapFactory.Options



set options.inSampleSize to some what higher value p(i.e 5) which means high compression that will take care of OutofMemory.
this worked for me.

thanks
 
Vishal Srivastav
Ranch Hand
Posts: 48
1
Java Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, even after reducing the size of the image to 1/3, the same error is coming.

When I am using the application to click the pic in LANDSCAPE mode, then no error is coming, and what I saw is automatically Image captured has size in KBs. In the sama application, when I am converting the same byte[] to write an image, that Image is at least of size 3.5+ MB.

Decreasing the size of the image to 1/3rd of original is not solving the matter.

Please help.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!