I'm using PNG images with transparency in my game and no matter what I do the edges of them get all grainy looking.
I have tried setting the following in my activity with no luck:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DITHER, WindowManager.LayoutParams.FLAG_DITHER);
Is there anything I can do in Photoshop or in my game to overcome this. Please see the image here:
It looks like your image is too low a resolution and the edges are not tidy, there is some white left over from when you deleted the background.
Open the image in photoshop, zoom right in and fix your edges. Probably best to redraw and resize again for the screen you are using.
Related
Dear Fellow Developers,
I've ran into the problem shown in the attached picture. We have been trying to tweak the dropdown menu's 9patch image provided by a graphics designer, but could not get it to work. The black stretch markers are not being hidden, and Android does not stretch it the way we would expect.
The device is a Nexus 7. We have tried several various image sizes, but none seemed to work. I am also attaching a copy of the 9patch.
What could be wrong?!
This happens:
Here is the 9patch
If the image has been created in a normal image editor rather than the android 9 patch tool, it could be just that its not done exactly right.
The image must have a 1px transparent border other than where the black lines are. Make sure its completely transparent and is only 1 px thick
Also I don't think you can have split lines (like you have down the left and right side of the image, I think they must be one solid line on each side)
I'm trying to use a 9-patch png for a Spinner, but the image isn't stretching as expected. I used Android Asset Studio.
Here's what the Spinner looks like:
http://i.imgur.com/MOXCccq.jpg?1
and here's what the 9-patch looks like:
http://i.imgur.com/gd6ywAu.png
The placement of the image is correct (it should be in the bottom right of the spinner), but I'm not sure why the color distortion is occurring (I want the entire spinner to be white).
Any suggestions? Thanks.
Your 9-patch is the problem. Looks like you downscaled this from a larger source? During the downscaling, your edge pixels were aliased:
So your stretch points are actually on semi-transparent pixels. Just fix those edge pixels to be white again and you'll be good to go.
I've made this 9-patch png and added it to the res/drawable folder:
It works nice in the example eclipse shows:
But on the emulator it looks messed up:
Why is this happening and how can I fix this?
EDIT: The border on which I've placed the black dots is white, not transparent. Not sure if that's got anything to do with it...
This probably happens because you have a small mistake with the black pixels you have set.
Try to re-cut the edges of the picture and to add the black pixels all over again.
I had this problem too once and this helped me.
if the border is white then this is your problem it has to be pure black or nothing at all.
UPDATE: Try this image:
It seems you are not saved your image with .9.png
In order to make it work do like this
save your image in the following format in your drawable folder
yourimage.9.png (not png format of your image)
Check this reference draw 9 patch
The Android SDK contains a 9-patch editing tool (draw9patch.bat) that can help you to produce and/or validate 9-patch images. Without it, it is very easy to make a mistake in defining your border.
The one-pixel border should be transparent except for the black pixels that define the various parts of the image to be treated differently during scaling.
Looking for advice with the next problem. I am developing small game and I have a *.png file for background. I need to put it to background of the main game screen. Moreover, it has to bee 2 times bigger in width and 1.5 times bigger in height as the screen's sizes, because my objects "flight" across these borders. Additionally the screen is moving around this background in a gameplay. But I have stuck a bit on how to do it.
I want my background to look similar on all screens with different sizes and densities. I have tried some solutions but I don't like them, or I have made something wrong:
Make different background images and put them in special folders. It sounds good, but with the amount of resolutions of Android devices in the market it is not sounds good for me. It will just make the size of *.apk bigger. And if I will use the methods to set background it will stretch the image - not a good idea I think.
In the onDraw() method draw the image on canvas. I have to put it's top-left corner to the most top-left corner of the possible game area and draw it. But, here is some options:
cut from the main image the image i want and draw only this piece (what I use now)
resize the image I have and draw with this changes
something else...
So, the question is: what is the best option for drawing background for the game screen when you need it to be almost twice bigger than the screen's size, make it looks same on all devices and move the screen around when the game is played?
you should use 9 patch image .
A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View in which you have placed it as the background.
see this link.
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
When using a transparent PNG image which has a fine fading shadow always there is an edge line around the shadow on the Android screen. It does not show this in emualator or Exclipse. See photo.
I wonder if there is way to improve on this. Is this something to do with inability of Android screen to show all 24 bit colours or the fact that is scaling and resampling image?
In this example the image is loaded into an ImageButton view. I tried it as source or background and it is the same quality.
The artefact you are seeing is known as "banding" and it is a consequence of your display being 16bits per pixel.
The best way to resolve this is to add some "noise" to your image asset in Photoshop or Paint.NET.
Alternatively you can set your window to be 32bpp with the following line added to your activity's onCreate(), between super.onCreate() and setContentView(). :
getWindow().setFormat(PixelFormat.RGBA_8888);