我想在android中旋轉圖像。我發現this useful post,它工作得很好,但它似乎在Android的旋轉從左下角開始。我需要從中心點旋轉我的圖像。可能嗎?代碼相同是有幫助的。 謝謝。從imageview中心點旋轉圖像
回答
嘗試:
Matrix matrix=new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
matrix.postRotate((float) angle, imageView.getDrawable().getBounds().width()/2, imageView.getDrawable().getBounds().height()/2);
imageView.setImageMatrix(matrix);
它從你給的鏈接相同的答案來。
這個怎麼樣(比goodm的回答略有不同):
public Bitmap rotateImage(int angle, Bitmap bitmapSrc) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(bitmapSrc, 0, 0,
bitmapSrc.getWidth(), bitmapSrc.getHeight(), matrix, true);
}
Yahhhh。它的工作。謝謝。 – IndieBoy 2013-05-13 17:47:58
只是偶然發現了這個,因爲我有類似的問題!如果你能幫助我,我會在哪裏加載png圖片到這個代碼中? – 2017-06-02 17:40:35
的問題@ goodm的解決方案是,ImageView的可能尚未奠定了沒有導致imageView.getDrawable()的getBounds()。 width()和.height()返回0.這就是爲什麼你仍然在0,0左右旋轉的原因。解決這個問題的一個方法就是確保在使用類似這樣的佈局之後創建並應用矩陣:How to set fixed aspect ratio for a layout in Android
@ Voicu的解決方案沒問題,但它需要您直接處理可能效率低下的位圖。更好的做法可能是直接查詢圖像資源的大小,但實際上並未將其加載到內存中。我用一個實用的方法來做到這一點,它看起來像這樣:
public static android.graphics.BitmapFactory.Options getSize(Context c, int resId){
android.graphics.BitmapFactory.Options o = new android.graphics.BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeResource(c.getResources(), resId, o);
return o;
}
這將返回一個Options對象將包含實際的寬度和高度。從活動中你可以使用這樣的:
ImageView img = (ImageView)findViewById(R.id.yourImageViewId);
Options o = getSize(this, R.drawable.yourImage);
Matrix m = new Matrix();
m.postRotate(angle, o.outWidth/2, o.outHeight/2);
img.setScaleType(ScaleType.MATRIX);
img.setImageMatrix(m);
,這是爲我工作:
RotationAnimatin anim= new RotationAnimation(0f,350f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//然後設置插,持續時間和RepeatCount
yourImageView.startAnimation(anim);
它是RotateAnimation而不是RotationAnimation – 2017-02-09 13:57:45
嘗試此
gestureCenterPoint.x =(int)(imageView.getPaddingLeft()+ matrix瓦爾斯[Matrix.MTRANS_X]); gestureCenterPoint.x + =(origonalWidth/2)*(matrixVals [Matrix.MSKEW_X]); gestureCenterPoint.x + =(origonalWidth/2)*(matrixVals [Matrix.MSCALE_X]);
gestureCenterPoint.y =(int)(imageView.getPaddingTop()+ matrixVals [Matrix.MTRANS_Y]); gestureCenterPoint.y + =(origonalHeight/2)*(matrixVals [Matrix.MSKEW_Y]); gestureCenterPoint.y + =(origonalHeight/2)*(matrixVals [Matrix.MSCALE_Y]);
- 1. ImageView中的旋轉圖像
- 2. Android - 圍繞中心點旋轉圖像?
- 3. 旋轉後在ImageView中適合圖像
- 4. 旋轉中心圖像視圖
- 5. 如何ImageView在360度中心旋轉?
- 6. 拉直圖像從圖像的中心旋轉和縮放
- 7. Swift:圍繞中心點旋轉圖層
- 8. 如何在圖像中心旋轉UIImage
- 9. jQuery旋轉圖像不在中心
- 10. 圍繞中心旋轉圖像
- 11. 中心使用旋轉的圖像GDI +
- 12. 在其中心旋轉圖像
- 13. 在畫布中圍繞其中心點旋轉圖像
- 14. BlackBerry drawTexturedPath旋轉將錨點移至圖像的中心
- 15. 如何定位在中心點旋轉的所有圖像 - android
- 16. 變化圖中心或旋轉攝像機,點在MATLAB - Earth_example
- 17. 旋轉圖像aroound點
- 18. 旋轉圖像後點擊
- 19. 如何使用MATLAB旋轉關於非圖像中心點的圖像?
- 20. 像轉向一樣旋轉Imageview?
- 21. 如何從固定的中心點旋轉圖像和箭頭線
- 22. 從其中心OpenGL ES 1.1圖像旋轉
- 23. ImageView不旋轉
- 24. 旋轉ImageView
- 25. Flex中給定中心的旋轉點
- 26. 如何防止imageview中的自動圖像旋轉?
- 27. - 旋轉圖像
- 28. 旋轉圖像
- 29. 旋轉圖像
- 30. 旋轉圖像
是的,我看到這個,但它不會從中心點旋轉。我應該添加什麼東西?感謝您的快速回復。 – IndieBoy 2013-05-13 17:06:36
@JASX發佈了一個解釋,如果你好奇... – newbyca 2013-10-15 07:26:59