开发者

Rotate rectangle bitmap in Android

开发者 https://www.devze.com 2023-03-10 20:41 出处:网络
I have a rectangle-shaped Bitmap, which I need to rotate it by 90 degrees clockwise or counter-clockwise.

I have a rectangle-shaped Bitmap, which I need to rotate it by 90 degrees clockwise or counter-clockwise.

I can do the rotation using this code:

    Matrix matrix = new Matrix();
    matrix.setRotate(90, originalBitmap.getWidth()/2, originalBitmap.getHeight()/2);
    return Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth(), originalBitmap.getHeight(), matrix, true);

However, this code rotates image "in-place" using old values for height/width. And the resulti开发者_高级运维ng image looks stretched and ugly.

Is there any good way to rotate the image by 90 degrees into new height/width? Probably, one possible solution is to modify dimensions of the original bitmap first?

Thanks


Don't you use old values while creating new bitmap? Just replace them in the last line:

 return Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth()/2, originalBitmap.getHeight()/2, matrix, true);
0

精彩评论

暂无评论...
验证码 换一张
取 消