I have a bitmap of 128*128 size. I want to make it of size 256*256. But I don't want to stretch the image. Instead, my old image should be placed at the center of the new image and remaining pixels should be filled with a certain color, for example white.
How can I do this?
ImageView have setScaleType(ScaleType type) method.
When ScaleType is http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Try to play with it. Good luck!!
Related
Assume I have an image which is larger than an ImageView size (width and height) and the scaleType is set to CENTER or the scaleType is set to MATRIX and the bitmap is translated and scaled. Therefore parts of the image are not visible. How may I calculate the visible part of the bitmap and crop exact that part. I want to crop and store only the visible part.
How may I do that?
Any help will be appreciated.
So you want exactly what the image view shows? I'd enable the drawing cache and grab it from the view. That should be exactly what's on screen.
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 have an activity which only has an ImageView on it. I'm setting an image bitmap for this view that is much taller than wider. So, for example, my activity has 720x950 and my image is 918x2077.
When I add the image in the imageView, both side parts of imageView stays white (read: no image in there).
If I call mImage.getWidth() it returns me the width of the entire imageView of 720 (which is the activity wide).
I would like to get the width of the image in specific, not of the view.. is that possible?
It sounds like the aspect ratio of your image is being kept. You want to know how much width the image is actually occupying.
You can calculate it!
if your bitmap is 918x2077 and your window size is 720x950, then to calculate your width, simply do:
(950/2077) * 918 = 419.8844...
Hope this helps :)
I have Imageview which i am creating it dynamically,now i am setting
imageView.setImageBitmap(bitmap);
imageView.setBackgroundResource(R.drawable.a);
What is happening is the setBackgroundResource image is stretching,as the bitmap size increases.
Why is it so?Is there any workaround?
A Background resource is designed to fill up the entire View, which is why it stretched when the contents of the View are increased in size.
A possible workaround would be to use a 9-patch drawable, which only stretches are specified by you.
Another workaround would be to scale your background as your normal View Contents increase, and reset it to the new background.
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.