2012-09-27 266 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中的視圖無效。

所以你必須先檢查,圖像的哪一側被用戶觸摸和拖動,然後你必須修改上面的代碼。 以上代碼僅在右側顯示縮放圖像