0

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

Kara
  • 6,115
  • 16
  • 50
  • 57
pengwang
  • 19,536
  • 34
  • 119
  • 168

2 Answers2

1

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);
Ron
  • 24,175
  • 8
  • 56
  • 97
0

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

Community
  • 1
  • 1
pengwang
  • 19,536
  • 34
  • 119
  • 168