android - picture isn't saved properly into the database (as BLOB) -
I try to save a photo as a blob in the database, but it is not properly stored in the database .
Byte [] that is passed is correct and has 4300 characters and the database contains only 12 characters, this is what is stored in DB: [B @ 43E7B 068] < / P>
Here is the code for my SQLandSERT:
Public Bullion SQL_INSERT_PICTURE (PictureDype Type) {try.d = OpenHelper.getWritableDatabase (); Log D. (Tag, "insert picture"); System.out.println ("Insert Image"); Db.execSQL ("Remove from the picture" + "where" + LinkPic + "= '" + type.getLink () + "'"); "+" Value ('+' type.getName () + "',' ',' ','" + Type.getLink () + "','" + type.getPicture () + "')"); System.out.println ("Picture size (BitairAir):" Type. Zant Picture (Length);); System.out.println ("Picture:" + type.getPicture ()); System.out.println ("Insert"); db.close (); return true;} hold (escalationation) {System.out.println ("insert failed"); db.close (); description is false;}} My question is why is not the right byte [] stored in DB or how can I do it? If you need more information or code then
thx kirbby
Use this code to convert to a byte array which can be stored as a BLOB for:
private byte [] getBitmapAsByteArray (bitmap bitmap) {Baitareonputstrym output stream = new Baitareon output stream (); // mid-priced quality , But PNG is flawless, so it has been ignored. Bitmap.compress (CompressFormat.PNG, 0, OutputStream); Return Output STream.toByteArray (); } OR <<> private byte [] getBitmapAsByteArray (bitmap bitmap) {final full width = bitmap.getWidth (); Last int height = bitmap.gatehit (); ByteBuffer byteBuffer = BitFufer.Olock (width * height * 4); Bitmap.copyPixelsToBuffer (ByteBuffer); Return byteBuffer.array (); }
The first option should always work. The second option is 32bits-per-pixel (ARGB_8888 format) thus follows 4 bytes. If you have a bitmap of another format (like 565), then he needs some modifications.
When you read image data from the database, do so: public bitmap loaded icon (long ICID) read {// database. ... byte [] = Bitmapdeta Karsrkgetblob (Karsrkgetindaks (Colmkiskanskdeta)); Return Bitmapficht. Decodbatearere (bitmapdata, 0, bitmapdata.line); } Make sure the database to your "table" is defined as the time BLOB execute SQL statements.
Comments
Post a Comment