-1

I create Byte[] and also its displaying on ImageView. Now When i click on Button , IMAGE should go in DATABASE.. I am Confused to how to put logic in ContentValue.

else if (requestCode == 2) {

            Uri selectedImage = data.getData();
            String[] filePath = {MediaStore.Images.Media.DATA};
            Cursor c = getContentResolver().query(selectedImage, filePath, null, null, null);
            c.moveToFirst();
            int columnIndex = c.getColumnIndex(filePath[0]);
            String picturePath = c.getString(columnIndex);
            c.close();

            Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            thumbnail.compress(Bitmap.CompressFormat.PNG, 100, bos);
            byte[] bArray = bos.toByteArray();
            imgPro.setImageBitmap(thumbnail);


        }

And My Content Valued code is here

  String name = iName.getText().toString();
                String age  = iAge.getText().toString();
                String date = iDoB.getText().toString();
                String gender = a1;
                String ward = iWard.getText().toString();



                try {
                    SQLiteDatabase db = helper.getWritableDatabase();
                    ContentValues values = new ContentValues();
                    values.put(WardRobe_Contact.KEY_NAME, name);
                    values.put(WardRobe_Contact.KEY_DOB, date);
                    values.put(WardRobe_Contact.KEY_AGE, age);
                    values.put(WardRobe_Contact.KEY_IDENTITY, a1);
                    values.put(WardRobe_Contact.KEY_PROFILE, ward);
                    values.put(WardRobe_Contact.KEY_IMAGE,"HERE HOW TO CAST IMAGE VIEW ??" );

                    long wardrobe_entry = db.insert(WardRobe_Contact.TABLE, null, values);
                    db.close(); // Closing database connection
                    Toast.makeText(getApplicationContext(), "Data Inserted Successfully", Toast.LENGTH_SHORT).show();

How can i cast to set image to Database.. please help me.. thanxx a lot in advance

prince
  • 1
  • get the byte array from the image. then convert it to string and store on database. – Rince Thomas Mar 24 '15 at 06:57
  • Hi Signare, thnxx for quick response.. could you suggest me after seeing my code.. how to write this logic... ? – prince Mar 24 '15 at 07:01
  • if i would able to save Byte[] bArray in database, My task would b finished... – prince Mar 24 '15 at 07:03
  • check this http://stackoverflow.com/questions/10513976/how-to-convert-image-into-byte-array-and-byte-array-to-base64-string-in-android – Rince Thomas Mar 24 '15 at 07:10
  • http://stackoverflow.com/questions/18804189/image-quality-changes-while-encoding-decoding-image-to-base64-string – Rince Thomas Mar 24 '15 at 07:15
  • hello Signare... That code is too horrible.. so please i would like to request you plz focus on my code and let me know what changes should have to make.. – prince Mar 24 '15 at 07:41

1 Answers1

0

Sometimes it makes more sense to store the image on disk and only put the file location in your DB. Then you can skip the whole blob <-> byte array conversion and use normal file operations to load the images.

I know that didn't answer your specific question, but if you change your process to the above you might not need the original method, and may save some time and effort as a bonus. Hope this helps.

Himanshu A Jadav
  • 2,286
  • 22
  • 34