代码: imagearray是String的数组。
ParcelFileDescriptor fd;
Uri imageUri2=Uri.parse(imagearray[1]);
try {
fd = getContentResolver().openFileDescriptor(imageUri2, "r");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bmp2 = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
Bitmap resized2 = Bitmap.createScaledBitmap(bmp2, 100, 100, true);
Bitmap conv_bm2 = ImageCropScale.getRoundedRectBitmap(resized2, 100);
ib2.setImageBitmap(conv_bm2);
LogCat:应用程序
try{ 07-15 17:58:26.121: I/Process(9506): Sending signal. PID: 9506 SIG: 9
07-15 17:59:52.062: D/AndroidRuntime(9905): Shutting down VM
07-15 17:59:52.062: W/dalvikvm(9905): threadid=1: thread exiting with uncaught exception (group=0x41664d40)
07-15 17:59:52.069: E/AndroidRuntime(9905): FATAL EXCEPTION: main
07-15 17:59:52.069: E/AndroidRuntime(9905): Process: com.example.withimage, PID: 9905
07-15 17:59:52.069: E/AndroidRuntime(9905): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.withimage/com.example.withimage.PictureChange}: java.lang.SecurityException:
Permission Denial: reading com.android.providers.media.MediaProvider uri
content://media/external/images/media/4534 from pid=9905, uid=10103 requires
android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.app.ActivityThread.access$800(ActivityThread.java:139)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
07-15 17:59:52.069: E/AndroidRuntime(9905): at android.os.Handler.dispatchMessage(Handler.java:102)
07-15 17:59:52.069: E/AndroidRuntime(9905): at android.os.Looper.loop(Looper.java:136)
07-15 17:59:52.069: E/AndroidRuntime(9905): at android.app.ActivityThread.main(ActivityThread.java:5086)
07-15 17:59:52.069: E/AndroidRuntime(9905): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 17:59:52.069: E/AndroidRuntime(9905): at java.lang.reflect.Method.invoke(Method.java:515)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-15 17:59:52.069: E/AndroidRuntime(9905): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-15 17:59:52.069: E/AndroidRuntime(9905): at dalvik.system.NativeStart.main(Native Method)
07-15 17:59:52.069: E/AndroidRuntime(9905): Caused by: java.lang.SecurityException: Permission Denial: reading
com.android.providers.media.MediaProvider uri content://media/external/images/media/4534 from pid=9905,
uid=10103 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
07-15 17:59:52.069: E/AndroidRuntime(9905): at android.os.Parcel.readException(Parcel.java:1465)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:148)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:682)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1063)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:904)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.content.ContentResolver.openFileDescriptor(ContentResolver.java:761)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.content.ContentResolver.openFileDescriptor(ContentResolver.java:716)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
com.example.withimage.PictureChange.onCreate(PictureChange.java:82)
07-15 17:59:52.069: E/AndroidRuntime(9905): at android.app.Activity.performCreate(Activity.java:5248)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
07-15 17:59:52.069: E/AndroidRuntime(9905): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
07-15 17:59:52.069: E/AndroidRuntime(9905): ... 11 more
07-15 17:59:54.341: I/Process(9905): Sending signal. PID: 9905 SIG: 9
新的LogCat:应用程序的 对于某些图像,它适用于其他只是停止工作。
/*try(07-15 19:11:43.037: I/Adreno-EGL(24501): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:
AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018_msm8610_LNX.LA.3.5.1_RB1__release_AU ()
07-15 19:11:43.037: I/Adreno-EGL(24501): OpenGL ES Shader Compiler Version: E031.24.00.08
07-15 19:11:43.037: I/Adreno-EGL(24501): Build Date: 03/07/14 Fri
07-15 19:11:43.037: I/Adreno-EGL(24501): Local Branch:
07-15 19:11:43.037: I/Adreno-EGL(24501): Remote Branch: quic/LNX.LA.3.5.1_RB1.1
07-15 19:11:43.037: I/Adreno-EGL(24501): Local Patches: NONE
07-15 19:11:43.037: I/Adreno-EGL(24501): Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.018
+ f2fd134 + NOTHING
07-15 19:11:43.065: D/OpenGLRenderer(24501): Enabling debug mode 0
07-15 19:11:51.805: D/dalvikvm(24501): GC_FOR_ALLOC freed 115K, 72% free 3180K/11120K, paused 12ms, total 13ms
07-15 19:11:51.843: I/dalvikvm-heap(24501): Grow heap (frag case) to 19.623MB for 15095824-byte allocation
07-15 19:11:52.014: D/dalvikvm(24501): GC_FOR_ALLOC freed 14K, 31% free 17989K/25864K, paused 12ms, total 12ms
07-15 19:11:52.047: I/dalvikvm-heap(24501): Grow heap (frag case) to 34.084MB for 15095824-byte allocation
07-15 19:11:52.211: D/dalvikvm(24501): GC_FOR_ALLOC freed 1K, 20% free 32810K/40608K, paused 12ms, total 14ms
07-15 19:11:52.287: D/dalvikvm(24501): GC_FOR_ALLOC freed 1K, 11% free 36489K/40608K, paused 12ms, total 12ms
07-15 19:11:52.315: I/dalvikvm-heap(24501): Grow heap (frag case) to 52.150MB for 15095824-byte allocation
07-15 19:11:52.490: D/dalvikvm(24501): GC_FOR_ALLOC freed 1K, 8% free 51310K/55352K, paused 12ms, total 12ms
07-15 19:11:52.520: I/dalvikvm-heap(24501): Grow heap (frag case) to 66.624MB for 15095824-byte allocation
07-15 19:11:52.687: D/dalvikvm(24501): GC_FOR_ALLOC freed 1K, 6% free 66131K/70096K, paused 13ms, total 13ms
07-15 19:11:52.716: I/dalvikvm-heap(24501): Grow heap (frag case) to 81.097MB for 15095824-byte allocation
07-15 19:11:52.911: D/dalvikvm(24501): GC_FOR_ALLOC freed 1K, 5% free 80952K/84840K, paused 14ms, total 14ms
07-15 19:11:52.911: I/dalvikvm-heap(24501): Forcing collection of SoftReferences for 15095824-byte allocation
07-15 19:11:52.933: D/dalvikvm(24501): GC_BEFORE_OOM freed 9K, 5% free 80942K/84840K, paused 22ms, total 22ms
07-15 19:11:52.933: E/dalvikvm-heap(24501): Out of memory on a 15095824-byte allocation.
07-15 19:11:52.933: I/dalvikvm(24501): "main" prio=5 tid=1 RUNNABLE
07-15 19:11:52.933: I/dalvikvm(24501): | group="main" sCount=0 dsCount=0 obj=0x41665e40 self=0x41587520
07-15 19:11:52.934: I/dalvikvm(24501): | sysTid=24501 nice=0 sched=0/0 cgrp=apps handle=1074438484
07-15 19:11:52.934: I/dalvikvm(24501): | state=R schedstat=( 0 0 0 ) utm=109 stm=17 core=0
07-15 19:11:52.934: I/dalvikvm(24501): at android.graphics.BitmapFactory.nativeDecodeFileDescriptor(Native
Method)
07-15 19:11:52.934: I/dalvikvm(24501): at
android.graphics.BitmapFactory.decodeFileDescriptor(BitmapFactory.java:657)
07-15 19:11:52.934: I/dalvikvm(24501): at
android.graphics.BitmapFactory.decodeFileDescriptor(BitmapFactory.java:689)
07-15 19:11:52.935: I/dalvikvm(24501): at
com.example.withimage.PictureChange.onCreate(PictureChange.java:207)
07-15 19:11:52.935: I/dalvikvm(24501): at android.app.Activity.performCreate(Activity.java:5248)
07-15 19:11:52.935: I/dalvikvm(24501): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
07-15 19:11:52.935: I/dalvikvm(24501): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
07-15 19:11:52.935: I/dalvikvm(24501): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
07-15 19:11:52.935: I/dalvikvm(24501): at android.app.ActivityThread.access$800(ActivityThread.java:139)
07-15 19:11:52.935: I/dalvikvm(24501): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
07-15 19:11:52.935: I/dalvikvm(24501): at android.os.Handler.dispatchMessage(Handler.java:102)
07-15 19:11:52.936: I/dalvikvm(24501): at android.os.Looper.loop(Looper.java:136)
07-15 19:11:52.936: I/dalvikvm(24501): at android.app.ActivityThread.main(ActivityThread.java:5086)
07-15 19:11:52.936: I/dalvikvm(24501): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 19:11:52.936: I/dalvikvm(24501): at java.lang.reflect.Method.invoke(Method.java:515)
07-15 19:11:52.936: I/dalvikvm(24501): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-15 19:11:52.936: I/dalvikvm(24501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-15 19:11:52.937: I/dalvikvm(24501): at dalvik.system.NativeStart.main(Native Method)
07-15 19:11:52.937: D/skia(24501): --- decoder->decode returned false
07-15 19:11:52.938: D/AndroidRuntime(24501): Shutting down VM
07-15 19:11:52.938: W/dalvikvm(24501): threadid=1: thread exiting with uncaught exception (group=0x41664d40)
07-15 19:11:52.941: E/AndroidRuntime(24501): FATAL EXCEPTION: main
07-15 19:11:52.941: E/AndroidRuntime(24501): Process: com.example.withimage, PID: 24501
07-15 19:11:52.941: E/AndroidRuntime(24501): java.lang.OutOfMemoryError
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.graphics.BitmapFactory.nativeDecodeFileDescriptor(Native Method)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.graphics.BitmapFactory.decodeFileDescriptor(BitmapFactory.java:657)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.graphics.BitmapFactory.decodeFileDescriptor(BitmapFactory.java:689)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
com.example.withimage.PictureChange.onCreate(PictureChange.java:207)
07-15 19:11:52.941: E/AndroidRuntime(24501): at android.app.Activity.performCreate(Activity.java:5248)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.app.ActivityThread.access$800(ActivityThread.java:139)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
07-15 19:11:52.941: E/AndroidRuntime(24501): at android.os.Handler.dispatchMessage(Handler.java:102)
07-15 19:11:52.941: E/AndroidRuntime(24501): at android.os.Looper.loop(Looper.java:136)
07-15 19:11:52.941: E/AndroidRuntime(24501): at android.app.ActivityThread.main(ActivityThread.java:5086)
07-15 19:11:52.941: E/AndroidRuntime(24501): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 19:11:52.941: E/AndroidRuntime(24501): at java.lang.reflect.Method.invoke(Method.java:515)
07-15 19:11:52.941: E/AndroidRuntime(24501): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-15 19:11:52.941: E/AndroidRuntime(24501): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-15 19:11:52.941: E/AndroidRuntime(24501): at dalvik.system.NativeStart.main(Native Method)*/)}
有些线是额外的一些线是额外的一些线是额外的一些线是额外的一些线是额外的一些线是额外的 有些线是额外的一些线是额外的一些线是额外的一些线是额外的一些线是额外的一些线是额外的 有些线是额外的一些线是额外的一些线是额外的一些线是额外的一些线是额外的线是额外的 非常感谢你
答案 0 :(得分:1)
请试试这个。 在 AndroidManifest.xml 文件中添加 READ_EXTERNAL_STORAGE 权限
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
答案 1 :(得分:0)
在项目的Androidmanifest文件中添加此权限,位于应用程序标记
的正上方<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
要写入外部存储,您确实必须在清单中声明这一点。另请参阅http://developer.android.com/reference/android/Manifest.permission.html以详细了解权限及其所需的原因。