1

こんにちは、私はアンドロイドの初心者です。画像の縦横比を維持するのを手伝ってくれる人はいますか? 私のアプリケーションでは、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);

これを見つけるのを手伝ってください。

4

3 に答える 3

2

you should have to use Scalling Property of ImageView for the ImageView use this property in your xml file use one the scale type for imageview

 android:adjustViewBounds="true"
 android:scaleType="fitXY" or  android:scaleType="centerCrop"
于 2012-07-27T05:34:44.373 に答える
0

xml またはアクティビティで ImageView の ScaleType プロパティを "CenterInside" に設定します。

my_image.setScaleType(ScaleType.CENTER_INSIDE);

ScaleType の詳細を見る

于 2012-07-27T05:04:25.590 に答える
0

ビットマップの表示は、非常に難しい場合があります。

このチュートリアルに厳密に従う必要があります: http://developer.android.com/training/displaying-bitmaps/index.html

于 2012-07-27T05:08:29.260 に答える