得到的图片是Bitmap类型,参数position 点击图片在ListView、GridView等内的位置 ,可根据需要编写代码二
public Bitmap getBmp(int position)
{
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = select(TB_NAME);
cursor.moveToPosition(position);
byte[] in = cursor.getBlob(cursor.getColumnIndex(IMAGE));
Bitmap bmpout = BitmapFactory.decodeByteArray(in, 0, in.length);
return bmpout;
}
二、将图片转化为 byte[]//参数id为图片资源 (R.drawable.img)
public byte[] img(int id)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(id)).getBitmap();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}