Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Image from 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.

Gallery 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;     } 

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")); 

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

like image 825
Nick Nelson Avatar asked Jan 28 '12 04:01

Nick Nelson


People also ask

How can I download image from ImageView in android?

//to get the image from the ImageView (say iv) BitmapDrawable draw = (BitmapDrawable) iv. getDrawable(); Bitmap bitmap = draw. getBitmap(); FileOutputStream outStream = null; File sdCard = Environment. getExternalStorageDirectory(); File dir = new File(sdCard.

How do I get Bitmap from ImageView?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)


2 Answers

To fetch currently selected view use

Gallery.getSelectedView();  

and for getting Drawable from imageView use:

ImageVIew.getDrawable() 

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); 
like image 151
jeet Avatar answered Oct 04 '22 12:10

jeet


    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();         }     }); 
like image 39
jojo Avatar answered Oct 04 '22 14:10

jojo