[英]Rotating a imageView around a point to some degrees
我想圍繞一個點旋轉imageview。 imageview指的是可繪制資源。
然后我將imageview轉換為位圖,以便可以在畫布上繪制它。
借助於此,我能夠在畫布上繪制可繪制對象
imageView = new ImageView(this);
imageView.setImageResource(drawable);
imageView.setDrawingCacheEnabled(true);
imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imageView.layout(0, 0, imageView.getMeasuredWidth(), imageView.getMeasuredHeight());
imageView.buildDrawingCache(true);
Matrix matrix = new Matrix();
matrix.setRotate(30,x, y);
canvas.drawBitmap(imageView.getDrawingCache(), matrix, paint);
矩陣不起作用。 圖像在點x,y處沒有旋轉。
誰能告訴我代碼中缺少的內容?
首先平移(固定)點上的矩陣,然后分別旋轉到該點。
Matrix matrix = new Matrix();
matrix.setTranslate(x,y);
matrix.postRotate(30,x, y);
canvas.drawBitmap(imageView.getDrawingCache(), matrix, paint);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.