I am able to save the images in the database. The issue i have now is with retrieve it and making use of it in the code.
Look at my DATABAse handler get method:
ImageClass getImage(int state_id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(DATABASE_TABLE_NAME, new String[]{STATE_ID, STATE_NAME, STATE_IMAGE}, STATE_ID + "=?",
new String[]{String.valueOf(state_id)}, null, null, null, null);
if (cursor != null);
cursor.moveToFirst();
ImageClass imageClass = new ImageClass(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getBlob(1));
cursor.close();
return imageClass;
}
Look at the code i used in main activity..
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ImageClass imageClass = db.getImage();
byte[]in = imageClass._image;
Bitmap imah = Utils.getImage(in);
img.setImageBitmap(imah);
}
});
} catch(IOException e) {
System.out.println(e);
}
}
This is my image Activity
public class ImageClass {
int _id;
byte[] _image;
String _state_name;
public ImageClass(){
}
public ImageClass(int state_id,String state_name, byte[] state_image) {
this._id = state_id;
this._state_name = state_name;
this._image = state_image;
}
public ImageClass(String state_name, byte[]state_image){
this._state_name = state_name;
this._image = state_image;
}
public ImageClass(int state_id, byte[]state_image){
this._id = state_id;
this._image= state_image;
}
public int get_id() {
return this._id;
}
public void set_id(int state_id) {
this._id = state_id;
}
public byte[] get_image() {
return this._image;
}
public void set_image(byte[] state_image) {
this._image = state_image;
}
public String get_state_name() {
return this._state_name;
}
public void set_state_name(String set_state_name) {
this._state_name = set_state_name;
}
Its really been frustrating me ever since. Tried a lot of things online, just couldnt find the right way...