[android-developers] createBitmap causes an outofmemory error

2010-11-08 Thread sharktiger
Hi,
In my app, I am creating a bitmap from its colors code like this :

int width=getImageWidth();
int height=getImageHeight();
int[] array=getbitmap();
int[] colorsAsIntegers = new int[width*height];
int i = 0;
int j = 0;

while (iwidth*height*4) {
colorsAsIntegers[j] = Color.argb(array[i], array[i+1], array[i+2],
array[i+3]);
i += 4;
j++;
}

myBitmap=Bitmap.createBitmap(colorsAsIntegers,
width,
height,
Bitmap.Config.ARGB_);

And often I get the outofmemoryerror :(
So how can I use the BitmapFactory optimisation to avoid this problem?
because I don't have an input stream or a file, I only have an array
containing my pixels

Thank you

-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] createBitmap causes an outofmemory error

2010-11-08 Thread Kumar Bibek
Each application has a cap on how much memory it can be allocated. If you go
beyond this, you will get this exception.

Try creating a Bitmap with smalled dimensions.

On Fri, Nov 5, 2010 at 7:22 PM, sharktiger hsoumi.me...@gmail.com wrote:

 Hi,
 In my app, I am creating a bitmap from its colors code like this :

 int width=getImageWidth();
 int height=getImageHeight();
 int[] array=getbitmap();
 int[] colorsAsIntegers = new int[width*height];
 int i = 0;
 int j = 0;

 while (iwidth*height*4) {
 colorsAsIntegers[j] = Color.argb(array[i], array[i+1], array[i+2],
 array[i+3]);
 i += 4;
 j++;
 }

 myBitmap=Bitmap.createBitmap(colorsAsIntegers,
 width,
 height,
 Bitmap.Config.ARGB_);

 And often I get the outofmemoryerror :(
 So how can I use the BitmapFactory optimisation to avoid this problem?
 because I don't have an input stream or a file, I only have an array
 containing my pixels

 Thank you

 --
 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
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com

-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en