2012-09-27 259 views
0

我新开发的android开发,目前正在处理画布和图像的应用程序... 但我被困在过程中。Android画布图像缩放

我想要实现,使得用户触摸了图像的边缘,如果他/她拖泰德图像,图像将被缩小一个功能..

我GOOGLE了很多,更多的,但无法找到任何教程或演示版。

希望你们所以你们帮助我。这种功能是通过GALAXY NOTE这样下面的图片提供..

enter image description here

回答

0

试试这个。

如果用户在右侧触摸图像并拖动右侧,则下面的代码将缩放图像并绘制缩放图像。

Bitmap bmpImage; 
     Rect src = new Rect(); 
     Rect dst = new Rect(); 
     src.left = initial_Start_pos_X; // initial Start X postion of image 
     src.top = initial_Start_pos_Y; // initial Start Y postion of image 
     src.right =initial_End_pos_X; // initial End X postion of image 
     src.bottom = initial_End_pos_Y; // initial End Y postion of image 

     dst.left = initial_Start_pos_X; 
     dst.top = initial_Start_pos_Y; 
     dst.right = Draged_Pox_X;  // Drag X position of image 
     dst.bottom = initial_End_pos_Y; 

     canvas.drawBitmap(bmpImage, src, dst, paint); // This line will scaled the image according to dst rect. It will take the image from src rect and draw in dst rect. so it will scaled the image. 

您必须在拖动图像侧时每次都使视图无效。你必须使ONTOUCHMOVE中的视图无效。

所以你必须先检查,图像的哪一侧被用户触摸和拖动,然后你必须修改上面的代码。 以上代码仅在右侧显示缩放图像