我想让我的图像旋转更多时间,我不能在onDraw方法中做到这一点,我的代码是:
options = new BitmapFactory.Options();
options.inScaled = false;
options.inJustDecodeBounds = false;
options.inDither = false;
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
public void setAddBmpImage(int rotate) {
byte[] by = getBitmapByte(rotatedBitmap);
Bitmap source = BitmapFactory.decodeByteArray(by, 0, by.length, options);
Bitmap bmpSephia = Bitmap.createBitmap(rotatedBitmap.getWidth(), rotatedBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmpSephia);
canvas.rotate(rotate);
canvas.drawBitmap(source, 0, 0, null);
rotatedBitmap= bmpSephia;
imageStartX = (screenWidth / 2 - rotatedBitmap.getWidth() / 2);
imageStartY = (screenHeight / 2 - rotatedBitmap.getHeight() / 2);
invalidate();
}
通过图像旋转得非常好,但图像变形,很难看,能不能告诉我原因,并给我一个好方法,谢谢
答案 0 :(得分:1)
尝试使用setAntiAlias(true)
Canvas canvas = new Canvas(bmpSephia);
canvas.rotate(rotate);
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawBitmap(source, 0, 0, paint);
或
BitmapDrawable bmdraw = new BitmapDrawable(bmpSephia);
bmdraw.setAntiAlias(true);
Canvas canvas = new Canvas(bmdraw.getBitmap());
canvas.rotate(rotate);
答案 1 :(得分:0)
我使用了@ user7777方法,并修改了Paint paint = new Paint(); paint.setAntiAlias(真);然后旋转图像旋转的中心,图像变形变小,我看rotate image in around its center point in canvas