-1

画像ビューに入れた画像を取得しようとしています。これが私のアプローチです:

// Get the image in the image view
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Bitmap myBitmap = mImageView.getDrawingCache();
    myBitmap.compress(CompressFormat.PNG, 0, outputStream);

次に、それをデータベースに挿入します。

mDbHelper.createReminder(outputStream);

DatabaseAdapterは次のようになります。

public long createReminder(ByteArrayOutputStream outputStream) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_IMAGE, outputStream.toByteArray());        
    return mDb.insert(DATABASE_TABLE, null, initialValues);
}

試してみると、アプリがクラッシュしました。私の発言はどういうわけか間違っていると思います。何か案は???

4

2 に答える 2

1
Drawable drawable = mImageView.getDrawable();
if (drawable instanceof BitmapDrawable) {
    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    Bitmap bitmap = bitmapDrawable.getBitmap();
}
于 2012-06-04T14:09:55.947 に答える
1
Drawable myDrawable = mImageView.getDrawable();

Bitmap bitmap = ((BitmapDrawable)myDrawable).getBitmap();

ここで、ビットマップをストリームに変換し、dbに保存します。

于 2012-06-04T14:13:17.443 に答える