我使用Nostra's UIL在GridView.
中显示图像但是,在提供的示例中,他通过在点击项目时传递数组的位置来获取图像:
@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);
}
});
有没有办法接收点击位置的Bitmap
?
这样的东西?
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;
}
});
但是,加载实际点击的图片?
我尝试没有成功:
@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);
}
});
答案 0 :(得分:1)
是的,你可以通过这种方式在你的OnItemClick
听众中......
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
}
答案 1 :(得分:1)
你也可以使用它。
BitmapDrawable bmdr = (BitmapDrawable)iv.getDrawable();
Bitmap mybmp = bmdr.getBitmap();
注意: 也不推荐使用BitmapDrawable构造函数。