I Can't Get To Load An Image Stored In A SQLite Database In Imageview
I already have an image stored in the database in BLOB but I can't load it in an layout, please help me with the problem. The application gets closed during its running (unfortunat
Solution 1:
Try to change this:
ImageView imgdisplay;;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgdisplay = (ImageView) findViewById(R.id.item_icon);
myDB = this.openOrCreateDatabase("hello", MODE_PRIVATE, null);
Cursor c = myDB.rawQuery("SELECT image FROM employee_details WHERE name= 'john'", null);
if (c.getCount() > 0) {
c.moveToFirst();
do {
byte[] blob = c.getBlob(c.getColumnIndex("image"))
Bitmap b = BitmapFactory.decodeByteArray(blob , 0, blob .length);
imgdisplay.setImageBitmap(b);
} while (c.moveToNext());
}
c.close();
//close yourdatabase here }
for resize your bitmap object:
public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.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 resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
return resizedBitmap;}
Post a Comment for "I Can't Get To Load An Image Stored In A SQLite Database In Imageview"