0

我已经工作了一个星期,我不明白为什么我不能得到我的缩略图。我只需要它,而不是实际的图像,我读到通过 Mediastore.captureimage 获取它很方便,没有 urifile 传递给 intent 。我的代码:

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {
   private ImageView image;

   @Override
   public void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image = (ImageView) findViewById(R.id.image);
   }

   public void vignette(View vue) {
      Intent intention = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     startActivityForResult(intention, 1);
   }

   @Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == 1) {
     Uri imageUri = null;
     if (data != null) {
    if (data.hasExtra("data")) {
           Bitmap vignette = (Bitmap) data.getExtras().get("data");
           image.setImageBitmap(vignette);
     }
     }
  }
 }
 }

实际上, data 不为 null,但 hasExtra("data") 给出了 null。虽然我可以看到 Intent { act=inline-data dat=content://media/external/images/media/8767 (has extras) } ...有没有办法获得额外的!

4

1 回答 1

0

Inorder to get bitmap from bitmap

 Uri imageUri = data.getData();
        Bitmap vignette = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);

call this in your onActivityResult function this will give the bitmap

You can always resize the bitmap to your requirement

vignette =Bitmap.createScaledBitmap(vignette ,100,100, true);

           image.setImageBitmap(vignette);

this will create a bitmap of 100*100

于 2013-06-03T10:01:48.123 回答