How "customizable" is Picasso vs. Universal Image Loader (UIL)? - android

My goal is to use one large image containing a textured background for my Android app. At run-time I want cut out a screen-size piece of it and place it as the background image.
Which Image Loader would be better for this?
This review of Android Image Loader libraries described some procs and cons of the Picasso library and the UIL library (among others).
So far I think Picasso seems to match my needs. "Picasso allows you to specify
exact target image size." I believe this would accomplish my goal of cropping out a specific size of image, based on the device's screen size and density.
This article claims that UIL allows for a lot of customization, but then it also says it "doesn’t not provide a way to specify image size directly you want to load into a view".
Am I correct that Picasso will better allow me to crop an image to the size of the actual screen size?

By default, if I remember correctly, Picasso isn't able to crop an image out of the box. But, Picasso allows you to code transformations, and specify their use, as part of the loading process.
Picasso.with(ctx).load(uri)
.transform(new YourCropTransform(params...))
.into(target)

Related

Using high definition pictures in android

I'm having some trouble when uploading high definition pictures in my app.
I have a Grid View and when I add the photo the app crashes stating that its a memory problem.
One solution I did was to decrease the size of the image through a website (https://www.befunky.com/create/resize-image/) but the image gets blurie.
Also used a solution that is present on the official Android developers' website (https://developer.android.com/topic/performance/graphics/load-bitmap.html), unsuccessfully (the app gets too slow and I have the previous result).
I've seen many applications where this is not a issue and I want to learn the way they do it correctly.
Try Picasso, it can load an image into your imageView from your drawable (or url), and its fit() method allows you to reduce the image to the lowest possible resolution, without affecting quality.
Basically, it measures the dimensions of the target ImageView and uses resize() to reduce the image size to the dimensions of your ImageView:
High quality picture in drawable folder:
Picasso.with(context)
.load(R.drawable.image)
.fit()
.into(imageView);
High quality picture from a url:
Picasso.with(context)
.load("www.url.com/image.jpg")
.fit()
.into(imageView);
You can find more details on how to use fit, resizing and scaling with Picasso here.

Android: Scale up width of ImageView in GridView

In my app I'm generating a bunch of Bitmaps at runtime to show in a GridView. The generated Bitmaps consist only of rectangular shapes and about five different colors.
If I make them big, they get scaled down nicely, but I get OutOfMemoryExceptions. But when I make them small, they're not scaled up to fit the column width. I think ImageView can't help me, because it doesn't know the final column with. Setting stretchMode to columnWidth in the GridView didn't help.
Setting adjustViewBounds to true on the ImageView helped with large Bitmaps, but it doesn't help for upscaling.
Is it somehow possible to scale the ImageView with the underlying Bitmap to the maximum column width of the GridView? This would be my preferred solution.
If not, can I determine the columnWidth of the GridView in advance to just generate the bitmap accordingly? (I don't like this solution that much, because I suspect that on devices with large screens I might run into OutOfMemoryExceptions again.)
You have two choices.
METHOD 1:
Optimize your images by using any online image compression sites . For example https://tinypng.com .TinyPNG uses smart lossy compression techniques to reduce the file size of your PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size!
METHOD 2:
Load your images using third party libraries like Universal Image Loader, Glide .. these libraries aims to provide a powerful, flexible and highly customizable instrument for image loading, caching and displaying. It provides a lot of configuration options and good control over the image loading and caching process.
Since you generate the bitmaps in your app, you can use libraries like Picasso to display them. Picasso will handle the memory on your behalf and you need not worry about OutOfMemory Exceptions.

How to define the Image sizes for various android devices, not Icons?

I want to use layout in this way, where image will be loaded from a HTTP server request. I need to know how can I define the image sizes from various android device , as in the server there will not be any drawable asset folder.
Till now I have fixed the height of the Relative Layout inside which the ImageView is placed,which has height and width : fill_parent, and scale_type : fitXY, for which if the image is small its getting stretched.
And this is not a good approach. Can you please suggest me a good way, as how can I define the image sizes.
Good question. There are two solutions that come to my mind:
Similar to how Andorid maintains resources (high display, extra high display, low display, etc.), Request your server to resize photos before sending them
Downloading full resolution photos and resizing them in your app.
Option #1 is more optimized, but #2 is easier to implement. It totally depends on how much time you're willing to spend on this.
It's also highly recommended that you use an image loading library for downloading images. Glide and Picasso are probably two of the best libraries out there. Pass an image URL and they'll handle everything: Downloading the photo, caching it in memory + storage, resizing, etc.
Oh and I don't think fitXY is the best option for your purpose. Try using centerCrop which crops your images to fit them properly.

Google Photos App style Image Cropping, Straightening and panning

I am looking for Google Photos app style image manipulation. I am kind of new to image processing. Any leads on how to make the cropping rectangle with the image the same size as cropping rectangle, rotation (which rotates both the image and cropping rectangle), image straightening (including how to get that angle slider kind of UI) will be great. If there are some libraries that has these features, that will also work.
Square has a library for loading and playing with images.
Here are some features:
- Handling ImageView recycling and download cancelation in an adapter.
- Complex image transformations with minimal memory use.
- Automatic memory and disk caching.
There is detailed information on how to use the lib on their website. Check it out: Picasso
The gradle line you need to add is:
compile 'com.squareup.picasso:picasso:2.5.2'
It's very easy to use. Here is how I load and adjust an image into an ImageView in my example app:
Picasso.with(mContext).load("http://cdn0.vox-cdn.com/uploads/chorus_asset/file/798874/DSCF1913.0.jpg").fit().centerCrop().into(imageView);
As you can see, I've used fit().centerCrop() here. This will adjust the image to fit proportionally inside my imageView. You can try different forms of image transformations to better fit your needs.
You can also load images from your drawable folder or directly from file:
Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load("file:///android_asset/DvpvklR.png").into(imageView2);
Picasso.with(context).load(new File(...)).into(imageView3);
EDIT:
Looks like I didn't fully understand your question when I first read it. Here are some tips for what you're trying to achieve. May not be exactly what you want, but I think it might be a start.
If you want to rotate your image, you can do it with Picasso using RequestCreator.rotate(float degrees).
Here's the documentation for RequestCreator.
As for cropping images (inside a specified rectangle, as you've shown), there is:
Android crop.
Or you can use Picasso Transformations and create a transformation like
CropTransformation(Top, Center, Bottom);
And ask Picasso to transform the image like this:
Picasso.with(mContext).load(R.drawable.demo)
.transform(transformation).into((ImageView) findViewById(R.id.image));
Also, as #Amit K Saha said on his answer, you can use some Android SDK effects. Check android.media.effect.
Hope this helps.
There are some help from android sdk. May not be exactly what you are looking but worth of a shot to start. Have a look here.
android.media.effect
And list of available effects can be found here
http://developer.android.com/reference/android/media/effect/EffectFactory.html

Android imageview image quality matter?

I am writing a Android app which need to display some high quality picture(took from professional DSLR). The problem is it can't be display from gallery.
I choose a photo in Gallery first. The target picture is 2464*1632 JPEG, roughly 4.5M;
Then I just need to compress it to 800*600 and display it in imageview:
image.setImageBitmap(this.bmp);
Thing is that I have tested other image I downloaded form internet(really low quality), and it works without any problem. Can anybody tell me why it can't be displayed? I will be really appericiated
Large images are tricky to handle due to limited memory. You have several choices:
Use a WebView (this allows you to have pinch and zoom functionality to make use of those extra pixels
Decode the image down to the size of the display and then put it in an ImageView using BitmapOpts http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html and changing inSampleSize. It seems you may be having difficulty with that, so consider using createScaledBitmap which just needs the dest width and height.

Categories

Resources