这是保存照片的功能。我想把照片放在画廊里。
public File getOutputMediaFile() {
File dir2 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "dentafy");
String timeStamp = new SimpleDateFormat("yyMMdd_HHmmss", Locale.getDefault()).format(new Date());
String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
String filename = File.separator + "2IMG_" + timeStamp + ".jpg";
Log.d("getOutMediaFile", filename);
File c = new File(dir2.getPath(), filename);
filepath = filename;
picturepath();
return c;
}
public String picturepath( )
{
return filepath;
}
答案 0 :(得分:0)
查看你的日志(我删除了不相关的行):
06-28 13:17:12.165 17307-17307/com.example.newrosoft1.dentafy I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
06-28 13:17:12.195 17307-17307/com.example.newrosoft1.dentafy D/dalvikvm: GC_FOR_ALLOC freed 10802K, 2% free 58270K/59144K, paused 30ms, total 30ms
06-28 13:44:21.398 24638-24638/com.example.newrosoft1.dentafy D/Activity: performCreate Call debug elastic valuetrue
06-28 13:44:21.458 24638-24638/com.example.newrosoft1.dentafy I/Timeline: Timeline: Activity_launch_request id:com.example.newrosoft1.dentafy time:156085873
06-28 13:44:22.619 24638-24638/com.example.newrosoft1.dentafy D/valoare este %@: file:///file%3A/storage/emulated/0/Android/data/com.example.newrosoft1.dentafy/files/Pictures/JPEG_20160628_134421_558130986.jpg
06-28 13:44:22.619 24638-24638/com.example.newrosoft1.dentafy D/valoare 2 este %@: file:///file%3A/storage/emulated/0/Android/data/com.example.newrosoft1.dentafy/files/Pictures/JPEG_20160628_134421_558130986.jpg
06-28 13:44:23.140 24638-24638/com.example.newrosoft1.dentafy I/art: Alloc sticky concurrent mark sweep GC freed 198(22KB) AllocSpace objects, 0(0B) LOS objects, 6% free, 107MB/115MB, paused 732us total 10.467ms
06-28 13:44:23.160 24638-24638/com.example.newrosoft1.dentafy I/art: Alloc partial concurrent mark sweep GC freed 1281(108KB) AllocSpace objects, 1(16KB) LOS objects, 12% free, 107MB/123MB, paused 732us total 16.082ms
06-28 13:44:23.190 24638-24638/com.example.newrosoft1.dentafy I/art: Alloc concurrent mark sweep GC freed 16(12KB) AllocSpace objects, 0(0B) LOS objects, 12% free, 107MB/123MB, paused 732us total 30.761ms
06-28 13:44:23.190 24638-24638/com.example.newrosoft1.dentafy I/art: Forcing collection of SoftReferences for 36MB allocation
06-28 13:44:23.210 24638-24638/com.example.newrosoft1.dentafy I/art: Alloc concurrent mark sweep GC freed 11(344B) AllocSpace objects, 0(0B) LOS objects, 12% free, 107MB/123MB, paused 610us total 22.705ms
06-28 13:44:23.210 24638-24638/com.example.newrosoft1.dentafy E/art: Throwing OutOfMemoryError "Failed to allocate a 38340876 byte allocation with 16777120 free bytes and 20MB until OOM"
06-28 13:44:23.210 24638-24638/com.example.newrosoft1.dentafy D/skia: --- decoder->decode returned false
06-28 13:44:23.210 24638-24638/com.example.newrosoft1.dentafy D/AndroidRuntime: Shutting down VM
06-28 13:44:23.220 24638-24638/com.example.newrosoft1.dentafy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.newrosoft1.dentafy, PID: 24638
java.lang.OutOfMemoryError: Failed to allocate a 38340876 byte allocation with 16777120 free bytes and 20MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:752)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:728)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:477)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:515)
at com.example.newrosoft1.dentafy.PictureConfirmation.onCreate(PictureConfirmation.java:411)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2655)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2767)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1449)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
前置摄像头和后置摄像头之间的区别在于后者拍摄的图像要大得多,并且无法将其全尺寸转换为位图以在ImageView中显示它:您跨越了应用程序内存限制。您可以增加应用程序允许的内存量,但更好 - 减小位图的大小。在这里,您有两种选择:将后置摄像头的图片大小设置得更小(最好适合图像视图的大小),或者在decodeFile()
中缩小位图。