As part of this application I am making, I want to change my wallpaper on my android device based on a bitmap that the user has selected.
I am able to change the background. However, the background is a completely distorted version of the bitmap. Any idea as to why this would happen?Here is my code:
Bitmap bitmap = ((BitmapDrawable)currentDrawable).getBitmap();
this.setWallpaper(bitmap);
My bitmap has a width of 240px and height of 180px. My emulator is of a size 480px by 800px.
I can scale my bitmap to 480px. However, the bitmap still ends up being distorted on the android wallpaper. Any thoughts on how this can be fixed?
Thanks in advance
You should create multiple images, for each potential (and common) resolution. You don't want any scaling, or the image will be distorted.
UPDATE:
Here is a ton of good information on support multiple screen sizes:
http://developer.android.com/guide/practices/screens_support.html
The wallpaper used by the default Launcher is bigger than the actual screen, that's why you can scroll the content and the wallpaper too.
Related
I have png images that have drop shadow. There is no unproportional images scaling problem, scaling are according to the aspect ratio.
When I using Image.asset() for placing images on phone screen, they're and their shadows looks low quality and not soft.
Original image looks: http://prnt.sc/p93vo2
Image on Android App: https://prnt.sc/p93vz3
Example images are same and 700x400, 96dpi.
You should see quality difference between images.
There is also a strange stuation. The shadow density on right and bottom side is more than shadow of original image on android app.
I've tried FilterQuality.high but no change, how to fix it?
In my case, the problem was due to a bad configuration of the image resolution system.
Full answer SO: Images loose quality when using image.asset in flutter
.
I am developing an android application which resizes android pictures. I was wondering if its possible to resize a file with resolution (1080X1920) to (500X500) square size.
Without looking too bad (quality and dimensions).
Let me show you an example.
First image:
Resized picture:
Answers using code will be appreciated
If you don't want to distort the image you have two options:
Crop the image
Implement the seam carving algorithm
Edit: this assumes you want to fill up the whole square. If not, just keep the width/height ratio and downscale the image properly so that the largest dimension fits in the side of the square.
In my app I have a Gallery-similar functionality and faced the issue that I need to scale the images. My test device in Nexus 5 which has a screen width of 1080p (360dp). Below are screenshots of an image having a width of 604 pixels opened with my app and the system-default Gallery:
My app:
=============================
Gallery:
The code I use to show the image is quite simple:
pathToImage = getIntent().getStringExtra("path");
img = (ImageView) findViewById(R.id.imgPictureView);
try {
bmpImage = BitmapFactory.decodeFile(pathToImage);
img.setImageBitmap(bmpImage);
} catch (Exception e) {
e.printStackTrace();
}
Opening a hi-res camera photo causes my ImageView to adjust its width to fill the screen, however I'm getting a heap size of about 80 (!!) MB.
It's obvious that the system gallery decides whether to scale the Bitmap up/down to make it fit the screen. For example, it scales a 60px image up, but only by a small factor so it doesn't become really blurry. I guess it also scales large camera pictures down to prevent OutOfMemoryError's. So in my example above, the gallery assumed the width of 604px is enough to scale it up to 1080 without noticeable quality loss, my app of course not due to lack of any additional code.
So the question is: how can I achieve the same result and determine the factor to scale images up/down without quality loss depending on the current screen?
Note: for those who will now post tons of (beyond controversy amazing) code examples showing how to actually scale a Bitmap or determine the screen width - this is NOT my question.
Bitmap can use a lot of memory and you got to scale them down. Instead of giving you a copied solution, here's a detailed documentation:
http://developer.android.com/training/displaying-bitmaps/index.html
You really should go through the whole guide. There's a lot to learn.
Second, set your ImageView's width to MATCH_PARENT and try changing its scaleType attribute to centerCrop. Play with the other available values for scaleType to get your desired result.
I want to create a bitmap from a view in Android, which basically works fine using the following approach: http://www.aquajava.hu/2011/06/19/converting-view-to-bitmap-without-displaying-it/
However, I want to modify this approach. Basically, my application supports multiple display densities for all kinds of resolution. Instead of creating a bitmap from a view based on the device's display, I want that the bitmap created always relies on the HDPI version. So although the display is maybe smaller I want to create a bitmap with 480 * 800 pixels. If I just increase the size of the bitmap, the font sizes and images still stay small according to the density. I don't want to just scale the image because the resolution would be quite poor then.
So basically, I search for a way to create a bitmap from a view ignoring the density of the view.
Does anybody know how I can solve this?
Have you tried calling setDensity on your Bitmap?
I have an image which is intended to be a background image, which fills the whole screen. The problem I am having is that the image displayed on the phone is of a much poorer quality than the original image. I have saved the image as a 320x480 jpg image, as my phone's display resolution is 320x480 also, so it is not related to the re-sizing of the image.
Here is a picture of what I'm seeing. On the left is the image opened on my desktop, on the right is a screenshot taken from my android phone.
The image quality on the phone can be improved by adding dither, but it is still not ideal. I'm struggling to understand what is going on. It appears as though the image is being loaded with reduced fidelity. It's almost as if the image is being draw in RGB_565 format, even though the phone is capable of 16m colors and should be able to display the image fine
Lots of people have similar problems with gradients. Try putting this in your activity:
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Window window = getWindow();
window.setFormat(PixelFormat.RGBA_8888);
}
What directory contains your image?
You should be careful with densities.
For example, if density of your screen is low and you put image to the drawable-mdpi, it will be blurred even if it has size exactly like screen one.
Try to put image to drawable-nodpi.
It could be the result of the jpg compression, which is lossy, which means you lose quality everytime you save it as a jpg, try using a png instead.