I am using google graph to get the desired graph for me and display it on a android device.
Now I want to display the received graph on a tablet screen but google graph api supports only 300,000 pixels as a max size (width x height) graph.
I am making a request for 500 x 600 px image and display it on a ImageView. I set the scaleType to fitXy and give the imageView width=fill_parrent height=850dpi because I want the image to almost fill the screen.
The problem is that the background of the image goes light gray or blurring after the ImageView scales the image and it looks bad on the white background of my application... If I make the ImageView wrap_content on width and height the graph has white background.
Is there any way to get the image displayed without changing it's background color?
Please note that I don't want to change the image's size.
I'd recommend to instead use width match_parent and then setAdjustViewBounds=true
If that doesn't fix it you probarbly have to change the image.
Unfortunately I had to change the image to a bigger one and the problem disappeared.
Related
I'm trying to make a basic media player. I downloaded a free .png from a website for the circular play button but when I just copy and paste it into the drawable folder and add it as my ImageButton I can't scale it down to be the size of my other buttons and the background is gray.
How would I scale the button down and trim out the gray background?
1. You can scale the image so that it works on multiple devices by doing something like this:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Image img = yourImage.getScaledInstance((width * .10), (height * .10), Image.SCALE_DEFAULT);)
This is just an example, but it would resize the image so that it is close to a tenth of the size.
2. Another method would be to simply resize the image with a program like paint, and have the image much smaller. Although this is an immediate easy fix, the image size is not responsive to actual screen size.
3. ScaleType attribute is also a means to change size depending on how you are using the image asset in your code. (thank Parth Patel)
I used an ImageView instead which can basically do anything a button can and scaled it down. Looks great, thank you to #ParthPatel for giving me the answer.
I have an application which the user can capture images and then send them
to the server. I set the image to be as Base64 and then send it to the server.
In the application I have this screens:
Feed
Post Screen
Fullscreen Image (Landscape)
When the user enters to each screen I get from the server a Base64 and
decode it to bitmap and set it to be the source of the imageview.
each screen has it's layout.
for the feed and post screens I set the imageview width and height to be hardcoded with some dp, and for the fullscreen image I set them to be fill_parent.
Now for each imageview I set the scale type to : fitXY, but I see that the
pictures are streched and in the fullscreen mode I can see the pixels.
I want to set the image to fit the xy but to be smooth as possible
I tried to set the adjustToBound to true and scaleType to cropCenter, fitCenter
and etc but it doesn't help.. how can I save the aspect ratio?
In order for adjustViewBounds to work, one dimension of the ImageView needs to be set to a hard value like dp value or match_parent, and the other dimension needs to be set to wrap_content. adjustViewBounds will make the wrap_content dimension adjust to be the right size to keep the image's aspect ratio.
I have an image which is actually 393 x 21 px, which I would like to set on the bottom of my View.
The problem is that, even if i set the width and the height to fill_parent, my image stays very small in the middle of the screen bottom and on the left and the right I have an empty field.
I can resolve this by reducing the Image width size mannualy but is ther any other solution whic could set the image in fullscreen ?
Thank you.
//in your xml Image attribute as
android:scaleType="fitXY"
or //using thru programatically
imgview.setScaleType(ScaleType.FIT_XY);
I am developing application having a resemblance appearance like " Gallery application".
When I click on image from the gallery... I want to fit image to whole screen..
I used this code..but it does not work .
can you guide me for this ...
Here is code for the same:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
imgView.setMinimumWidth(width);
imgView.setMinimumHeight(height);
imgView.setMaxWidth(width);
imgView.setMaxHeight(height);
you should use the following attribute of the imageview to fit the image to the screen.
Controls how the image should be resized or moved to match the size of this ImageView.
Must be one of the following constant values.
Constant Value
matrix 0
fitXY 1
fitStart 2
fitCenter 3
fitEnd 4
center 5
centerCrop 6
centerInside 7
android:scaleType="fitxy"
like wise you can use others to change the size of your image.
You may consider having the image open in its own activity, with android:noHistory="true" in the manifest, and onClick() have it end the activity. That way you don't have to worry about the image resizing and ruining everything in the activity it is being chosen in.
I have one question. I want to set one image to image button. I have one button image of size 90 x 48. I want to set this image on Image button.
Problems:
I need to set image on background parameter or src parameter?
If i set image on background parameter its not showing its actual size(smaller than actual size) if i have set the Layout width = wrap content and Layout Height= wrap content. If i give Layout width = 98dip and Layout Height= 48dip then its showing the same size. Is it a coorect way?
thanks
set image as background Parameter sometimes src makes problem
if you are set width and height as wrap_content then android will check the screen size and try to adjust to your screen if screen size is big then android displays your image as its actual height and width and if screen size is less then it will compress your image
so best way is to set height and width is as wrap_content if you have to use portrait and landscape mode both
Yes.
If you use Layout width = wrap content and Layout Height= wrap content, image will be as actual size. Maybe just the density of your monitor is less than the density of your phone?
Remember dip != pixels.