ひよつこです。
早速ですが質問させていただきます。
現在Viewのサイズに合わせてBitmapをリサイズし、Viewの中央に寄せる処理をさせたいと思っています。
float mWidth,mHeight; //ImageViewの幅と高さ
Bitmap bmp = BitmapFactory.decodeFile(画像ファイルのパス);
float scaleX = mWidth / bmp.getWidth();
float scaleY = mHeight / bmp.getHeight();
Matrix matrix = new Matrix();
if(scaleX < scaleY){
matrix.preScale(scaleX, scaleX);
matrix.postTranslate(0, (mHeight - (bmp.getHeight() * scaleX) ) / 2);
}else if(scaleX > scaleY){
matrix.preScale(scaleY, scaleY);
matrix.postTranslate((mWidth - (bmp.getWidth() * scaleY) ) / 2, 0);
}
Bitmap bmp2 = Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,true);
ImageView.setImageBitmap(bmp2);
何が問題なのでしょうか。