0

在我的 xml 文件中,我声明了两个imageview,然后我通过使用setImageBitmap()方法在其中添加了图像,并应用了单独的触摸事件。

但是这里的问题是,当添加第二张图像时我无法移动第一张图像,setImageBitmap()现在只有第二张图像可以移动。
在此先感谢,对不起英语。

working_bitmap = BitmapFactory.decodeFile(file_location+"cropped_image.jpg");  
outBitmap=Bitmap.createBitmap(
working_bitmap.getWidth(),
working_bitmap.getHeight(),Bitmap.Config.ARGB_8888);    
Canvas canvas1 = new Canvas(outBitmap);
canvas1.drawBitmap(working_bitmap, new Matrix(), null);
if(downloaded_shirt_image != null)
{
    int width = downloaded_shirt_image.getWidth();
    int height = downloaded_shirt_image.getHeight();
    int halfWidth = width/3;
    int halfHeight = height/3;
    //Half Scaled
    Bitmap bmHalf = Bitmap.createScaledBitmap(downloaded_shirt_image,
        halfWidth, halfHeight, false);
    proimg =(ImageView)findViewById(R.id.pro_img);
    proimg.setDrawingCacheEnabled(true);
    proimg.setImageBitmap(bmHalf);
    proimg.setVisibility(View.VISIBLE);
    proimg.setOnTouchListener(new View.OnTouchListener()
    {
      public boolean onTouch(View v, MotionEvent event) {
      ImageView view = (ImageView) v;
      int rotation = 25;
      // Dump touch event to log
      dumpEvent(event);
      // Handle touch events here...
      switch (event.getAction() & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        savedMatrix.set(matrix);
        start.set(event.getX(), event.getY());
        Log.d(TAG, "mode=DRAG");
        mode = DRAG;
        proimg.invalidate();
        break;
      case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) { 
// ...
                                                                                           matrix.set(savedMatrix);                                                            
        matrix.postTranslate(event.getX() - start.x,
        event.getY() - start.y);
       }
      else if (mode == ZOOM) {
         float newDist = spacing(event);
         Log.d(TAG, "newDist=" + newDist);
        if (newDist > 10f) {
        matrix.set(savedMatrix);
        float scale = newDist / oldDist;
        matrix.postScale(scale, scale, mid.x, mid.y);
        }
     }
    proimg.invalidate();
    break;
 }
      view.setImageMatrix(matrix);
    return true; // indicate event was handled
  }
 });
  canvas1.drawBitmap(downloaded_shirt_image, 50, 192, null);
 }

 if(downloaded_pant_image != null)
 {
  int width = downloaded_pant_image.getWidth();
  int height = downloaded_pant_image.getHeight();
  int halfWidth = width/3;
  int halfHeight = height/3;
  //Half Scaled
  Bitmap bmHalf = Bitmap.createScaledBitmap(downloaded_pant_image,
                  halfWidth, halfHeight, false);
  pantimg =(ImageView)findViewById(R.id.pro_img_down);
  pantimg.setDrawingCacheEnabled(true);
  pantimg.setImageBitmap(bmHalf);
  pantimg.setVisibility(View.VISIBLE);
  pantimg.setOnTouchListener(new View.OnTouchListener()
  {
   public boolean onTouch(View v, MotionEvent event) {
   ImageView view = (ImageView) v;
   int rotation = 25;
   // Dump touch event to log
   dumpEvent(event);
  // Handle touch events here...
  switch (event.getAction() & MotionEvent.ACTION_MASK) {
  case MotionEvent.ACTION_DOWN:
  savedMatrix.set(matrix);
  start.set(event.getX(), event.getY());
  Log.d(TAG, "mode=DRAG");
  mode = DRAG;
  pantimg.invalidate();
  break;
 case MotionEvent.ACTION_MOVE:
  if (mode == DRAG) {
  // ...

 matrix.set(savedMatrix);                                              matrix.postTranslate(event.getX() - start.x,
 event.getY() - start.y);
 }
else if (mode == ZOOM) {
float newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 10f) {
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
pantimg.invalidate();
break;
}
view.setImageMatrix(matrix);
return true; // indicate event was handled
}
}                            
);
canvas1.drawBitmap(downloaded_pant_image, 110, 565, null);
}
4

1 回答 1

1

另请参阅以下链接的答案和评论,它可能会对您有所帮助。

拖放两个图像

于 2012-06-18T07:23:00.280 回答