2

Can anyone tell me how to change the image inside imageview that i have zoom while keeps the image zoomed? the previous and new image has the same size. for the zoom functions, i'm using the code from https://stackoverflow.com/a/7458910/1346016 i've try using setimagebitmap, setimagedrawable, and some other but none of them seems working. everytime i refresh the image, the image size return to it's original size.

thank you

here is how my code looks like:

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);
}

EDIT: now i've tried to change the code for changing image into:

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

but i still has the same problem.

Community
  • 1
  • 1
Thomas
  • 55
  • 1
  • 8

1 Answers1

0

Have you tried saving the Matrix of the image before changing and re-applying the Matrix to the image after changing it?

Rajesh
  • 15,724
  • 7
  • 46
  • 95
  • yes i've try it by getting the previous imagedrawable and imagematrix and set it to the new one but it still not working. – Thomas Apr 20 '12 at 09:33
  • When you make an assignment as in `buffer = img;` both `buffer` and `img` refer to the same object, whatever changes you make to `img` will be applicable to `buffer` as well. So `img.bmHeight = buffer.bmHeight;` etc., are actually self assignments. An assignment does not make a copy of the object. – Rajesh Apr 23 '12 at 03:55
  • thanks for the information. now i tried to only copy the matrix. but i still got the same problem. the image resize into it's original size. i've post the new code into the question. please have a look at it again. – Thomas Apr 23 '12 at 08:03