【发布时间】:2015-12-29 20:40:48
【问题描述】:
我有一个 Imageview 假设 image1。现在有一个名为 image2 的 imageview。图像1>图像2。我想将 image2 拖到 image1 上并使用画布保存新图像。图像已合并,但 image2 未在正确位置合并。任何帮助,将不胜感激。 这是我的合并代码
int maxWidth = (bitmap1.getWidth() > resizedbitmap2.getWidth() ? bitmap1.getWidth() : resizedbitmap2.getWidth());
int maxHeight = (bitmap1.getHeight() > resizedbitmap2.getHeight() ? bitmap1.getHeight() : resizedbitmap2.getHeight());
Bitmap bmOverlay = Bitmap.createBitmap(maxWidth, maxHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bitmap1, 0f, 0f, null);
canvas.drawBitmap(resizedbitmap2, x, y, null);
这就是我拖动图像2的方式
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction())
{
case MotionEvent.ACTION_DOWN:
// attemptClaimDrag();
moving=true;
break;
case MotionEvent.ACTION_MOVE:
if(moving){
x=arg1.getRawX()-ima2.getWidth()/2;
y=arg1.getRawY()-ima2.getHeight()*3/2;
ima2.setX(x);
ima2.setY(y);
}
break;
case MotionEvent.ACTION_UP:
moving=false;
break;
}
return true;
}
定义了这两个
float x,y=0.0f
【问题讨论】: