android imageview scrolling to display full high quality image - android

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);
}

Related

How do you add a trimmed circular button image to your android drawable folder?

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.

Image in ImageView auto scale when display the same BitmapDrawable with another ImageView?

This situation I have met in Android and still can't find any solution.
I have an ImageView display by these code:
BitmapDrawable value = ...;
imageView1.setImageDrawable(value);
Then I use imageView2 to display the same image in Drawable:
imageView2.setImageDrawable(value);
And ops,... the image in imageView1 auto scale and become bigger than the older. (imageView2 is bigger than imageView1).
Is there anyone saw this situation before?
Drawables are immutable, so the one bitmap is getting scaled and then shown by both ImageViews.
To get a different (unshared) version for the second one, try:
imageView2.setImageDrawable(value.mutate());

How to get width of what image really occupies on the ImageView android

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 :)

Android- How to get image size

I have an image loaded asynchronously by its url. Then i set the layout width and height according to the size of the of the image loaded. Is there a way i can get this aside from getting the size from my ImageLoader class using BitmapFactoryOptions (i forgot the, if it is BitmapOptions or BitmapFactoryOptions).
The problem is that at the start of the activity, the image is not rendered.
I am not quitely sure your case, but it is still able to get image's size by setting BitmapFactory.Options.inJustDecodeBounds = true even when the image is not rendered.

Removing image from ImageView and load new Image

I am facing problem on removing image from ImageView.
What I want an Image is loaded in ImageView, and then a new Image is taken by the camera and now that Image should load in ImageView replacing the previous one. I have tried
invalidate();
setImageBitmap(null);
setImageResource(0);
All these 3 methods are not working. Can someone help me.
Use this for setting image in ImageView
image.setImageResource(R.drawable.image);
If you want to set the Image By Drawable Image you can use like this
your_image_view.setImageDrawable(context.getResources().getDrawable(your_drawable_Image_id));
If you want to set the image by BitMapDrawable
your_image_view.setBackgroundDrawable(your_drawable_bitmap);
edit_countflag.setBackgroundColor(0);
edit_countflag.setImageResource(R.drawable.flag_id);

Categories

Resources