Android: Comment charger une image en Bitmap

Je suis en mesure de charger une image de ressource, de drawable dossier, dans une image et la même échelle fine, mais maintenant j'ai besoin de charger une image à partir de n'importe quel stockées sur la Carte SD, et je peux voir ce qui va me permettre d'afficher et de sélectionner;

    startActivityForResult(new Intent(Intent.ACTION_PICK,
         android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);

Cependant jusqu'à présent, j'ai été incapable de trouver exactement ce que les données sont renvoyées et comment le charger dans un bitmap.

Mise à JOUR:

C'est maintenant ce que je suis;

@Override
protected void onActivityResult(int requestCode, int resultCode,
            Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);

if (resultCode == RESULT_OK) {

    Uri contentURI =  Uri.parse(intent.getDataString());

    c = mSurfaceHolder.lockCanvas();

    tempCanvas.setBitmap(mDrawing);

    Bitmap tempBitmap = null;

    ContentResolver cr = getContentResolver();

    try {           
      InputStream in = cr.openInputStream(contentURI);
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inSampleSize=8;
      tempBitmap = BitmapFactory.decodeStream(in,null,options);
        }
    catch (Exception ee) {
      tempBitmap = BitmapFactory.decodeResource(getResources(),
                    R.drawable.icon);
        }

    tempCanvas.drawBitmap(tempBitmap, 0, 0, null);
    c.drawBitmap(tempBitmap, 0, 0, null);

    mSurfaceHolder.unlockCanvasAndPost(c);
  }
}

Et il erreurs avec l'app s'est arrêté de façon inattendue" avec logcat montrant;

ERROR/AndroidRuntime(24768): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=com.htc.HTCAlbum.action.ITEM_PICKER_FROM_COLLECTIONS dat=content://media/external/images/media/185 }} to activity {com.example.colorbook/com.example.colorbook.Colorbook}: java.lang.NullPointerException
Complete logcat as it finished gallery view activity and tried to return intent;<br>
02-03 10:47:22.042: DEBUG/MainActivity(22984): [HTCAlbum][MainActivity][onPause]: Begin<br>02-03 10:47:22.042: DEBUG/MainActivity(22984): store mCurrentPosition_backup=0<br>02-03 10:47:22.042: DEBUG/DisplayManager(22984): store mCurrentPosition_backup=0<br>02-03 10:47:22.092: DEBUG/dalvikvm(22984): GC_EXPLICIT freed 1459 objects / 91880 bytes in 44ms<br>02-03 10:47:22.102: INFO/AlbumMapper(22984): Create thumbnail for: /mnt/sdcard/workspace/Colorbook/res/drawable/fileload.png<br>02-03 10:47:22.102: DEBUG/ThumbnailWorker(22984): [stopWorking] Stop working, now join #37, /mnt/sdcard/workspace/Colorbook/res/drawable/fileload.png<br>02-03 10:47:22.102: DEBUG/AlbumAdapter(22984): set thread priority to normal<br>02-03 10:47:22.102: DEBUG/AbstractViewGetter(22984): Raise getter prefetcher thread priority to normal.<br>02-03 10:47:22.102: DEBUG/AbstractViewGetter(22984): Join getter prefetch thread<br>02-03 10:47:22.102: DEBUG/AbstractViewGetter(22984): Getter prefetch join time: 2<br>02-03 10:47:22.102: DEBUG/AlbumMapper(22984): cancel current decode operation<br>02-03 10:47:22.182: DEBUG/AndroidRuntime(24768): Shutting down VM<br>02-03 10:47:22.182: WARN/dalvikvm(24768): threadid=1: thread exiting with uncaught exception (group=0x400259f8)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768): FATAL EXCEPTION: main<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=com.htc.HTCAlbum.action.ITEM_PICKER_FROM_COLLECTIONS dat=content://media/external/images/media/185 }} to activity {com.example.colorbook/com.example.colorbook.Colorbook}: java.lang.NullPointerException<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3734)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3776)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.ActivityThread.access$2800(ActivityThread.java:135)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.os.Handler.dispatchMessage(Handler.java:99)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.os.Looper.loop(Looper.java:144)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.ActivityThread.main(ActivityThread.java:4937)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at java.lang.reflect.Method.invokeNative(Native Method)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at java.lang.reflect.Method.invoke(Method.java:521)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at dalvik.system.NativeStart.main(Native Method)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768): Caused by: java.lang.NullPointerException<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at com.example.colorbook.Colorbook.loadImageToCanvas(Colorbook.java:524)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at com.example.colorbook.Colorbook.onActivityResult(Colorbook.java:231)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.Activity.dispatchActivityResult(Activity.java:3931)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3730)<br>02-03 10:47:22.182: ERROR/AndroidRuntime(24768):     ... 11 more<br>02-03 10:47:22.202: WARN/ActivityManager(97):   Force finishing activity com.example.colorbook/.Colorbook<br>02-03 10:47:22.704: WARN/ActivityManager(97): Activity pause timeout for HistoryRecord{46207010 com.example.colorbook/.Colorbook}<br>02-03 10:47:22.742: DEBUG/Sensors(97): close_akm, fd=114<br>02-03 10:47:22.852: DEBUG/MainActivity(22984): [HTCAlbum][MainActivity][onStop]: Begin<br>02-03 10:47:22.902: DEBUG/dalvikvm(22984): GC_EXPLICIT freed 398 objects /23264 bytes in 38ms<br>02-03 10:47:22.902: DEBUG/MainActivity(22984): [HTCAlbum][MainActivity][onDestroy]: Begin<br>02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: Begin<br>02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: [email protected] size: 0<br>02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: No more clients. release resources.<br>02-03 10:47:22.912: DEBUG/OnlineDataCenter(22984): [HTCAlbum][OnlineDataCenter][unbindContext]: End 0<br>02-03 10:47:22.912: DEBUG/ThumbnailWorker(22984): [stopWorking] Stop working, now join #-1, Decode Complete!!<br>02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): set thread priority to normal<br>02-03 10:47:22.912: DEBUG/AlbumMapper(22984): cancel current decode operation<br>02-03 10:47:22.912: DEBUG/AlbumMapper(22984): cancel current decode operation<br>02-03 10:47:22.912: DEBUG/ThumbnailWorker(22984): [stopWorking] Stop working, now join #-1, Decode Complete!!<br>02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): set thread priority to normal<br>02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): Join worker thread in destroy<br>02-03 10:47:22.912: DEBUG/AlbumAdapter(22984): Join time: 0<br>02-03 10:47:22.922: INFO/MainActivity(22984): mWorker finishes jobs at onDestroy().<br>02-03 10:47:22.932: DEBUG/CollectionsActivity(22984): [HTCAlbum][CollectionsActivity][onDestroy]: Begin<br>02-03 10:47:22.932: DEBUG/AlbColAdap(22984): [HTCAlbum][AlbumCollectionsAdapter][onDestroy]: Begin<br>02-03 10:47:22.942: INFO/BatteryStatsImpl(97): notePhoneSignalStrengthLocked: 2->3<br>02-03 10:47:22.952: DEBUG/AlbColAdap(22984): [HTCAlbum][AlbumCollectionsAdapter][onDestroy]: End<br>
InformationsquelleAutor DKDiveDude | 2011-02-03