gpt4 book ai didi

安卓 : Getting byte[] from Image ID

转载 作者:行者123 更新时间:2023-11-30 04:47:31 26 4
gpt4 key购买 nike

这是我正在做的:

在 onActivityResult 中,我在 Intent 中获取数据。

 Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);

此代码获取图像 ID:

data.getData().getLastPathSegment();

现在我想使用这个图像 ID 来获取 byte[] imageData,这样我就可以将图像上传到服务器上。

我该怎么做?

最佳答案

Uri selectedImageUri = data.getData();

String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(selectedImageUri, projection, null, null, null);
cursor.moveToFirst();
selectedImagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
cursor.close();

try
{
File myFile = new File(selectedImagePath);
int filelenghth=(int)myFile.length();
byte [] mybytearray = new byte [filelenghth];
BufferedInputStream bis1 = new BufferedInputStream(new FileInputStream(myFile));

bis1.read(mybytearray,0,mybytearray.length);

dos.write(mybytearray,0,mybytearray.length); // write the array to the data output stream
// or whatever else you want to do with it
finish();
}
catch(Exception e)
{
e.printStackTrace();
}

关于安卓 : Getting byte[] from Image ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4507802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com