从ImageView获取图像

Nic*_*son 24 android android-gallery android-imageview

我有一个显示图像数组的图库,点击它们时会显示在图像视图中.我希望能够分享当前在意图选择器中显示的图像.我无法弄清楚如何选择当前图像.

图库代码:

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;
    }
Run Code Online (Sandbox Code Playgroud)

意图选择代码:

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"));
Run Code Online (Sandbox Code Playgroud)

在哪里说R.drawable.alright我需要它以某种方式成为当前图像的变量.有任何想法吗?

jee*_*eet 63

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

Gallery.getSelectedView(); 
Run Code Online (Sandbox Code Playgroud)

并从imageView使用以获取Drawable:

ImageVIew.getDrawable()
Run Code Online (Sandbox Code Playgroud)

如果您想从drawable使用以下输入流:

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);
Run Code Online (Sandbox Code Playgroud)


joj*_*ojo 5

    l.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TextView textView=(TextView)view.findViewById(R.id.textView);
            ImageView imageView=(ImageView)view.findViewById(R.id.imageView);
            String textViewString=textView.getText().toString();
            Bitmap image=((BitmapDrawable)imageView.getDrawable()).getBitmap();

            DialogClass dialogClass=new DialogClass(MainActivity.this,image,textViewString);
            dialogClass.show();
        }
    });
Run Code Online (Sandbox Code Playgroud)