小编DKD*_*ude的帖子

Android:发送失败结果ResultInfo {who = null,request = 1,result = -1,data = Intent

我在Logcat中收到意图传递错误,当我调用它时app会意外停止;

startActivityForResult(new Intent(Intent.ACTION_PICK,
         android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 1);
Run Code Online (Sandbox Code Playgroud)

或者就此而言;

startActivityForResult(new Intent(Intent.ACTION_PICK,
         android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
Run Code Online (Sandbox Code Playgroud)

然后处理它;

@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);
  } …
Run Code Online (Sandbox Code Playgroud)

android image sd-card android-intent android-activity

4
推荐指数
1
解决办法
1万
查看次数

Android:如何将图像加载到Bitmap中

我可以将资源图像从drawable文件夹加载到位图中,甚至可以进行缩放,但是现在我需要从存储在SD卡上的任何图像中加载图像,我可以看到这将允许我查看和选择;

    startActivityForResult(new Intent(Intent.ACTION_PICK,
         android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 1);
Run Code Online (Sandbox Code Playgroud)

但到目前为止,我一直无法确切地找出返回的数据以及如何将其加载到位图中.

更新:

这就是我现在所得到的;

@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);
  }
}
Run Code Online (Sandbox Code Playgroud)

用logcat显示"app已经意外停止"出错了;

ERROR/AndroidRuntime(24768): …
Run Code Online (Sandbox Code Playgroud)

android load image bitmap sd-card

1
推荐指数
1
解决办法
3万
查看次数