I found the solution!
Add the below code after getting the lightmaps
from above. This converts the android.media.Image
type to a bitmap and then saves it to memory.
for (int i = 0; i < lightmaps.length; i++)
{
Image lightmapimage = lightmaps[i];
int width = lightmapimage.getWidth();
int height = lightmapimage.getHeight();
Image.Plane[] planes = lightmapimage.getPlanes();
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * width;
ByteBuffer buffer = planes[0].getBuffer();
Bitmap bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
lightmapimage.close();
saveBitmap(bitmap);
}
Below is the saveBitmap function [Source]. This saves the bitmap as a png to /storage/emulate/0/DCIM
. Change this if you want to.
public static void saveBitmap(Bitmap bm)
{
String path = "";
File parent = new File(TextUtils.isEmpty(path) ? Environment.getExternalStorageDirectory() + "/" + Environment
.DIRECTORY_DCIM : path);
if (!parent.exists()) {
parent.mkdirs();
}
File f = new File(parent.getAbsolutePath() + File.separator + "arcore_bitmap" + new Date().getTime() + ".jpg");
if (f.exists()) {
f.delete();
}
FileOutputStream out = null;
try {
out = new FileOutputStream(f);
bm.compress(Bitmap.CompressFormat.PNG, 90, out);
Log.i("savingbitmap","savingbitmap" + parent.getAbsolutePath());
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}