Question

I am using Nostra's UIL to display images in a GridView. However, in the example provided, he gets the image by passing the position of the array at the moment an item has been clicked:

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent i = new Intent(context, DoneDiscardActivity.class);
    i.putExtra("pos", position + "");
    startActivity(i);
    }
});

Is there a way to receive the Bitmap to the clicked position?

Something like this?

loader.displayImage(imagesA[position], holder.image, op,
    new SimpleImageLoadingListener() {
    @Override
    public void onLoadingStarted(String imageUri, View view) {
        spinner.setVisibility(View.VISIBLE);
    }

    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
        spinner.setVisibility(View.GONE);
    }

    @Override
    public void onLoadingComplete(String imageUri,View view, Bitmap loadedImage) {
        spinner.setVisibility(View.GONE);
        bitmap = loadedImage; 
    }
    });

But, loading the actual clicked image?

I tried without success:

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ImageView iv = (ImageView)view.findViewById(R.id.grid_item_image);
    Drawable d = iv.getDrawable();
    Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
});
Was it helpful?

Solution

Yes you can by this way in your OnItemClick listener..

    ImageView iv = (ImageView) view.findViewById(R.id.grid_item_image);
    Drawable drawable = iv.getDrawable();
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable d = (BitmapDrawable) drawable;
        Bitmap bitmap = d.getBitmap();//Required bitmap
    }

OTHER TIPS

you can use this also.

BitmapDrawable bmdr = (BitmapDrawable)iv.getDrawable();
Bitmap mybmp = bmdr.getBitmap();

Note: BitmapDrawable constructor is deprecated also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top