我正试图从我的相机拍摄照片并将其作为缩略图放在我的应用程序上,它成功地让我拍了一张照片但不会更远,它似乎只输出图像,这是徽标我的申请。
以下是代码:
public void breakfastPicture(){
bPicButton = (Button)findViewById(R.id.bPicButton);
bPicButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"breakfast.jpg");
Uri photoPath = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath);
// start camera activity
startActivityForResult(intent, TAKE_PICTURE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == TAKE_PICTURE && resultCode== RESULT_OK && intent != null){
Bundle extras = intent.getExtras();
ImageView bThumbnail = (ImageView)findViewById(R.id.bThumbnail);
Bitmap bBitMap = (Bitmap) extras.get("data");
bThumbnail.setImageBitmap(bBitMap);
}
}
答案 0 :(得分:0)
而不是:
Bundle extras = intent.getExtras();
Bitmap bBitMap = (Bitmap) extras.get("data");
尝试使用:
File file = new File(Environment.getExternalStorageDirectory(),"breakfast.jpg");
ImageView bThumbnail = (ImageView)findViewById(R.id.bThumbnail);
Bitmap bBitMap = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1000, 700);
bThumbnail.setImageBitmap(bBitMap);
decodeSampleBitmapFromFile方法:
public static Bitmap decodeSampledBitmapFromFile(String path, int reqWidth, int reqHeight) {
// BEST QUALITY MATCH
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
// Calculate inSampleSize, Raw height and widht of image
final int height = options.outHeight;
final int width = options.outWidth;
options.inPreferredConfig = Bitmap.Config.RGB_565;
int inSampleSize = 1;
if (height > reqHeight)
{
inSampleSize = Math.round((float)height/(float)reqHeight);
}
int expectedWidth = width/inSampleSize;
if(expectedWidth > reqWidth)
{
inSampleSize = Math.round((float)width/(float)reqWidth);
}
options.inSampleSize = inSampleSize;
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(path, options);
}