mardi 21 juillet 2015

How to store image using ActiveAndroid in DB

This My My Activity class code for Storing Values using activeandoid ... i have converted image file to byte in below code .. but it is not Stored in Db ...All other values were stored

case R.id.notVerified:
                    ActiveAndroid.beginTransaction();
                    try {
                        c.setName(Ename.getText().toString());
                        c.setEmail(Eemail.getText().toString());
                        c.setMemo(Eemail.getText().toString());
                        c.setPhone(Ephone.getText().toString());
                        c.setPhoto("user.png");
                        String s = new String(byteArray);

                        Toast.makeText(getActivity(), c.getImage().toString() ,Toast.LENGTH_LONG).show();
                        c.setImage(byteArray);
                        c.setTitle(ETitle.getText().toString());
                        c.save();
                        ActiveAndroid.setTransactionSuccessful();
                        Toast.makeText(getActivity(), "Contact Added",Toast.LENGTH_LONG).show();
                    } finally {
                        ActiveAndroid.endTransaction();
                    }

                    break;

This is for Converting Image to Byte 

if (requestCode == CAMERA_REQUEST) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};

            Cursor cursor = getActivity().getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String filePath = cursor.getString(columnIndex);
            Eimgname.setText(filePath);
            cursor.close();

            Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            yourSelectedImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byteArray = stream.toByteArray();
            c.setImage(byteArray);
        }

Aucun commentaire:

Enregistrer un commentaire