Refresh image cache in ImageView - android

I have an imageView from which I take visible part of image with getDrawingCache(). It works well. But when I change image in imageView and try to get bitmap from it, getDrawingCache() returns bitmap of the first image. I tried to call this method buildDrawingCache() before calling getDrawingCache() but it didn't help.
How can I refresh cache or associated bitmap or I don`t know what in order to get new image?

Solution was very simple:
imageView.destroyDrawingCache();
imageView.buildDrawingCache();
imageView.getDrawingCache();

Related

Image crop help using multiple imageview

here's my problem... Would it be possible to load a picture, call the crop activity, and load the cropped images on different imageviews without changing the main image??
I have 3 imageviews. My imageview 1 is for the main image loadout, my imageview 2 is for the result of the crop activity, the same goes with imageview 3.
I am using com.theartofdev.edmodo:android-image-cropper:2.6.0....
The good thing about this one is that it already has lots of functions, but the problem is that what I want to happen is that it would load the image that I have already called in my main imageview.
Get the instances of the Views in the activity class.
Use the method below to get the image source to bitmap
Display bm returned from convertImageViewToBitmap to the second ImageView.
private Bitmap convertImageViewToBitmap(ImageView v){
Bitmap bm =
((BitmapDrawable)v.getDrawable()).getBitmap();
return bm;
}

Is it possible to translate an ImageView on the android platform using Picasso?

For example, if I loaded an image into an ImageView as such:
Imeteor = (ImageView) findViewById(R.id.meteor1);
Picasso.with(this)
.load(R.drawable.red_meteor)
.resize((int) meteorWidth, (int) meteorHeight)
.into(Imeteor);
Is it then possible to translate (move across or around the screen) said ImageView using Picasso? The current method I am using is below.
Imeteor = (ImageView) findViewById(R.id.meteor1);
Imeteor.setX(meteorXPosition);
Imeteor.setY(meteorYPosition);
With the values of "meteorXPosition", and "meteorYPosition" being updated in a separate method from where the image is loaded. Also, "meteorXPosition", and "meteorYPosition" are updated every millisecond.
Or,
By the fact that the image is loaded using Picasso, does that mean that the every time the ImageView is accessed it is accessed through Picasso? For example, by the code I provided above
Imeteor = (ImageView) findViewById(R.id.meteor1);
Imeteor.setX(meteorXPosition);
Imeteor.setY(meteorYPosition);
For anyone who might read this, and doesn't bother to read the comments. Picasso only handles loading the bitmap, and performing transformations on the bitmap in the image view. For moving a bitmap within an image view an option is to use the image view's setX() and setY() function. Which moves the the image view to a new location (the bitmap is in the image view). For moving images it is best to look up how to move an image view.

Calling setImageBitmap not always work for ImageView

In my application the user selects a bitmap and then i use the following code:
BitmapFactory.Options op= new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(path,op);
imageView.setImageBitmap(bitmap);
Unfortunately, sometimes ImageView does not display anything
What can i do?
Sometimes bitmap is too large. Thats why imageview turns blank! I think that here you can find what you need: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
I found this problem for Android 8 and low. There is no difference use method setImageBitmap or setImageUri : ImageView will be blank sometimes. There is no any errors and you can get Bitmap from ImageView.
Solution.
Use width and height of Bitmap for ImageView no more then double screen size, better is to fit to the screen size.

Removing image from ImageView and load new Image

I am facing problem on removing image from ImageView.
What I want an Image is loaded in ImageView, and then a new Image is taken by the camera and now that Image should load in ImageView replacing the previous one. I have tried
invalidate();
setImageBitmap(null);
setImageResource(0);
All these 3 methods are not working. Can someone help me.
Use this for setting image in ImageView
image.setImageResource(R.drawable.image);
If you want to set the Image By Drawable Image you can use like this
your_image_view.setImageDrawable(context.getResources().getDrawable(your_drawable_Image_id));
If you want to set the image by BitMapDrawable
your_image_view.setBackgroundDrawable(your_drawable_bitmap);
edit_countflag.setBackgroundColor(0);
edit_countflag.setImageResource(R.drawable.flag_id);

Android - Add A Touch Event Listener To BMP

I have a bitmap:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);
I want it so when a user presses on the bmp, I get a trace message (I will add in what I need it to do)
Anyone have any ideas?
Actually, Bitmap is a picture that can't exist on your layout without any container. A container for a picture in Android is ImageView. So to make a clickable ImageView with your picture inside you should use:
ImageView imgView = (ImageView)findViewById(R.id.img);
imgView.setImageBitmap(bmp);
imgView.setOnClickListener(new View.OnClickListener());
Hope this helps.
It may be more appropriate to use an ImageButton rather than an ImageView. Although, you could implement the onTouchEvent and register a touch event listener on the main element that the Bitmap relies in. Or, register an onTouchListener for the ImageView.
You will have to set an ImageView's background Bitmap as bmp, and then set a click listener on the ImageView.
Take a look at ImageView's setImageBitmap method, and View.OnClickListener

Categories

Resources