0

作成したビューのバイマップ イメージのサイズを変更しています。

Bitmap image = imageCreate( getMeasuredWidth(), getMeasuredHeight() );
image = imageResize( image, 62, 62 );
imageSave(image,"test.png");

サイズ変更は、カスタム ビュー内で行われます。

protected Bitmap imageCreate( int width, int height ) {

    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(image);
    draw(canvas);
    return image;
}

protected Bitmap imageResize(Bitmap image, int newWidth, int newHeight) {

    int width = image.getWidth();
    int height = image.getHeight();

    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // CREATE A MATRIX FOR THE MANIPULATION
    Matrix matrix = new Matrix();
    // RESIZE THE BIT MAP
    matrix.postScale(scaleWidth, scaleHeight);
    // RECREATE THE NEW BITMAP
    Bitmap resizedImage = Bitmap.createBitmap(image, 0, 0, width, height, matrix, false);

    return resizedImage;
}

最後に、画像を保存します。

protected boolean imageSave( Bitmap image, String filename, Context context ) {

    try {
        FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
        image.compress(Bitmap.CompressFormat.PNG, 90, fos);
        fos.close();

        return true;
    } catch (Exception e) {

        e.printStackTrace();
    }

    return false;
}

私の質問は、なぜ画質がひどいのか!?

画像は一種のピクセル化されています。元の画像は素晴らしいです。

また、良い方法はありますか?

4

1 に答える 1

0

このコード

// 新しいビットマップを再作成する Bitmap resizedImage = Bitmap.createBitmap(image, 0, 0, width, height, matrix, false);

フィルタリングを有効にするには、最後の引数を true に設定します。

それは役に立ちますか?

于 2012-07-09T20:30:15.987 に答える