获取图像的ImageView的 [英] Getting Image from ImageView

查看:156
本文介绍了获取图像的ImageView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个画廊,显示图像,点击的时候都显示在ImageView的数组。我希望能够分享当前正在显示的意图选择器的图像。我不知道如何选择当前的图像。

I have a gallery that shows an array of images, when clicked they are displayed in an imageview. I want to be able to SHARE the image that is currently being displayed in an intent chooser. I can't figure out how to select the current image.

画廊code:

public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = new ImageView(mContext);

        imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }

意向选择器code:

Intent chooser code:

Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/png");

            share.putExtra(Intent.EXTRA_STREAM,
                    Uri.parse("android.resource://com.appinfluence.fanapp.v1/drawable/" + Integer.toString(R.drawable.alright)));

            startActivity(Intent.createChooser(share, "Share Image"));

R.drawable.alright凡说我需要为当前​​图像的变量不知。任何想法?

Where it says R.drawable.alright I need that to be a variable of the current image somehow. Any ideas?

推荐答案

要获取当前选定的视图使用

To fetch currently selected view use

Gallery.getSelectedView(); 

和从ImageView的使用越来越绘制对象:

and for getting Drawable from imageView use:

ImageVIew.getDrawable()

如果您想从可绘制采用以下获得的InputStream:

If you want to get inputstream from the drawable use following:

BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
Bitmap bitmap = bitmapDrawable .getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(imageInByte);

这篇关于获取图像的ImageView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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