优化拍照流程自动生成hdr文件

mem
liuguijing 6 months ago
parent 92ec7a8535
commit 07bc04003d

@ -167,6 +167,7 @@ public class Camera2RawFragment extends Fragment {
* but the orientation of the has changed, and thus the preview rotation must be updated. * but the orientation of the has changed, and thus the preview rotation must be updated.
*/ */
private OrientationEventListener mOrientationListener; private OrientationEventListener mOrientationListener;
private static ArrayList<PngPhotoBean> list = new ArrayList<>();//用来存储已拍照的照片名称
public static native boolean makeHdr(long exposureTime1, String path1, long exposureTime2, String path2, String outputPath); public static native boolean makeHdr(long exposureTime1, String path1, long exposureTime2, String path2, String outputPath);
@ -594,105 +595,13 @@ public class Camera2RawFragment extends Fragment {
}; };
Button takepic = view.findViewById(R.id.takepic); Button takepic = view.findViewById(R.id.takepic);
Button button = view.findViewById(R.id.tojpg);
EditText baoguang = view.findViewById(R.id.baoguang);
EditText iso = view.findViewById(R.id.iso);
// if (exposureTime > 0) {
// baoguang.setText(exposureTime + "");
// }
// if (sensitivity > 0) {
// iso.setText(sensitivity + "");
// }
takepic.setOnClickListener(new View.OnClickListener() { takepic.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
isHandTakePic = true; isHandTakePic = true;
String s1 = baoguang.getText().toString();
String s2 = iso.getText().toString();
if (s1 != null && !s1.equals("")) {
pic1 = Double.parseDouble(s1);
}
if (s2 != null && !s2.equals("")) {
// sensitivity = Integer.parseInt(s2);
pic2 = Double.parseDouble(s2);
}
takePicture(); takePicture();
} }
}); });
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
// List<String> strings = RawToJpgConverter.listFiles(directory);
// if (strings != null && strings.size() > 0) {
// for (String item : strings) {
// if (item.contains("create")) {
// File file1 = new File(directory, item);
// File file2 = new File(directory, "create_" + item + ".jpg");
// try {
// RawToJpgConverter.convertRawToJpg(file1.getPath(), file2.getPath());
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// }
// }
// }
File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
String dcimpath = directory.getPath();
List<String> strings = RawToJpgConverter.listFiles(directory);
long t1;
long t2;
String p1;
String p2;
ArrayList<PngPhotoBean> list = new ArrayList();
if (strings != null && strings.size() > 0) {
for (String item : strings) {
if (item.contains("create")) {
String[] s = item.split("_");
File file1 = new File(directory, item);
PngPhotoBean bean = new PngPhotoBean();
bean.etime = Long.parseLong(s[1]);
bean.path = file1.getPath();
list.add(bean);
if (list.size() == 2) {
break;
}
}
}
}
if (list.size() == 2) {
PngPhotoBean bean = list.get(0);
PngPhotoBean bean1 = list.get(1);
makeHdr(bean.etime, bean.path, bean1.etime, bean1.path, dcimpath + "/" + "hdr_" + generateTimestamp() + ".png");
}
}
});
// mTextureView.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// int actionMasked = MotionEventCompat.getActionMasked(event);
// int fingerX, fingerY;
// int length = (int) (getResources().getDisplayMetrics().density * 80);
// switch (actionMasked) {
// case MotionEvent.ACTION_DOWN:
// fingerX = (int) event.getX();
// fingerY = (int) event.getY();
//
// mIvFocus.setX(fingerX - length / 2);
// mIvFocus.setY(fingerY - length / 2);
//
// mIvFocus.setVisibility(View.VISIBLE);
// triggerFocusArea(fingerX, fingerY);
//
// break;
// }
//
// return false;
// }
// });
} }
@Override @Override
@ -1167,8 +1076,8 @@ public class Camera2RawFragment extends Fragment {
} }
// Find the best preview size for these view dimensions and configured JPEG size. // Find the best preview size for these view dimensions and configured JPEG size.
// Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedViewWidth, rotatedViewHeight, maxPreviewWidth, maxPreviewHeight, largestJpeg); Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedViewWidth, rotatedViewHeight, maxPreviewWidth, maxPreviewHeight, largestJpeg);
Size previewSize = new Size(3840, 2160); // Size previewSize = new Size(3840, 2160);
if (swappedDimensions) { if (swappedDimensions) {
mTextureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth()); mTextureView.setAspectRatio(previewSize.getHeight(), previewSize.getWidth());
@ -1459,13 +1368,6 @@ public class Camera2RawFragment extends Fragment {
} }
} }
/**
* Runnable that saves an {@link Image} into the specified {@link File}, and updates
* {@link android.provider.MediaStore} to include the resulting file.
* <p/>
* This can be constructed through an {@link ImageSaverBuilder} as the necessary image and
* result information becomes available.
*/
private static class ImageSaver implements Runnable { private static class ImageSaver implements Runnable {
/** /**
@ -1550,34 +1452,26 @@ public class Camera2RawFragment extends Fragment {
break; break;
} }
} }
// Decrement reference count to allow ImageReader to be closed to free up resources.
mReader.close(); mReader.close();
// If saving the file succeeded, update MediaStore.
if (success) { if (success) {
File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
String directoryPath = directory.getPath();
File file = new File(directory, "create_" + mExpostime + "_" + generateTimestamp() + ".png"); File file = new File(directory, "create_" + mExpostime + "_" + generateTimestamp() + ".png");
String path = file.getPath();
try { try {
RawToJpgConverter.convertRawToJpg(mFile.getPath(), file.getPath()); RawToJpgConverter.convertRawToJpg(mFile.getPath(), path);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
PngPhotoBean bean = new PngPhotoBean();
// covertNum++; bean.setEtime(mExpostime);
// MediaScannerConnection.scanFile(mContext, new String[]{mFile.getPath()}, bean.setPath(path);
// /*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() { list.add(bean);
// @Override if (list.size() == 2) {
// public void onMediaScannerConnected() { PngPhotoBean bean1 = list.get(0);
// // Do nothing PngPhotoBean bean2 = list.get(1);
// } makeHdr(bean1.getEtime(), bean1.getPath(), bean2.getEtime(), bean2.getPath(), directoryPath + "/" + "hdr_" + generateTimestamp() + ".png");
// }
// @Override
// public void onScanCompleted(String path, Uri uri) {
// Log.i(TAG, "Scanned " + path + ":");
// Log.i(TAG, "-> uri=" + uri);
// }
// });
} }
} }

@ -2,9 +2,22 @@ package com.xypower.mppreview;
public class PngPhotoBean { public class PngPhotoBean {
public long etime; private long etime;
public String path; private String path;
public long getEtime() {
return etime;
}
public void setEtime(long etime) {
this.etime = etime;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
} }

@ -77,7 +77,7 @@ public class RawToJpgConverter {
ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
// 5. 将Bitmap以JPG格式编码到输出流中 // 5. 将Bitmap以JPG格式编码到输出流中
rawBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream); rawBitmap.compress(Bitmap.CompressFormat.PNG, 100, bytestream);
// 6. 将输出流转换为字节数组,并关闭输出流 // 6. 将输出流转换为字节数组,并关闭输出流
byte[] jpgData = bytestream.toByteArray(); byte[] jpgData = bytestream.toByteArray();

@ -12,45 +12,16 @@
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<EditText
android:background="@color/white"
android:id="@+id/baoguang"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:hint="曝光 单位 微秒"
android:textColor="@color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:background="@color/white"
android:id="@+id/iso"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:hint="ISO"
android:textColor="@color/black"
app:layout_constraintLeft_toRightOf="@id/baoguang"
app:layout_constraintTop_toTopOf="parent" />
<Button <Button
android:id="@+id/takepic" android:id="@+id/takepic"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="20dp" android:layout_marginBottom="40dp"
android:layout_marginTop="10dp" android:background="@mipmap/takepic"
android:shadowColor="@null"
android:text="拍照" android:text="拍照"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/iso" /> app:layout_constraintRight_toRightOf="parent" />
<Button
android:id="@+id/tojpg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="转jpg"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/takepic" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Loading…
Cancel
Save