Get Bitmap from Lazy ListView Android - android

I implemented lazy ListView adapter to display the images along with text from internet in Listview.Now I want to get the Bitmap of image when particular ListItem clicked and want to display it in a ImageView,But I am unable to get the Bitmap from the image.I am using this logic in OnItemClickListener for ListView:-
View imageView1 = listView1.getChildAt(position);
ImageView imageView3 = (ImageView) imageView1.findViewById(R.id.image);
Bitmap b;
imageView3.setDrawingCacheEnabled(true);
imageView3.buildDrawingCache();
b = ((BitmapDrawable) imageView3.getDrawable()).getBitmap();
car_image_detail.setImageBitmap(b);
But getting NullPointerException sometimes.Can anyone please help me out..?

Please use my code. I am getting the image from the listview when a particular item is clicked and setting it to another imageview.
//Code in listview itemclick listener
final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
final BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
show.setImageBitmap(yourBitmap); // show is another imageview

Related

How to do image blur on touch (progressively)?

I want to blur a portion of bitmap and set into image view. But I am not getting any reference of the same.
Took me 40 seconds to find the solution in stackoverflow, Please use search :)
Use the blur from here:
https://stackoverflow.com/a/10028267/5618671
(Make sure to +1 Yahel, the user that posted the blur solution)
Get your Bitmap (can get it from your existing imageView), Call the fast blur when imageView has been clicked, and set the imageView with the new blurred Bitmap :
example
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//GET BITMAP FROM IMAGEVIEW
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmapFromImageView = drawable.getBitmap();
Bitmap blurredBitmap = fastblur(bitmapFromImageView, BITMAP_SCALE, BLUR_RADIUS)
imageView.setImageBitmap(blurredBitmap);
}
});
P.S Make sure imageview is declared final:
final ImageView imageView;

How to convert a textview to Imageview

I am trying to get a Imageview from textview. I tried many methods but not able to set that textview on Imageview as image.
I tried following method:
TextView tv = (TextView)findViewById(R.id.textview);
tv.buildDrawingCache();
ImageView img = (ImageView)findViewById(R.id.imageview);
img.setImageBitmap(tv.getDrawingCache());
but i am not still able to show that textview on Imageview. Can someone help me that how can i set textview as image on that imageview?
Try this, if it maya help you
yourTextView.setDrawingCacheEnabled(true);
yourTextView.buildDrawingCache();
yourImageview.setImageBitmap(tv1.getDrawingCache());
call
tv.buildDrawingCache(true);
Bitmap b = tv.getDrawingCache(true).copy(Bitmap.Config.ARGB_8888, false);
tv.destroyDrawingCache();
img.setImageBitmap(b);

GridView Click Display full screen image

i have Gridview that display Image from internet using universal-image-loader
i want when i click on image in gridview
show up in full screen
here is my simple code :
MainActivity
Photoist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,int pos, long id) {
// String url = mAdapter.getItem(pos).getImgUrl();
GridView lv = (GridView) parent;
ImageView SelectedImage = (ImageView) parent.getChildAt(pos-lv.getFirstVisiblePosition()).findViewById(R.id.iconImg);
SelectedImage.buildDrawingCache();
Bitmap myimage = SelectedImage.getDrawingCache();
Intent intent = new Intent(getActivity(),FullScreenImageView.class);
intent.putExtra("MyImageIntent", myimage);
startActivity(intent);
}
});
FullScreenImageView.Class
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
ImageView Fullscreen = (ImageView) findViewById(R.id.imgDisplay);
Bitmap Image = (Bitmap) getIntent().getExtras().get("MyImageIntent");
Fullscreen.setImageBitmap(Image);
}
The Error in this Code :
Fullscreen.setImageBitmap(Image);
i hope someone can help
and i have 1 more question
how i can make the FullScreenImage Swipe/Slide . i mean if i slide image left it show next image, and i slide it right show previews image .
-sorry for my bad english, and thanks
Edit:
Try this when getting the Bitmap from your ImageView:
Bitmap image = ((BitmapDrawable)SelectedImage.getDrawable()).getBitmap();
Bitmap class implements parcelable, which means that it's instances can be stored in a parcel.
Parcel by the way is just androids way of serialization.
Change
Bitmap image = (Bitmap) getIntent().getExtras().get("MyImageIntent");
to
Bitmap image = (Bitmap) getIntent().getParcelableExtra("MyImageIntent");
For the slide part you want to create a ViewPager which was designed for exactly that.

How to retrieve an image from ImageView when Click on that image?

i have a ImageView in the layout, when i click on the image i want to get that image into a variable and replace with another image in this ImageView. please help me..
The onClick Listener will give you a View, that's the ImageView that was clicked. Cast it to an ImageView and do whatever you want with it.
in this example i have take previous image in Drawable and replace i with new image. if you set any imageview to image which stay in drawable variable(d) then use :: setBackgroundDrawable(d); is useful
public void onClick(View v){
ImageView i;
i = (ImageView) findViewById(R.id.img);
Drawable d = i.getBackground();
i.setBackgroundResource(R.id.secondImage);
}

How set an image in Android ImageView

I need to show a image, when i press a button on my application.
I'm trying with:
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageDrawable(R.drawable.loading);
but it shows an error.
Anyone can help me? Thanks.
import package_name.R.drawable;
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageResource(drawable.loading);
OR
you can set the image from the start, set it to invisible and when you want to show it just change the visibility property.
for future visitors:
sometime setImageDrawable(Drawable) method show an error like:
The method setImageDrawable(Drawable) in the type ImageView is not applicable for the arguments (int)
can try following codes:
ImageView imageView = (ImageView) findViewById(R.id.myImageView);
Drawable image = getResources().getDrawable(R.drawable.your_image);
imageView.setImageDrawable(image);
--------- OR can try this ------------------
imageView.setImageDrawable(ContextCompat.getDrawable(YourActivity.this, R.drawable.your_image));
hope it work for you.

Categories

Resources