如何从一个活动图像发送到从Android图库中选择另一个活动? [英] How to send image from one activity to another activity that is selected from the android Gallery?

查看:109
本文介绍了如何从一个活动图像发送到从Android图库中选择另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置的图像是从Android图库选择。
我用这个code获得所选图像。

I want to set the Image to be Selected from the Android Gallery. I use this code to get selected Image.

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT);// 
//startActivity(intent);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);

和该方法的onActivityResult就像是:

And the onActivityResult Method is like:

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {     
        super.onActivityResult(requestCode, resultCode, data);     
        if (requestCode == 10 && resultCode == Activity.RESULT_OK) {             
            Uri contentUri = data.getData();          
            String[] proj = { MediaStore.Images.Media.DATA };         
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);         
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);         
            cursor.moveToFirst();         
            String tmppath = cursor.getString(column_index);           
            Bitmap croppedImage = BitmapFactory.decodeFile(tmppath);
            go.setVisibility(View.VISIBLE);
            //canvas.drawBitmap(kangoo, 130, 100, null);
            //previewImage.setVisibility(View.VISIBLE);

            imageSrc.setImageBitmap(croppedImage);    //set to your imageview          
        }
}

现在,我想从库中选择图像并将其发送到另一个活动。那么它是如何可能的上述code?
谢谢你。

Now, I want to select Image from the gallery and send it to another activity. So how it is Possible with above code ?? Thanks.

推荐答案

您可以通过图像到下一个活动的 URI

You can pass the URI of the Image to next Activity.

URI 你从获得的onActivityResult()

的onCreate()接下来活动的

德code中的位图再次将其设置为的ImageView

Decode the Bitmap again and set it to ImageView

这篇关于如何从一个活动图像发送到从Android图库中选择另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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