【发布时间】:2019-04-16 05:41:36
【问题描述】:
我有 Image 对象,我将它的 byteBuffer 保存到 Bitmap 以下载图像。但我认为我没有正确创建位图,因为正在创建 0Byte 图像。
I have looked everywhere how to convert the image object(not the drawable) to convert to bitmap.But i cant find a valid way.
//arcore image acquire.
Image image=frame.acquireCameraImage();
//edgeDetector is a function that returns these values wrapped
//into a bytebuffer.
ByteBuffer buffer11=edgeDetector.detect(
image.getWidth(),
image.getHeight (),
image.getPlanes()[0].getRowStride(),
image.getPlanes()[0].getBuffer());
byte[] bytes = new byte[buffer11.capacity()];
buffer11.get(bytes);
Log.i("ByteBuffer",bytes.toString());
Bitmap bitmapImage = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, null);
Log.i("Bitmap","created");
Date currentTime11 = Calendar.getInstance().getTime();
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/saved_images");
if (!myDir.exists()) {
myDir.mkdirs();
}
String myimage = "I-"+ currentTime11.toString() +".jpg";
File file = new File (myDir, myimage);
if (file.exists ())
file.delete ();
try {
FileOutputStream out = new FileOutputStream(file);
Log.i("Checking","Checking");
if(bitmapImage!=null)
{
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 90, out);
//saving the bitmap.
}
out.flush();
out.close();
image.close();//closing image so the application wont crash.
}
catch (Exception e) {
Log.i("Error","Try again");
//handling exceptions
}
我想存储框架获取的非空图像。 请说明处理此图像对象并将图像保存在外部存储中的正确方法。
【问题讨论】:
-
edgeDetector是什么? -
这是 edgeDetector chromium.googlesource.com/external/github.com/google-ar/…
标签: android image api file android-external-storage