개인적으로 제 생각에 당신은 새로운 Canvas
을 만들어야한다고 생각합니다. 비트 맵의 크기를 먼저 조절해야합니다. 아래의 방법을 사용하여 뷰의 크기와 비트 맵의 크기 사이의 비율을 계산합니다.
public static float computeScale(float w1, float h1, float w2, float h2) {
if (w1 > 0 && h1 > 0 && w2 > 0 && h2 > 0) {
return Math.max(w1/w2, h1/h2);
}
return 1;
}
은 그래서 규모와 새로운 비트 맵의 폭, 높이 아래의 코드에 의해 계산됩니다 :
float scale = computeScale(viewWidth, viewHeight, bitmapWith, bitmapHeight);
if(scale > 1){
int newWidth = Math.round(bitmapWidth/scale);
int newHeight = Math.round(bitmapHeight/scale);
}
// The code for resizing the source bitmap with the newWidth and newHeight.
// Bitmap newBitmap = ...;
마지막으로, 새 Canvas
을 만들기 위해 새 비트 맵을 사용합니다.
Canvas canvas = new Canvas(newBitmap);
정확하게 질문이 올지 모르겠습니다. 'canvas.scale (xScale, yScale)'을 호출 할 때 yScale 요소를 얼마만큼 설정할지 알 수 있습니까? 또한 캔버스 크기를 항상 장치의 너비와 높이와 같게하려고합니까? –