dng自动转png

mem
liuguijing 6 months ago
parent c7c564ddec
commit 92ec7a8535

@ -23,7 +23,7 @@ android {
// arguments "-DANDROID_STL=c++_shared" // arguments "-DANDROID_STL=c++_shared"
// arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DNCNN_ROOT=" + ncnnroot // arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DNCNN_ROOT=" + ncnnroot
arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni" arguments "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni"
abiFilters 'arm64-v8a', 'armeabi-v7a' abiFilters 'arm64-v8a'
// setAbiFilters(['arm64-v8a']) // setAbiFilters(['arm64-v8a'])
} }
} }
@ -36,11 +36,11 @@ android {
} }
} }
sourceSets { // sourceSets {
main{ // main{
jniLibs.srcDirs=['src/main/jniLibs'] // jniLibs.srcDirs=['src/main/jniLibs']
} // }
} // }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8

@ -5,9 +5,7 @@
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- A camera with RAW capability is required to use this application -->
<!-- A camera with RAW capability is required to use this application -->
<uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.raw" /> <uses-feature android:name="android.hardware.camera.raw" />
@ -22,7 +20,10 @@
android:theme="@style/Theme.MpPreview" android:theme="@style/Theme.MpPreview"
tools:targetApi="31"> tools:targetApi="31">
<activity <activity
android:name="com.xypower.mppreview.MainActivity" android:name=".CameraActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -30,6 +31,17 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.stg.rouge.activity.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths_public"
tools:replace="android:resource" />
</provider>
</application> </application>
</manifest> </manifest>

