This is a common problem when using the BimapFactory.decode, there
is a bug or memory leak. We've had lengthy discussions about this in
previous threads. Using smaller bitmaps, using bitmap.recycle(), and
turning down the sample size can mitigate, but not eliminate this
problem.
Mark
On Mar 25, 2:05 pm, George <[email protected]> wrote:
> I wrote a sample application which rotates and scales a bitmap on
> clicking a key. When the bitmap is large (1280x1024) I quickly run
> into an OutOfMemory exception at CreateBitmap and I need to Force
> Close the application. No issues with smaller bitmaps.
>
> I have already tried using bitmap.recycle and setting the bitmap to
> null, but the memory does not get freed up. I have seen multiple posts
> with similar issues, but could not find one that solves my issue. Do I
> need to force the GC at some point? Here is the code I am using:
>
> public class TransformAndroid extends Activity {
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> LinearLayout linLayout = new LinearLayout(this);
>
> mBitmapOrg = BitmapFactory.decodeResource(getResources(),
> R.drawable.sample);
>
> mScaleWidth = 0.1f;
> mScaleHeight = 0.1f;
> mRotateAngle = 0;
>
> mImageView = new ImageView(this);
>
> TransformThePicture();
>
> // center the Image
> mImageView.setScaleType(ScaleType.CENTER);
>
> // add ImageView to the Layout
> linLayout.addView(mImageView,
> new LinearLayout.LayoutParams(
> LayoutParams.FILL_PARENT,
> LayoutParams.FILL_PARENT
> )
> );
>
> // set LinearLayout as ContentView
> setContentView(linLayout);
>
> }
>
> private void TransformThePicture()
> {
> Matrix matrix = new Matrix();
> matrix.postScale(mScaleWidth, mScaleHeight);
> matrix.postRotate(mRotateAngle);
>
> int width = mBitmapOrg.getWidth();
> int height = mBitmapOrg.getHeight();
>
> mResizedBitmap = Bitmap.createBitmap(mBitmapOrg, 0, 0,
> width, height, matrix, true);
>
> mImageView.setImageBitmap(mResizedBitmap);
> mImageView.invalidate();
>
> }
>
> public boolean onKeyDown(int keyCode, KeyEvent event) {
> if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
>
> mScaleWidth += 0.08;
> mScaleHeight += 0.05;
> mRotateAngle += 5;
>
> if (mScaleWidth >= 1.0f) mScaleWidth = 0.1f;
> if (mScaleHeight >= 1.0f) mScaleHeight = 0.1f;
> if (mRotateAngle >= 90) mRotateAngle = 0;
>
> mResizedBitmap.recycle();
> TransformThePicture();
>
> return (true);
> }
>
> return super.onKeyDown(keyCode, event);
> }
>
> private Bitmap mBitmapOrg;
> private float mScaleWidth;
> private float mScaleHeight;
> private int mRotateAngle;
> private ImageView mImageView;
> private Bitmap mResizedBitmap;
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---