开发者

convert image data in to byte code using base64 encodein android

开发者 https://www.devze.com 2023-02-01 23:32 出处:网络
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 arr

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 ..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号