-1
// Convert image to bitmap
Bitmap src1 = BitmapFactory.decodeFile(R.drawable.fried_chicken);

// Convert bitmap to byte
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
src1.compress(Bitmap.CompressFormat.JPEG,100,baos1);
byte[] byte1 = baos1.toByteArray();

// Convert byte to blob
Blob blob1 = new SerialBlob(byte1);

When I do this, theres a red line for R.drawable.fired_chicken. Aren't I supposed to put the path file? Am I missing something? SerialBlob is also underlined, is this because of the previous error?

FYI: I am decoding an image into bitmap then to blob because I want to save it into a sqlite database.

image

rob banks
  • 11
  • 3

1 Answers1

0

The red line is because you are trying to decode a drawable (by its id) instead of a File (by a String) to decode the drawable change the line to

Bitmap src1 = BitmapFactory.decodeResource(context.getResources(),R.drawable.fried_chicken);

For the SerialBlob error as far as I know there's no SerialBlob in Android Studio Try checking this how to store Image as blob in Sqlite & how to retrieve it?

Mirco0
  • 306
  • 1
  • 2
  • 8
  • thanks. do you have an idea on how to fix the `SerialBlob`? – rob banks Jul 15 '22 at 10:13
  • @Micro0 sorry but just wanna make sure. To store an image into a database, it needs to be a blob right? Im new to this. And in the link you sent me, it shows `Connection`. What am I suppose to connect to? If it is a database, i tried checking my file explore (data/data/package name) and theres no database folder even though I ran `db = new Handler(this);` – rob banks Jul 15 '22 at 10:56
  • The code that you need is the insertUser method – Mirco0 Jul 15 '22 at 12:16
  • Thanks. After some looking, I've figured out how to insert my data into the database. Thank you, you helped a lot :)))) – rob banks Jul 15 '22 at 14:52