483

Bitmap イメージを Drawable に変換するにはどうすればよいですか?

4

12 に答える 12

870

Bitmapこれを試して、タイプ画像をに変換してくださいDrawable

Drawable d = new BitmapDrawable(getResources(), bitmap);
于 2010-12-30T07:04:40.700 に答える
158

に変換したときにビットマップが正しくスケーリングされないという問題が多数見られたBitmapDrawableので、一般的な変換方法は次のとおりです。

Drawable d = new BitmapDrawable(getResources(), bitmap);

がないとResources referencebitmap正しくスケーリングされていても、 が正しくレンダリングされない場合があります。bitmapここには、引数だけで直接呼び出すのではなく、このメソッドを使用するだけで解決できる多くの質問があります。

于 2012-01-31T11:14:09.133 に答える
36

公式のBitmapdrawableドキュメント

これは、ビットマップをドローアブルに変換する方法のサンプルです

Bitmap bitmap;  
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
于 2014-06-11T11:20:54.263 に答える
32

コンテキストで使用しました

//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
于 2016-10-13T00:06:25.800 に答える
20

ビットマップ画像があり、次のように描画可能で使用したい場合

Bitmap contact_pic;    //a picture to show in drawable
drawable = new BitmapDrawable(contact_pic); 
于 2012-11-20T06:50:31.830 に答える
11

これを行うだけです:

private void setImg(ImageView mImageView, Bitmap bitmap) {

    Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
    mImageView.setDrawable(mDrawable);
}
于 2015-07-23T16:55:43.303 に答える
-1

そして、これを試すことができます:

public static Bitmap mirrorBitmap(Bitmap bInput)
    {
        Bitmap  bOutput;
        Matrix matrix = new Matrix();
        matrix.preScale(-1.0f, 1.0f);
        bOutput = Bitmap.createBitmap(bInput, 0, 0, bInput.getWidth(), bInput.getHeight(), matrix, true);
        return bOutput;
    }
于 2021-01-12T10:13:57.757 に答える