旋转图像但图像颜色暗且图像变形

发布于 2024-11-29 14:43:42 字数 976 浏览 2 评论 0原文

我想旋转图像更多时间,但我不能在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();

}

通过图像旋转得很好,但是图像变形,非常难看,你能告诉我为什么吗,并给出给我一个好方法,谢谢

i want to rotate i image more time,and i cannot to do it in the onDraw Method,my code is:

           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();

}

through the image rotate very well,but the image is deformation,it is very ugly ,can you tell me why,and give me a good method,thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-12-06 14:43:42

尝试使用 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);

Try using the setAntiAlias(true)

Canvas canvas = new Canvas(bmpSephia);
canvas.rotate(rotate);
Paint paint = new Paint();
paint.setAntiAlias(true);
canvas.drawBitmap(source, 0, 0, paint);

Or

BitmapDrawable bmdraw = new BitmapDrawable(bmpSephia);
bmdraw.setAntiAlias(true);
Canvas canvas = new Canvas(bmdraw.getBitmap());
canvas.rotate(rotate);
桃扇骨 2024-12-06 14:43:42

我已经使用了@user7777方法,并修改 Paint Paint = new Paint();
Paint.setAntiAlias(true);然后旋转图像的中心旋转,图像变形发生了一点变化,我看看 围绕画布中的中心点旋转图像

i have used @user7777 methods ,and modify Paint paint = new Paint();
paint.setAntiAlias(true); then rotate the center of the image rotate ,the image-deformation is changed little alos i look at rotate image in around its center point in canvas

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文