【发布时间】:2014-12-18 08:25:32
【问题描述】:
在我的应用程序中,用户可以从相机意图中获取图像,然后我想将该图像返回到图像视图。我该怎么做?
这是我的相机意图:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);
还有onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
//Check that request code matches ours:
if (requestCode == TAKE_PICTURE)
{
//Check if your application folder exists in the external storage, if not create it:
File imageStorageFolder = new File(Environment.getExternalStorageDirectory()+File.separator+"Kruger National Park");
if (!imageStorageFolder.exists())
{
imageStorageFolder.mkdirs();
Log.d(TAG , "Folder created at: "+imageStorageFolder.toString());
}
//Check if data in not null and extract the Bitmap:
if (data != null)
{
String filename = "image";
String fileNameExtension = ".jpg";
File sdCard = Environment.getExternalStorageDirectory();
String imageStorageFolder1 = File.separator+"Kruger National Park"+File.separator;
File destinationFile = new File(sdCard, imageStorageFolder1 + filename + fileNameExtension);
Log.d(TAG, "the destination for image file is: " + destinationFile );
if (data.getExtras() != null)
{
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
try
{
FileOutputStream out = new FileOutputStream(destinationFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
}
catch (Exception e)
{
Log.e(TAG, "ERROR:" + e.toString());
}
一切正常,但现在只想将其添加到我的 ImageView:
ImageView image = (ImageView) v.findViewById(R.id.imageV);
image.setImageResource();
有人可以帮忙吗?
【问题讨论】:
标签: android image android-intent