我是android编程的新手。我想写一个做两件事的程序。
首先:捕获图像并存储完整尺寸的图像
Scnd:在图像视图中显示
我已经完成了本教程的第一步 https://developer.android.com/training/camera/photobasics#java
但是在此文档中仅显示了如何显示缩略图 但我想在imageView中显示或加载所拍摄图像的完整尺寸
有人知道我该怎么办吗? 谢谢
这是我的代码
public class MainActivity extends AppCompatActivity {
static final int REQUEST_IMAGE_CAPTURE = 1 ;
static final int REQUEST_TAKE_PHOTO = 1;
String mCurrentPhotoPath;
ImageView mImageView;
AppCompatActivity main = this;
private View.OnClickListener myListener = new View.OnClickListener(){
public void onClick(View v) {
dispatchTakePictureIntent();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FloatingActionButton fab = findViewById(R.id.fab);
mImageView = findViewById(R.id.imageView2);
fab.setOnClickListener(myListener);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
private void dispatchTakePictureIntent(){
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try{
photoFile = createImageFile();
}catch(Exception e){
Log.d(TAG, "dispatchTakePictureIntent: exeption" + e.getMessage());
}
if(photoFile != null ){
Uri photoURI = FileProvider.getUriForFile(this, "com.example.am.project" , photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT , photoURI);
Toast.makeText(getApplicationContext() , photoURI.toString() , Toast.LENGTH_SHORT).show();
startActivityForResult(takePictureIntent , REQUEST_IMAGE_CAPTURE);
}
}
}
private File createImageFile() throws IOException {
//Create an Image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(imageFileName , ".jpg", storageDir);
//Save a file :path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
}