早速ですが質問させていただきます。
今回SurfaceViewの大きさに合わせてリサイズしたBitmapを
SurfaceViewの中央に描画したいと思っています。
private int mWidth; //SurfaceViewの幅
private int mHeight; //SurfaceViewの高さ
private Bitmap prepareImage(Bitmap res){
Bitmap result = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
float scaleX = mWidth / res.getWidth();
float scaleY = mHeight / res.getHeight();
Matrix m = new Matrix();
if(scaleX < scaleY){
m.preScale(scaleX, scaleX);
m.postTranslate(0, (mHeight - (res.getHeight() * scaleX) ) / 2);
}else if(scaleX > scaleY){
m.preScale(scaleY, scaleY);
m.postTranslate((mWidth - (res.getWidth() * scaleY) ) / 2, 0);
}else{
m.postScale(scaleX, scaleY);
}
Canvas canvas = new Canvas(result);
canvas.drawBitmap(res, m, new Paint());
return result;
}
Bitmap bmp = BitmapFactory.createBitmap("ファイルのパス");
surface.prepareImage(bmp);
surface.doDraw();
しかしSurfaceViewの描画は正しく行われていますが、
なぜかリサイズされないのです。
コードの抜粋で済みませんが、
原因を教えていただけると助かります。
よろしくお願いします。