我正在开发一个应用程序,使用SD卡中的图像URI上传图像,将其转换为字节数组并保存在数据库后端。作为一名新的Android开发人员,请给出一些解决方案...
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)
{}
输出结果为:
12-30 13:00:24.619: VERBOSE/check(773): L2V4dGVybmFsL2ltYWdlcy9tZWRpYS8y
这是我认为未转换为字节数组的显示输出,请提供一些解决方案。