0

It most like this question:How to convert View to Bitmap in android?. And my way is:

Bitmap bitmap = null;
int viewWidth = view.getWidth();
int viewHeight = view.getHeight();
bitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;

But there's a OutofMemory may happen in createBitmap(), so I want to scale the bitmap's size. Like this:

bitmap = Bitmap.createBitmap(viewWidth / 4, viewHeight / 4, Bitmap.Config.RGB_565);

Now the question is:

How can I draw view to the scaled bitmap?

Thanks a lot.

Community
  • 1
  • 1
user3875388
  • 541
  • 1
  • 6
  • 19

1 Answers1

0

What kind of view is that? is it larger than the screen? From my experience there should be enough memory available to create a buffer the size of the screen. Did you check if there are other leaks in your app? Try to analyze your memory usage with the Android Device Monitor. As a last resort try to do a garbage collection System.gc() before allocating the bitmap.

Clemens
  • 86
  • 8
  • The view is not larger than screen.Because I had filter this. 'If the view's is larger than screen, return null direct". – user3875388 Mar 26 '15 at 09:36
  • If you really have no memory (what I would investigate) and to answer the question how to scale the view to the bitmap: Use the Canvas translate and scale methods. See related [post](http://stackoverflow.com/questions/8198088/android-canvas-scale-translate-and-positing) – Clemens Mar 26 '15 at 18:45
  • Thank you.There is a memory leak in my app. – user3875388 Apr 22 '15 at 06:33
  • cool so no need for scaling any more? please mark the answer as correct if this is the case – Clemens May 21 '15 at 21:36