こんにちは、私はアンドロイドの初心者です。画像の縦横比を維持するのを手伝ってくれる人はいますか? 私のアプリケーションでは、SDCARD から画像を選択し、インテントを次のアクティビティに渡すことで imageview に表示します。しかし、ほとんどの場合、画像が大きいか小さい場合、画像は私のイメージビューに正しく表示されません。
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[16 * 1024];
options.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeStream(getContentResolver()
.openInputStream(mImageCaptureUri));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
Bitmap newbitmap = Bitmap.createScaledBitmap(bitmap, 120,
120, true);
newbitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
Intent photointent = new Intent(MethinkzActivity.this,
DisplayImage.class);
photointent.putExtra("photo", bs.toByteArray());
startActivity(photointent);
そして、他のアクティビティでは、次を使用してそれをキャッチします。
bitmap = BitmapFactory.decodeByteArray(getIntent()
.getByteArrayExtra("photo"), 0, getIntent()
.getByteArrayExtra("photo").length);
final double viewWidthToBitmapWidthRatio = (double) my_image
.getWidth() / (double) bitmap.getWidth();
my_image.getLayoutParams().height = (int) (bitmap.getHeight() * viewWidthToBitmapWidthRatio);
my_image.setImageBitmap(bitmap);
これを見つけるのを手伝ってください。