@ -79,7 +79,7 @@ bool makeHdr(std::vector<float>& times, std::vector<std::string>& paths, cv::Mat
extern "C" extern "C"
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_com_xypower_camera2raw_Camera2RawFragment_makeHdr__JLjava_lang_String_2JLjava_lang_String_2Ljava_lang_String_2( Java_com_xypower_mppreview_Camera2RawFragment_makeHdr(
JNIEnv *env, jobject thiz, jlong exposureTime1, jstring path1, jlong exposureTime2, JNIEnv *env, jobject thiz, jlong exposureTime1, jstring path1, jlong exposureTime2,
jstring path2, jstring outputPath) { jstring path2, jstring outputPath) {
@ -107,7 +107,7 @@ Java_com_xypower_camera2raw_Camera2RawFragment_makeHdr__JLjava_lang_String_2JLja
extern "C" extern "C"
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_com_xypower_camera2raw_Camera2RawFragment_makeHdr__JLjava_lang_String_2JLjava_lang_String_2JLjava_lang_String_2Ljava_lang_String_2( Java_com_xypower_mppreview_Camera2RawFragment_makeHdr2(
JNIEnv *env, jobject thiz, jlong exposureTime1, jstring path1, jlong exposureTime2, JNIEnv *env, jobject thiz, jlong exposureTime1, jstring path1, jlong exposureTime2,
jstring path2, jlong exposureTime3, jstring path3, jstring outputPath) { jstring path2, jlong exposureTime3, jstring path3, jstring outputPath) {

@ -1,5 +1,7 @@
package com.xypower.mppreview; package com.xypower.mppreview;
import static java.lang.System.loadLibrary;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
@ -28,8 +30,6 @@ import android.hardware.camera2.params.MeteringRectangle;
import android.hardware.camera2.params.StreamConfigurationMap; import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.Image; import android.media.Image;
import android.media.ImageReader; import android.media.ImageReader;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -86,6 +86,12 @@ import java.util.concurrent.atomic.AtomicInteger;
*/ */
public class Camera2RawFragment extends Fragment { public class Camera2RawFragment extends Fragment {
private static int covertNum;
static {
loadLibrary("mppreview");
}
/** /**
* Conversion from screen rotation to JPEG orientation. * Conversion from screen rotation to JPEG orientation.
*/ */
@ -162,8 +168,10 @@ public class Camera2RawFragment extends Fragment {
*/ */
private OrientationEventListener mOrientationListener; private OrientationEventListener mOrientationListener;
private 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);
private native boolean makeHdr(long exposureTime1, String path1, long exposureTime2, String path2, long exposureTime3, String path3, String outputPath);
public static native boolean makeHdr2(long exposureTime1, String path1, long exposureTime2, String path2, long exposureTime3, String path3, String outputPath);
private int mExposureComp = MainActivity.ExposureComp; private int mExposureComp = MainActivity.ExposureComp;
@ -392,7 +400,7 @@ public class Camera2RawFragment extends Fragment {
private Long exposetime; private Long exposetime;
private Integer sensitivity; private Integer sensitivity;
/** /**
/** * /**
* A {@link CameraCaptureSession.CaptureCallback} that handles events for the preview and * A {@link CameraCaptureSession.CaptureCallback} that handles events for the preview and
* pre-capture sequence. * pre-capture sequence.
*/ */
@ -614,21 +622,51 @@ public class Camera2RawFragment extends Fragment {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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); File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
String dcimpath = directory.getPath();
List<String> strings = RawToJpgConverter.listFiles(directory); 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) { if (strings != null && strings.size() > 0) {
for (String item : strings) { for (String item : strings) {
if (item.contains("RAW")) { if (item.contains("create")) {
String[] s = item.split("_");
File file1 = new File(directory, item); File file1 = new File(directory, item);
File file2 = new File(directory, "create_" + item + ".jpg"); PngPhotoBean bean = new PngPhotoBean();
try { bean.etime = Long.parseLong(s[1]);
RawToJpgConverter.convertRawToJpg(file1.getPath(), file2.getPath()); bean.path = file1.getPath();
} catch (IOException e) { list.add(bean);
throw new RuntimeException(e); 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");
}
} }
}); });
@ -1130,7 +1168,7 @@ 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());
@ -1270,10 +1308,10 @@ public class Camera2RawFragment extends Fragment {
Rational rational = mCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP); Rational rational = mCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
double step = rational.doubleValue(); double step = rational.doubleValue();
// mCharacteristics.get(CameraMetadata.CONTROL_AE_COMPENSATION_STEP) // mCharacteristics.get(CameraMetadata.CONTROL_AE_COMPENSATION_STEP)
List<CaptureRequest> requests = new ArrayList<>(); List<CaptureRequest> requests = new ArrayList<>();
for (int idx = 0; idx < 10; idx++) { double v = 0;
for (int idx = 0; idx < 2; idx++) {
// Set request tag to easily track results in callbacks. // Set request tag to easily track results in callbacks.
captureBuilder.setTag(mRequestCounter.getAndIncrement()); captureBuilder.setTag(mRequestCounter.getAndIncrement());
@ -1284,7 +1322,7 @@ public class Camera2RawFragment extends Fragment {
if (isHandTakePic) { if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) { if (exposureTime > 0) {
double v = exposureTime * pic1; v = exposureTime * pic1;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
} }
if (sensitivity > 0) { if (sensitivity > 0) {
@ -1300,142 +1338,7 @@ public class Camera2RawFragment extends Fragment {
if (isHandTakePic) { if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF); captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) { if (exposureTime > 0) {
double v = exposureTime * 2; v = exposureTime * 7;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 2) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 3;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 3) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 4;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 4) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 5;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 5) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 6;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 6) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 7;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 7) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 8;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 8) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 9;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 9) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 10;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
}
if (sensitivity > 0) {
captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, 100);
}
}
}
if (idx == 10) {
// captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, new Integer(4));
// 设置曝光时间例如设置为1000微秒
// long exposureTime = 1000 000000L; // 1000微秒
if (isHandTakePic) {
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
if (exposureTime > 0) {
double v = exposureTime * 11;
captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v); captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) v);
} }
if (sensitivity > 0) { if (sensitivity > 0) {
@ -1451,6 +1354,8 @@ public class Camera2RawFragment extends Fragment {
ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(activity).setCharacteristics(mCharacteristics); ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(activity).setCharacteristics(mCharacteristics);
ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(activity).setCharacteristics(mCharacteristics); ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(activity).setCharacteristics(mCharacteristics);
rawBuilder.setExposetime((long) v);
mJpegResultQueue.put((int) request.getTag(), jpegBuilder); mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
mRawResultQueue.put((int) request.getTag(), rawBuilder); mRawResultQueue.put((int) request.getTag(), rawBuilder);
@ -1591,14 +1496,16 @@ public class Camera2RawFragment extends Fragment {
* A reference counted wrapper for the ImageReader that owns the given image. * A reference counted wrapper for the ImageReader that owns the given image.
*/ */
private final RefCountedAutoCloseable<ImageReader> mReader; private final RefCountedAutoCloseable<ImageReader> mReader;
private final long mExpostime;
private ImageSaver(Image image, File file, CaptureResult result, CameraCharacteristics characteristics, Context context, RefCountedAutoCloseable<ImageReader> reader) { private ImageSaver(Image image, File file, CaptureResult result, CameraCharacteristics characteristics, Context context, RefCountedAutoCloseable<ImageReader> reader, long mexpostime) {
mImage = image; mImage = image;
mFile = file; mFile = file;
mCaptureResult = result; mCaptureResult = result;
mCharacteristics = characteristics; mCharacteristics = characteristics;
mContext = context; mContext = context;
mReader = reader; mReader = reader;
mExpostime = mexpostime;
} }
@Override @Override
@ -1649,19 +1556,28 @@ public class Camera2RawFragment extends Fragment {
// If saving the file succeeded, update MediaStore. // If saving the file succeeded, update MediaStore.
if (success) { if (success) {
MediaScannerConnection.scanFile(mContext, new String[]{mFile.getPath()}, File directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
/*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() { File file = new File(directory, "create_" + mExpostime + "_" + generateTimestamp() + ".png");
@Override try {
public void onMediaScannerConnected() { RawToJpgConverter.convertRawToJpg(mFile.getPath(), file.getPath());
// Do nothing } catch (IOException e) {
} throw new RuntimeException(e);
}
@Override // covertNum++;
public void onScanCompleted(String path, Uri uri) { // MediaScannerConnection.scanFile(mContext, new String[]{mFile.getPath()},
Log.i(TAG, "Scanned " + path + ":"); // /*mimeTypes*/null, new MediaScannerConnection.MediaScannerConnectionClient() {
Log.i(TAG, "-> uri=" + uri); // @Override
} // public void onMediaScannerConnected() {
}); // // Do nothing
// }
//
// @Override
// public void onScanCompleted(String path, Uri uri) {
// Log.i(TAG, "Scanned " + path + ":");
// Log.i(TAG, "-> uri=" + uri);
// }
// });
} }
} }
@ -1676,6 +1592,8 @@ public class Camera2RawFragment extends Fragment {
private CaptureResult mCaptureResult; private CaptureResult mCaptureResult;
private CameraCharacteristics mCharacteristics; private CameraCharacteristics mCharacteristics;
private Context mContext; private Context mContext;
private long mexpostime;
private RefCountedAutoCloseable<ImageReader> mReader; private RefCountedAutoCloseable<ImageReader> mReader;
/** /**
@ -1688,6 +1606,12 @@ public class Camera2RawFragment extends Fragment {
mContext = context; mContext = context;
} }
public synchronized ImageSaverBuilder setExposetime(long time) {
mexpostime = time;
return this;
}
public synchronized ImageSaverBuilder setRefCountedReader(RefCountedAutoCloseable<ImageReader> reader) { public synchronized ImageSaverBuilder setRefCountedReader(RefCountedAutoCloseable<ImageReader> reader) {
if (reader == null) throw new NullPointerException(); if (reader == null) throw new NullPointerException();
@ -1723,7 +1647,7 @@ public class Camera2RawFragment extends Fragment {
if (!isComplete()) { if (!isComplete()) {
return null; return null;
} }
return new ImageSaver(mImage, mFile, mCaptureResult, mCharacteristics, mContext, mReader); return new ImageSaver(mImage, mFile, mCaptureResult, mCharacteristics, mContext, mReader, mexpostime);
} }
public synchronized String getSaveLocation() { public synchronized String getSaveLocation() {

@ -0,0 +1,17 @@
package com.xypower.mppreview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class CameraActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
if (null == savedInstanceState) {
getSupportFragmentManager().beginTransaction().setReorderingAllowed(true).replace(R.id.container, Camera2RawFragment.class, null).commit();
}
}
}

@ -0,0 +1,8 @@
package com.xypower.mppreview;
import static java.lang.System.loadLibrary;
public class HdrUtil {
}

@ -1,22 +1,57 @@
package com.xypower.mppreview; package com.xypower.mppreview;
import androidx.appcompat.app.AlertDialog; import static java.lang.System.loadLibrary;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.text.Editable;
import android.view.MenuItem; import android.view.View;
import android.widget.Button;
//import org.opencv.android.OpenCVLoader; import android.widget.EditText;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static int ExposureComp = 0; public static int ExposureComp = 0;
private EditText hdrnum;
private Button systakepic;
private Button hdrtakepic;
private ActivityResultLauncher<Intent> photoResultLauncher;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
initView();
initActivityResult();
}
private void initView() {
hdrtakepic = findViewById(R.id.hdrtakepic);
systakepic = findViewById(R.id.systakepic);
hdrnum = findViewById(R.id.hdr_num);
hdrtakepic.setOnClickListener(this);
systakepic.setOnClickListener(this);
}
private void initActivityResult() {
photoResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
}
});
} }
@Override @Override
@ -29,85 +64,41 @@ public class MainActivity extends AppCompatActivity {
// } // }
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
int comp = -1000;
switch (id) {
case R.id.action_picture:
takePicture();
break;
case R.id.action_focus:
doFocus();
break;
case R.id.action_comp0:
comp = 0;
break;
case R.id.action_comp1:
comp = 1;
break;
case R.id.action_comp2:
comp = 2;
break;
case R.id.action_comp3:
comp = 3;
break;
case R.id.action_comp4:
comp = 4;
break;
case R.id.action_comp_1:
comp = -1;
break;
case R.id.action_comp_2:
comp = -2;
break;
case R.id.action_comp_3:
comp = -3;
break;
case R.id.action_comp_4:
comp = -4;
break;
case R.id.action_info:
new AlertDialog.Builder(this)
.setMessage(R.string.intro_message)
.setPositiveButton(android.R.string.ok, null)
.show();
break;
default:
break;
}
if (comp> -1000) {
ExposureComp = comp;
restartFragment();
}
return super.onOptionsItemSelected(item);
}
private void restartFragment() { private void restartFragment() {
getSupportFragmentManager().beginTransaction().replace(R.id.container, Camera2RawFragment.newInstance()).commit();
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, Camera2RawFragment.newInstance())
.commit();
} }
private void doFocus() { private void doFocus() {
Camera2RawFragment fragment = (Camera2RawFragment)getSupportFragmentManager().findFragmentById(R.id.container); Camera2RawFragment fragment = (Camera2RawFragment) getSupportFragmentManager().findFragmentById(R.id.container);
fragment.doFocus(); fragment.doFocus();
} }
private void takePicture() { private void takePicture() {
Camera2RawFragment fragment = (Camera2RawFragment)getSupportFragmentManager().findFragmentById(R.id.container); Camera2RawFragment fragment = (Camera2RawFragment) getSupportFragmentManager().findFragmentById(R.id.container);
fragment.isHandTakePic = false; fragment.isHandTakePic = false;
fragment.takePicture(); fragment.takePicture();
} }
@Override
public void onClick(View view) {
int id = view.getId();
switch (id) {
case R.id.hdrtakepic:
Intent intent = new Intent(this, CameraActivity.class);
Editable text = hdrnum.getText();
String s = text.toString();
if (s != null && !s.equals("")) {
double v = Double.parseDouble(s);
intent.putExtra("hdrnum", v);
}
startActivity(intent);
break;
case R.id.systakepic:
PhotoUtil.openCamera(this, photoResultLauncher);
break;
}
}
} }

@ -0,0 +1,83 @@
package com.xypower.mppreview;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import androidx.activity.result.ActivityResultLauncher;
import androidx.core.content.FileProvider;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PhotoUtil {
/**
* photoUri
*/
private static Uri photoUri;
/**
*
*/
public static void openCamera(Context context, ActivityResultLauncher<Intent> photoResultLauncher) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//确保有相机来处理Intent
if (takePictureIntent.resolveActivity(context.getPackageManager()) != null) {
File photoFile = saveFileName(context);
if (photoFile != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//适配Android 7.0文件权限通过FileProvider创建一个content类型的Uri
photoUri = FileProvider.getUriForFile(context.getApplicationContext(), "com.stg.rouge.activity.fileprovider", photoFile);
} else {
photoUri = getDestinationUri(context);
}
takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
photoResultLauncher.launch(takePictureIntent);
}
}
}
/**
* Uri
*
* @return
*/
private static Uri getDestinationUri(Context context) {
String fileName = String.format("winetalk_%s.jpg", System.currentTimeMillis());
File cropFile = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName);
return Uri.fromFile(cropFile);
}
//当前路径,拍照回调后需要使用
private String currentPath = null;
/**
*
*
* @return
*/
private static File saveFileName(Context context) {
File newFolder = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date date = new Date(System.currentTimeMillis());
String name = format.format(date) + ".jpg";
File ji = null;
try {
ji = new File(newFolder + "/" + name);
ji.createNewFile();
// currentPath = ji.getAbsolutePath();
} catch (Exception e) {
e.printStackTrace();
}
return ji;
}
}

