如何从设备在Android的Java应用程序中的图像 [英] how to get the images from device in android java application

查看:181
本文介绍了如何从设备在Android的Java应用程序中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我要上传的图片。

In my application I want to upload the image.

有关,我必须得在Android设备从画廊的图片。

For that I have to get images from gallery in android device.

我怎样写code,完成此?

How do I write code that accomplishes this?

推荐答案

提起的意图与行动为 ACTION_GET_CONTENT 和类型设置为图像/ * 。这将启动照片选择器活动。当用户选择一个图像,您可以使用 onActivityResult 回调得到的结果。

Raise an Intent with Action as ACTION_GET_CONTENT and set the type to "image/*". This will start the photo picker Activity. When the user selects an image, you can use the onActivityResult callback to get the results.

是这样的:

Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK)
    {
        Uri chosenImageUri = data.getData();

        Bitmap mBitmap = null;
        mBitmap = Media.getBitmap(this.getContentResolver(), chosenImageUri);
        }
}

这篇关于如何从设备在Android的Java应用程序中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