使用旋转矩阵位图 [英] Rotating a bitmap using matrix
问题描述
在使用矩阵旋转位图,顶点是不稳定的。
矩阵矩阵=新的Matrix(); matrix.postRotate(mDegree,100,100); mCompasstemp = Bitmap.createBitmap(mCompPic,0,0,mCompPic.getWidth(),mCompPic.getHeight(),矩阵,真); mCompassHud.setImageBitmap(mCompasstemp);
我的code输出像 -bitmap会旋转。 我的位图-vertex并不稳定。 -bitmap是调整
我需要禁用图像缩放,使旋转stable.Can请你提出了一个解决方案?
而不是直接从原来的创建新的位图,另一个(更直接的,恕我直言)选择是创建所产生的位图,创建一个画布位图,然后做你的旋转/平移/缩放画布上绘制原来的位图到通过画布的新位图。
基本上,你正在寻找,然后在:
scaledImage = Bitmap.createBitmap(croppedWidth,croppedHeight,Bitmap.Config.ARGB_8888);
帆布offscreenCanvas =新的Canvas(scaledImage);
字模=新的Matrix();
matrix.setRotate(旋转,CENTREX,centreY);
matrix.postScale(将scaleX,的scaleY);
offscreenCanvas.setMatrix(矩阵);
offscreenCanvas.drawBitmap(pickedImage,0,0,新涂料(Paint.DITHER_FLAG));
While rotating a bitmap using matrix, vertex is not stable..
Matrix matrix = new Matrix(); matrix.postRotate(mDegree,100,100); mCompasstemp = Bitmap.createBitmap(mCompPic, 0, 0, mCompPic.getWidth(), mCompPic.getHeight(), matrix, true); mCompassHud.setImageBitmap(mCompasstemp);
Output of my code is like -bitmap will rotate. -vertex of my bitmap is not stable. -Bitmap is resizing
I need disable image resizing and make the rotation stable.Can you please suggest a solution for this?
Rather than creating your new Bitmap directly from the original, another (more straight-forward, imho) option is to create the resultant Bitmap, create a Canvas with that Bitmap, then do your rotation/translation/scaling on the Canvas and draw the original Bitmap onto the new Bitmap via the Canvas.
Basically, you're looking, then, at:
scaledImage = Bitmap.createBitmap (croppedWidth, croppedHeight, Bitmap.Config.ARGB_8888);
Canvas offscreenCanvas = new Canvas (scaledImage);
Matrix matrix = new Matrix();
matrix.setRotate (rotations, centreX, centreY);
matrix.postScale(scaleX, scaleY);
offscreenCanvas.setMatrix (matrix);
offscreenCanvas.drawBitmap (pickedImage, 0, 0, new Paint(Paint.DITHER_FLAG));
这篇关于使用旋转矩阵位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!