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;;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgdisplay = (ImageView) findViewById(R.id.item_icon);
myDB = this.openOrCreateDatabase("hello", MODE_PRIVATE, null);
Cursorc= 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"))
Bitmapb= 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) {
intwidth= bm.getWidth();
intheight= bm.getHeight();
floatscaleWidth= ((float) newWidth) / width;
floatscaleHeight= ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATIONMatrixmatrix=newMatrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAPBitmapresizedBitmap= 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"