@ -0,0 +1,10 @@
package com.xypower.mppreview;
public class PngPhotoBean {
public long etime;
public String path;
}

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CameraActivity">
<!-- res/layout/example_activity.xml -->
<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -4,13 +4,54 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingTop="20dp"
android:paddingRight="15dp"
tools:context=".MainActivity"> tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView <!-- <Switch-->
android:id="@+id/container" <!-- android:id="@+id/hdr"-->
android:name="com.xypower.mppreview.Camera2RawFragment" <!-- android:layout_width="wrap_content"-->
android:layout_width="match_parent" <!-- android:layout_height="wrap_content"-->
android:layout_height="match_parent" <!-- android:layout_marginLeft="15dp"-->
tools:layout_editor_absoluteX="190dp" <!-- android:layout_marginTop="20dp"-->
tools:layout_editor_absoluteY="311dp" /> <!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
<TextView
android:id="@+id/hdrhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="曝光补偿:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/hdr_num"
android:layout_width="50dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/hdrhint"
app:layout_constraintLeft_toRightOf="@+id/hdrhint"
app:layout_constraintTop_toTopOf="@+id/hdrhint" />
<Button
android:id="@+id/hdrtakepic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="HDR拍照"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/hdrhint" />
<Button
android:id="@+id/systakepic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="拍照"
app:layout_constraintLeft_toRightOf="@id/hdrtakepic"
app:layout_constraintTop_toTopOf="@+id/hdrtakepic" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>
Loading…
Cancel
Save