Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

java - How to fix cutted/trimmed side on canvas/bitmap?

Im trying to merge to bitmap using this code

Bitmap bitmapMerged = Bitmap.createBitmap(
            w, h,
            bitmapOriginal.getConfig()); 
            Canvas canvasMerged = new Canvas(bitmapMerged);
            canvasMerged.drawBitmap(bitmapOriginal, 0, 0, null);
            canvasMerged.drawBitmap(bitmapSecond, bitmapOriginal.getWidth(), 0, null);
            

It merge successfully, my next goal is to rotate the merged bitmap so I used this code

Matrix matrix = new Matrix(); 
             matrix.postRotate(10); 
             canvasMerged.setMatrix(matrix);

But the image is cutted/trim the side it seems it didnt fit in how to fix this?

example

question from:https://stackoverflow.com/questions/65641503/how-to-fix-cutted-trimmed-side-on-canvas-bitmap

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use matrix.postRotate(); with center. So,

matrix.postRotate( 10, centerX, centerY );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...