사용자가 이미지 해상도 (예 : 4096x3024px)를 선택한 다음 스트림에서 변경 가능한 비트 맵을 가져온 다음이를 surfaceview로 전송하고 화면 크기에서 비트 맵 크기로 확장하는 데 사용할 또 다른 캔버스를 만들 수 있습니다.
이 캔버스를 확대하면 이미지가 올바르게 확대되지 않습니다. 중앙 피벗에서 배율을 조정 한 행렬을 만들려고 시도했지만 여전히 결과가 없습니다.
여기에서 카메라 미리보기에서 비트 맵을 가져오고 크기 조정 및 저장에 사용되는 캔버스에 그립니다.
public Bitmap mergeImageAndCanvas(Bitmap bitmap) {
// DRAW TO Canvas created in constructor
canvasImage.setBitmap(bitmap);
render(canvasImage, true);
canvasImage.setBitmap(null);
System.out.println("Canvas " + canvas.getWidth() + ", height " + canvas.getHeight());
return bitmap;
}
여기에서 내가 그리는 텍스트와 선의 정확한 위치를 유지하기 위해 이미지를 확대하고 가운데로 설정합니다.
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// Toast.makeText(getContext(), "Surfaceview surfaceChanged() width " +
// width + ", height" + height,
// Toast.LENGTH_LONG).show();
bitmapWitdh = photoHandler.photoWidth;
bitmapHeight = photoHandler.photoHeight;
canvasWidth = width;
ratioX = (float) canvasWidth / 1280;
canvasHeight = height;
scaleX = ((float) bitmapWitdh) / (float) canvasWidth;
scaleY = ((float) bitmapHeight) / (float) canvasHeight;
float middleX = bitmapWitdh / 2.0f;
float middleY = bitmapHeight / 2.0f;
scaleMatrix = new Matrix();
// scaleMatrix.preScale(scaleX, scaleY);
scaleMatrix.setScale(scaleX, scaleY, middleX, middleY);
// scaleMatrix.postTranslate(-(bitmapWitdh) / 2, -(bitmapHeight) / 2);
// scaleMatrix.setTranslate(300, 300);
canvasImage.setMatrix(scaleMatrix);
}
다음은 업 스케일 후 달성하고 싶은 것입니다 (사용자가 1280x720 해상도로 화면에서 보는 것입니다) 이미지 화면
이것은 사용자가 얻는 것 (이미지 해상도 2560x1920) 최종 이미지
모든 해상도에 대해 캔버스 크기를 조정하는 솔루션은 방법으로 크기를 조정하는 것입니다 Canvas.setScale()
. 매트릭스 스케일링은 기본적으로 화면 왼쪽 상단에있는 (0,0) 인 원점에서 적용되며 원하는 해상도 (캡처 된 이미지의 크기)를 분할하여 얻은 scaleX 및 scaleY 계수를 통해 캔버스 크기를 다른 차원으로 변환합니다. 카메라) 현재 해상도 (장치 해상도) 너비 및 높이로.
기본적으로 캡처 된 이미지와 장치의 화면 크기가 일치합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다