Bitmap newBmap = Bitmap.createBitmap(bmap, 0, 0, bmap.getWidth(), bmap.getHeight(), mx, true);
Activity中没有其他资源了,bmap的图片也很小,为什么新的bmap对象 会出现内存超出呢?

解决方案 »

  1.   

    换过N张了,png,直接用bmp的图都会错图片10kb以下。
      

  2.   

    Bitmap newBmap = Bitmap.createBitmap(bmap, 0, 0, bmap.getWidth(), bmap.getHeight(), mx, true);
    package com.ImagesZoom;import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Matrix;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.RelativeLayout;public class ImagesZoom extends Activity {
        private Button amplify ;
        private Button narrow;
        private ImageView viewer;
        private Bitmap bmap;
        private RelativeLayout layout;
        
        
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            //init
            amplify = (Button) findViewById(R.id.big);
            narrow = (Button) findViewById(R.id.small);
            layout = (RelativeLayout) findViewById(R.layout.main);
            viewer = (ImageView) findViewById(R.id.viewer);
            bmap = BitmapFactory.decodeResource(getResources(), R.drawable.cc);
            
            
            viewer.setImageBitmap(bmap); 
            amplify.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
    ImagesZoom.this.amplify(1.25f);
    }
    });
            
            narrow.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
    ImagesZoom.this.narrow(0.8f);

    }
    });
        }
        
        private void amplify(float f){
         Matrix mx = new Matrix();
         mx.setScale(bmap.getWidth() * f, bmap.getHeight() * f);
         Bitmap newBmap = Bitmap.createBitmap(bmap, 0, 0, bmap.getWidth(), bmap.getHeight(), mx, true);
         ImageView reViewer = new ImageView(ImagesZoom.this);
         reViewer.setImageBitmap(newBmap);
        
         layout.removeView(viewer);
         layout.addView(reViewer);
         setContentView(layout);
        
        }
        private void narrow(float f){
         Matrix mx = new Matrix();
         mx.setScale(bmap.getWidth() * f, bmap.getHeight() * f);
         Bitmap newBmap = Bitmap.createBitmap(bmap, 0, 0, bmap.getWidth(), bmap.getHeight(), mx, true);
         ImageView reViewer = new ImageView(ImagesZoom.this);
         reViewer.setImageBitmap(newBmap);
        
         layout.removeView(viewer);
         layout.addView(reViewer);
         setContentView(layout);
        
        }}
      

  3.   

    Bitmap newBmap = Bitmap.createBitmap(bmap, 0, 0, bmap.getWidth(), bmap.getHeight(), mx, true); 代码贴上面了。应该没啥问题。。
      

  4.   

    你的mx是错的,
    mx.setScale(bmap.getWidth() * f, bmap.getHeight() * f);这个不知道放大多少倍了
    float scaleWidth = ((float) newWidth) / width;  
    float scaleHeight = ((float) newHeight) / height; 
    mx.setScale(scaleWidth,scaleHeight);
      

  5.   

    遇到以上同样问题,解决不了,
    private Bitmap bit;
     bit=BitmapFactory.decodeResource(getResources(),R.drawable.icon);
          Matrix matrix=new Matrix();
          //matrix.postScale(bitmapwidth, bitmapheight);
          int width,height;
          width=bit.getWidth();
          height=bit.getHeight();
          matrix.postScale(width,  height);
          Bitmap resizebtm=Bitmap.createBitmap(bit,0,0,width,height,matrix,true);