- picture isn't saved properly into the database (as BLOB)
- public boolean SQL_INSERT_PICTURE(PictureDatatype type) {
- try{
- this.db = openHelper.getWritableDatabase();
- Log.d(TAG, "Insert picture");
- System.out.println("insert picture");
- db.execSQL("DELETE FROM picture " +
- "where " + LinkPic + " = '" + type.getLink() + "'");
- db.execSQL("INSERT OR REPLACE INTO picture " +
- "( " + NamePic + ", " + LinkPic + ", " + PicturePic + ") " +
- "VALUES ('" + type.getName() + "', '" + type.getLink() +"', '" +
- type.getPicture() +"')");
- System.out.println("size of the picture (bytearray): " + type.getPicture().length);
- System.out.println("the picture: " + type.getPicture());
- System.out.println("insert complete");
- db.close();
- return true;
- }
- catch(SQLException s){
- System.out.println("Insert failed");
- db.close();
- return false;
- }
- }
- private byte[] getBitmapAsByteArray(Bitmap bitmap) {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- // Middle value is quality, but PNG is lossless, so it's ignored.
- bitmap.compress(CompressFormat.PNG, 0, outputStream);
- return outputStream.toByteArray();
- }
- private byte[] getBitmapAsByteArray(Bitmap bitmap) {
- final int width = bitmap.getWidth();
- final int height = bitmap.getHeight();
- ByteBuffer byteBuffer = ByteBuffer.allocate(width * height * 4);
- bitmap.copyPixelsToBuffer(byteBuffer);
- return byteBuffer.array();
- }
- public Bitmap loadIcon(long iconId) {
- // Prepare the cursor to read from database....
- byte[] bitmapData = cursor.getBlob(cursor.getColumnIndex(Columns.Icons.DATA));
- return BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length);
- }