diff --git a/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java b/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java index 79f8919..13c354f 100644 --- a/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java +++ b/app/src/main/java/com/xypower/mppreview/Camera2RawFragment.java @@ -167,6 +167,7 @@ public class Camera2RawFragment extends Fragment { * but the orientation of the has changed, and thus the preview rotation must be updated. */ private OrientationEventListener mOrientationListener; + private static ArrayList list = new ArrayList<>();//用来存储已拍照的照片名称 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 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() { @Override public void onClick(View view) { 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(); } }); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { -// File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); -// List 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 strings = RawToJpgConverter.listFiles(directory); - long t1; - long t2; - String p1; - String p2; - ArrayList 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 @@ -1167,8 +1076,8 @@ public class Camera2RawFragment extends Fragment { } // 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 = new Size(3840, 2160); + Size previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedViewWidth, rotatedViewHeight, maxPreviewWidth, maxPreviewHeight, largestJpeg); +// Size previewSize = new Size(3840, 2160); if (swappedDimensions) { 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. - *

- * This can be constructed through an {@link ImageSaverBuilder} as the necessary image and - * result information becomes available. - */ private static class ImageSaver implements Runnable { /** @@ -1550,34 +1452,26 @@ public class Camera2RawFragment extends Fragment { break; } } - - // Decrement reference count to allow ImageReader to be closed to free up resources. mReader.close(); - - // If saving the file succeeded, update MediaStore. if (success) { File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM); + String directoryPath = directory.getPath(); File file = new File(directory, "create_" + mExpostime + "_" + generateTimestamp() + ".png"); + String path = file.getPath(); try { - RawToJpgConverter.convertRawToJpg(mFile.getPath(), file.getPath()); + RawToJpgConverter.convertRawToJpg(mFile.getPath(), path); } catch (IOException e) { throw new RuntimeException(e); } - -// covertNum++; -// MediaScannerConnection.scanFile(mContext, new String[]{mFile.getPath()}, -// /*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() { -// @Override -// public void onMediaScannerConnected() { -// // Do nothing -// } -// -// @Override -// public void onScanCompleted(String path, Uri uri) { -// Log.i(TAG, "Scanned " + path + ":"); -// Log.i(TAG, "-> uri=" + uri); -// } -// }); + PngPhotoBean bean = new PngPhotoBean(); + bean.setEtime(mExpostime); + bean.setPath(path); + list.add(bean); + if (list.size() == 2) { + PngPhotoBean bean1 = list.get(0); + PngPhotoBean bean2 = list.get(1); + makeHdr(bean1.getEtime(), bean1.getPath(), bean2.getEtime(), bean2.getPath(), directoryPath + "/" + "hdr_" + generateTimestamp() + ".png"); + } } } diff --git a/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java b/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java index 34f57af..d732c11 100644 --- a/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java +++ b/app/src/main/java/com/xypower/mppreview/PngPhotoBean.java @@ -2,9 +2,22 @@ package com.xypower.mppreview; public class PngPhotoBean { - public long etime; - public String path; + private long etime; + 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; + } } diff --git a/app/src/main/java/com/xypower/mppreview/RawToJpgConverter.java b/app/src/main/java/com/xypower/mppreview/RawToJpgConverter.java index 3e512cf..3503a86 100644 --- a/app/src/main/java/com/xypower/mppreview/RawToJpgConverter.java +++ b/app/src/main/java/com/xypower/mppreview/RawToJpgConverter.java @@ -77,7 +77,7 @@ public class RawToJpgConverter { ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); // 5. 将Bitmap以JPG格式编码到输出流中 - rawBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytestream); + rawBitmap.compress(Bitmap.CompressFormat.PNG, 100, bytestream); // 6. 将输出流转换为字节数组,并关闭输出流 byte[] jpgData = bytestream.toByteArray(); diff --git a/app/src/main/res/layout/fragment_camera2_raw.xml b/app/src/main/res/layout/fragment_camera2_raw.xml index dfb3882..2f20fae 100644 --- a/app/src/main/res/layout/fragment_camera2_raw.xml +++ b/app/src/main/res/layout/fragment_camera2_raw.xml @@ -12,45 +12,16 @@ android:layout_height="match_parent" /> - - - -