2

谁能告诉我如何在保持图像缩放的同时更改图像视图中的图像?以前的和新的图像具有相同的大小。对于缩放功能,我使用来自https://stackoverflow.com/a/7458910/1346016的代码 我尝试使用 setimagebitmap、setimagedrawable 和其他一些,但它们似乎都不起作用。每次我刷新图像时,图像大小都会恢复到原来的大小。

谢谢你

这是我的代码的样子:

TouchImageView img,buffer;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // set multi touch zooming
    img = new TouchImageView(this);
    img.setMaxZoom(4f);
    Bitmap img1 = BitmapFactory.decodeResource(getResources(), R.drawable.blueprint);
    img.setImageBitmap(img1);

    // refresh image
    refreshImage();

    setContentView(img);
}
public void refreshImage() {
       handler.postDelayed(new Runnable() {
             public void run() {
                 Bitmap img1 = BitmapFactory.decodeResource(getResources(), R.drawable.blueprint);
                 Canvas newImg = new Canvas(img1);
                 newImg.drawBitmap(img1, 0f, 0f, null);
                 Paint inner = new Paint();
                 Paint outer = new Paint();            
                 inner.setARGB(255, 0, 138, 255);
                 outer.setARGB(100, 0, 138, 255);

                 newImg.drawCircle(axis[0], axis[1], 9, inner);
                 newImg.drawCircle(axis[0], axis[1], 50, outer);

                 buffer = img;
                 img.setImageBitmap(img1);
                 img.bmHeight = buffer.bmHeight;
                 img.bmWidth = buffer.bmWidth;
                 img.bottom = buffer.bottom;
                 img.setImageDrawable(buffer.getDrawable());
                 img.origHeight = buffer.origHeight;
                 img.origWidth = buffer.origWidth;
                 img.redundantXSpace = buffer.redundantXSpace;
                 img.redundantYSpace = buffer.redundantYSpace;
                 img.right = buffer.right;
                 img.saveScale = buffer.saveScale;
                 img.setImageMatrix(buffer.matrix);
                 img.setScaleType(ScaleType.MATRIX);
             }
         }, 2000);
}

编辑:现在我尝试将更改图像的代码更改为:

m = img.matrix;
img.setImageBitmap(img1);
img.matrix = m;
img.setImageMatrix(m);

但我仍然有同样的问题。

4

1 回答 1

0

您是否尝试在更改之前保存Matrix图像并在更改后重新应用Matrix到图像?

于 2012-04-20T09:23:19.383 回答