3

i am developing one app i am using upload image in sdcard getting from uri of image , this convert in to byte array how can implemented i am new developer in android i am saving this image in byte array in database backend please forward some solution ....

 startActivityForResult(new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
            }
  public void onActivityResult(int requestCode,int resultCode,Intent data)  
 {
 super.onActivityResult(requestCode, resultCode, data);
 if (resultCode == Activity.RESULT_OK) 
 {
 Uri selectedImage = data.getData();
 Cursor cur = PhotoImage.this.managedQuery(selectedImage, null, null, null, null);
 if(cur.moveToFirst())
 {
 long Length = cur.getLong(cur.getColumnIndex(ImageColumns.SIZE));
 try{
 String Image=Base64.encodeBytes(selectedImage.getPath().getBytes());
 Log.v("check",Image);
 byte[] bytedata = new byte[(int) Length];
 FileOutputStream fos=new FileOutputStream(Img);
 fos.write(bytedata[0]);
 fos.close();
   }
 catch (Throwable th)
 {}

output is:

12-30 13:00:24.619: VERBOSE/check(773): L2V4dGVybmFsL2ltYWdlcy9tZWRpYS8y

this is the display output i think not converted in byte array please some solution ..

3
  • 3
    Is there a badge for the most unreadable question ? Commented Dec 30, 2010 at 9:45
  • what $%& are you doing here? Opening a stream and writing the first byte of an unitialized byte array? Commented Dec 30, 2010 at 10:03
  • i am asking how we can convert image data in to byte array using base64 Commented Dec 30, 2010 at 10:23

1 Answer 1

2

This code will convert image file into bytes:

FileInputStream fin = c.openFileInput(path of file);
byte[] imageBytes = new byte[fin.available()];
fin.read(imageBytes);

put this in try...catch()

Try this and let me know if you are asking the same or some thing else.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.