Your image is simply way too big. You should resize the Bitmap after loading it or, if it's a JPEG, rescale it at loading time. Take a look at BitmapFactory.Options to see how to do it.
Alternatively you could handle the screen rotation yourself but it will prevent you from using alternate resources. No matter what solution you pick, remember you can only allocate 16 MB of memory for your entire application and an image as big as the one you are talking about is probably using most of these 16 MB. On Mon, Dec 22, 2008 at 11:27 PM, mattsm8 <[email protected]> wrote: > > Thanks for helping Romain! > > I get an OutOfMemoryError on getDrawable(R.drawable.largeimage) > > > On Dec 22, 5:59 pm, Romain Guy <[email protected]> wrote: >> What is the crash exactly? What do you see in the logs? It sounds like >> you're having an OutOfMemory situation. >> >> >> >> On Mon, Dec 22, 2008 at 12:53 PM, mattsm8 <[email protected]> wrote: >> >> > I am trying to create an application which will display an image which >> > is larger than the screen of the device where the user can scroll >> > around to see different parts of the picture. This all works fine >> > until I open or close the keyboard on my G1 whereupon the application >> > crashes. Funnily enough it does not crash if only the orientation is >> > changed without opening or closing the keyboard. I reduced the >> > application to the bare minimum to try to see if I could work around >> > it in some way but it seems that as soon as I create an ImageView with >> > a large picture the memory is never released, even if I dereference >> > the ImageView object. Clearly there is something essential that I >> > don't understand here, could someone help, please? >> >> > A stripped down version of my app is below. I have created a standard >> > android application in Eclipse and modified the java file as below. >> > The drawable largeimage is a png file of 1.3mb. >> >> > package com.mattsm8.android.imagetest; >> >> > import android.app.Activity; >> > import android.os.Bundle; >> > import android.widget.ImageView; >> >> > public class ImageTest extends Activity { >> > ImageView iv = null; >> > @Override >> > public void onCreate(Bundle savedInstanceState) { >> > super.onCreate(savedInstanceState); >> > iv = new ImageView(this); >> > setContentView(iv); >> > iv.setImageDrawable(iv.getResources().getDrawable >> > (R.drawable.largeimage)); >> > setContentView(R.layout.main); >> > iv = null; >> > } >> > } >> >> -- >> Romain Guy >> Android framework engineer >> [email protected] >> >> Note: please don't send private questions to me, as I don't have time >> to provide private support. All such questions should be posted on >> public forums, where I and others can see and answer them > > > -- Romain Guy Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

