I have a SQLite database where I am inserting data directly which should appear as prestored data for my app user.My code is working fine for one image.But no idea to convert and retrieve an array of image
I tried Bitmap bitmap=BitmapFactory.decodeResource(getResources().pmge);.But I caused error to decodeResource () synatx
code
public class MainActivity extends Activity {
Integer [] pmge ={R.drawable.candle1,R.drawable.candl3,
R.drawable.candl4,R.drawable.candl5,R.drawable.candl6,
R.drawable.lawn,R.drawable.sglc10,R.drawable.senson,R.drawable.thejus6669};
MyDataBase myDataBase;
SQLiteDatabase database;
Cursor c;
ImageView imageView;
byte[] img,img1;
Bitmap b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView=(ImageView)findViewById(R.id.imge);
myDataBase=new MyDataBase(getApplicationContext(),"imagedata",null,1);
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.candle1);
ByteArrayOutputStream bos=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
img=bos.toByteArray();
database=myDataBase.getWritableDatabase();
Bitmap b1=BitmapFactory.decodeByteArray(img, 0, img.length);
imageView.setImageBitmap(b1);
}
}
class MyDataBase extends SQLiteOpenHelper{
public MyDataBase(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table tableimage (image BLOB,);");
db.execSQL("INSERT INTO tableimage(image) VALUES(img) ");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}