user3013499
user3013499

Reputation: 43

scaling image to different imageview sizes

I'm storing and displaying images taken with the camera app in my views. these images are displayed in different sized imageViews in different views

for eg, in one page i have a 1/6 screen size display ,in another a thumbnail display and in another a full screensize display. How should i handle the scaling ?

At first i was taking the bitmap ,compressing using bp.compress(Bitmap.CompressFormat.JPEG, 100, bytes); and setting in the image view. this wasn't great for the full screen display it only fits the thumbnail display.

along with this i'm displaying a few images from drawable folder in some views, again they look very different in different screens (for e.g emulator and samsung galaxy phone)

i have seen various posts on these problems like using a custom class extending imageview etcetc. what is the best route to take? thanks in advancce for any suggestions

Upvotes: 0

Views: 191

Answers (1)

Graham Smith
Graham Smith

Reputation: 25757

It depends on what the desired outcome is you are looking for. For smaller thumbnail views you could try to apply a centre crop and for the larger views you are looking for you may want the image to be as large as the screen will allow, while preserving the aspect ratio.

To make life simpler why not use the Picasso library from Square? It handles a LOT of what you are asking and is free library in the form of a JAR. One of the major benefits is the easy syntax and it takes images from the file system and drawable folders.

It includes some transformations and you can create some of your own too, which gives some added versatility should Square fail to provide the transformations you need.

Finally it handles caching of images and from what I can remember it keeps a scaled cached image in memory versus a huge image that would take up more.

Coding Example

Picasso.with(context).load(R.drawable.landing_screen).into(imageView1);
Picasso.with(context).load(new File(...)).into(imageView2);

and for thumbnails something like this might be of use

Picasso.with(context)
  .load(url)
  .resize(50, 50)
  .centerCrop()
  .into(imageView)

http://square.github.io/picasso/

Upvotes: 2

Related Questions