I'm using Picasso for downloading images from URL and putting in ImageView. Images are rectangle, but my ImageViews are squares. So I need to use some cropping, because I have spaces on top and bottom.
Without cropping the image is clear:
Picasso.with(context)
.load(left.get(pos).getImageName())
.into(ivFrontPageLeftImage);
To fit inside and crop I'm using:
Picasso.with(context)
.load(left.get(pos)
.getImageName())
.fit().centerInside()
.into(ivFrontPageLeftImage);
But as you can see the image is not clear, it is blur.
So how can I fit image inside the square (ImageView). Also image need to be clear, not blur?
I download this image, crop it with size 300 x 300 (to be square, i cut from left and right) and upload it. I use this new image to put in ImageView:
Picasso.with(context)
.load("http://oi62.tinypic.com/29y61p3.jpg")
.fit().centerCrop()
.into(ivFrontPageLeftImage);
As you can see image is clear and it is not blur.
How can I do this programmatically? Is it possible with Picasso, or I need other library to do this?
I can't comment on Lee's answer as I don't have enough reputation. But his answer was correct as I had the same issue. You can also set it in the ImageView object by doing the following:
imageView = (ImageView) view.findViewById(R.id.img);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Apply center crop on your ImageView instead of the method you are now using.
<ImageView
...
android:scaleType="centerCrop"/>
Related
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.
I've come across this simple problem with the Picasso library. I haven't find any way to put an image into ImageView center it like android:ScaleType="center" does without cropping. Do you have any ideas about how to solve this ? My problem is that I don't know at the runtime the height and width of the BitMap I download so I can't use resize() properly.
This is a little late, but for anyone who's looking for a solution :
Picasso
.with(context)
.load(ImageURL)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
If your ImageView is fixed one dimension and flexible another dimension (ex. android:width="match_parent", android:height="wrap_content"), you should be able to use android:adjustViewBounds="true" to get the ImageView to resize to display your image without cropping.
i am not found fit to center without resizing,
Picasso.get()
.load(source).resize(1650,700)
.centerCrop(Gravity.CENTER).into(imageView, new Callback()
I am setting a imgage in an ImageView. I want to scale down the image size without reducing the imageview size. Please guide me step by step.
Use scaleType parameter for your imageviews and set the value to centerFit or centerCrop. More here: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Taken from this link: source
You should also see android:adjustViewBounds to make the ImageView resize itself to fit the rescaled image. For example, if you have a rectangular image in what would normally be a square ImageView, adjustViewBounds=true will make it resize the ImageView to be rectangular as well. This then affects how other Views are laid out around the ImageView.
I am trying to get my images to appear in my image view so that if an image is say 600x400 and my image view is 200x200 that the image is scaled to 300x200 and then the extra width is cropped out so that the image appears as a 200x200 image. I have played with the various ScaleTypes but i can't find one that suits what i want. I want something like a combo of ScaleType.FIT_XY and ScaleType.CENTER_CROP
What you need to do is to scale down the image using the inSampleSize as shown here:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
and then use ScaleType.CENTER_CROP to show the image in the view.
i am working on displaying an image and placing an icon on top of it... clicking the icon will show an enlarged version of the image...
though putting the imageview holding the image in a LinearLayout scales the image to the width of the dialog, the problem is that i need to display the image in a dialog but the image is very high resolution and hence is far bigger than the width of the dialog...
I need to show the actual image with scrolling for both ways to see the whole image... But whenever i try putting the imageView in a scrollview the top of my imageview is blank... and again though image scrolls downwards the width is scaled to the width of the dialog...
Helppppppppp guys....
Thanx for your help androidbase... I found the solution... Actually we can say its a workaround but better than any other solution i can think of...
Actually what i do is that i implement webview and directly load the image url in it using webview.loadurl(myurl);
and further i enabled the zoom featured too hence i get an allround complete zooming capabilities...
Thanx all 4 ur help
developer.android.com/reference/android/graphics/Bitmap.html
developer.android.com/reference/android/graphics/BitmapFactory.html
refer this link.
Bitmap mIcon1 = BitmapFactory.decodeResource(context.getResources(),R.drawable.twitter_icon);
imgview.setImageBitmap(mIcon1);
convert your image to bitmap and use. hope it works.....
EDIT:
URL img_value = new URL(string_url_input);
if (profile != null) {
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
image_view.setImageBitmap(mIcon1);
}