12

いくつかの画像があるという点で、Web サイトを解析して URL にコンテンツを表示しています。サイトから解析された画像をトリミングしたい。私はこれに本当に苦労しています、これに関して誰かが私を助けることができますか?

4

4 に答える 4

23

すでにウェブサイトから画像を「取得」しており、トリミングするのではなくサイズを変更したいと思いますか? つまり、サムネイルを作成します。

その場合は、次を使用できます。

    // load the origial BitMap (500 x 500 px)
    Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), 
           R.drawable.android);

    int width = bitmapOrg.width();
    int height = bitmapOrg.height();
    int newWidth = 200;
    int newHeight = 200;

    // calculate the scale - in this case = 0.4f
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    // createa matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);

    // recreate the new Bitmap
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, 
                      width, height, matrix, true); 

    // make a Drawable from Bitmap to allow to set the BitMap 
    // to the ImageView, ImageButton or what ever
    BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);

    ImageView imageView = new ImageView(this);

    // set the Drawable on the ImageView
    imageView.setImageDrawable(bmd);

    // center the Image
    imageView.setScaleType(ScaleType.CENTER);
于 2010-09-16T10:04:11.627 に答える
2

Android 連絡先マネージャーEditContactActivityが使用するIntent("com.android.camera.action.CROP")

これはサンプルコードです:

Intent intent = new Intent("com.android.camera.action.CROP");
// this will open all images in the Galery
intent.setDataAndType(photoUri, "image/*");
intent.putExtra("crop", "true");
// this defines the aspect ration
intent.putExtra("aspectX", aspectY);
intent.putExtra("aspectY", aspectX);
// this defines the output bitmap size
intent.putExtra("outputX", sizeX);
intent.putExtra("outputY", xizeY);
// true to return a Bitmap, false to directly save the cropped iamge
intent.putExtra("return-data", false);
//save output image in uri
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

次に、ユーザーがOKまたはCancelstartActivityWithResult()を押したかどうかを確認します。前者の場合、トリミングされた画像は に保存されます。uri

于 2013-01-10T10:12:42.307 に答える
-3
<ImageView  android:id="@+id/title_logo"
            android:src="@drawable/logo"
            android:scaleType="centerCrop" android:padding="4dip"/>
于 2012-09-07T18:35:01.740 に答える