【发布时间】:2016-10-16 11:26:20
【问题描述】:
我得到了这个监听器:
@Override
public void onClick(View v) {
showDialog();
ImageButton currentButton = (ImageButton)v;
Bitmap bmp = BitmapFactory.decodeFile(mCurrentPhotoPath);
currentButton.setImageBitmap(bmp);
}
图像在showDialog() 中成功拍摄,但在此之后它不会设置为imageButton。它变白了。生成的路径是:
file:/storage........../filename.jpg 并保存在 mCurrentPhotoPath
我尝试在拍摄后从drawable 设置图像只是为了尝试它并且它有效。出于某种原因,我无法将图像设置为ImageButton。我必须调整它的大小(照片是全尺寸的)吗?
按照THIS 教程我这样做了:
@Override
public void onClick(View v) {
showDialog((ImageButton)v);
setPic((ImageButton)v);
}
private void setPic(ImageButton mImageView) {
if (shotFired){
int targetW = mImageView.getWidth();
int targetH = mImageView.getHeight();
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,bmOptions);
mImageView.setImageBitmap(bitmap);
mImageView.setTag(mCurrentPhotoPath);
shotFired=false;
}
似乎如果我调用setPic() 而不进行新的拍摄,而只是调用旧的我让它工作。一定是及时的……我需要让这件事发挥作用。
【问题讨论】:
-
你是从 showDialog 启动相机吗??
-
“生成的路径是:file:/storage........../filename.jpg”——这不是路径。那也不是有效的
Uri,所以我不知道那是什么。但是,decodeFile()不会识别它。 -
我按照我刚刚发布的教程做了所有这些。
-
@sanjeetkumarSingh 是的,我是
-
有什么想法吗?还是不行
标签: android android-intent camera