嗨,谁能帮我解决这个问题。我在这一行遇到错误File imageFile = new File(photoUri); 说构造函数 File(photoUri) 是未定义的,即使我在将调用它的方法上有那个构造函数。这是我的代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQ){
if (resultCode == RESULT_OK) {
Uri photoUri = null;
if (data == null){
Toast.makeText(this, "Image saved successfully", Toast.LENGTH_LONG).show();
photoUri = fileUri;
} else {
photoUri = data.getData();
Toast.makeText(this, "Image saved successfully in: " + data.getData(), Toast.LENGTH_LONG).show();
}
showPhoto(photoUri);
} else if (resultCode == RESULT_CANCELED)
{
Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
} else
{
Toast.makeText(this, "Callout for image capture failed!", Toast.LENGTH_LONG).show();
}
}
}
private void showPhoto(Uri photoUri)
{
File imageFile = new File(photoUri);
if (imageFile.exists())
{
Drawable oldDrawable = photoImage.getDrawable();
if (oldDrawable != null) { ((BitmapDrawable)oldDrawable).getBitmap().recycle();
}
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmap);
photoImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
photoImage.setImageDrawable(drawable);
}
}