I am creating a game for android and I would like the sprites to have the look of an old NES game. I have some 12x12 pixel images and would like them to keep their pixelated look as they are scaled up.
Please view the following link
http://imgur.com/a/LR3eK/all
One image is a screenshot of the image as it looks in an editor. This is how I would like it to look in game. The other image is what it actually looks like blown up in game (blurry).
The image is imported as a Drawable and I'm calling Drawable.draw(Canvas canvas) on it.
I've read up on the problem and found some info here (Android: drawable resolutions). I believe it's either that anti aliasing or some kind of interpolation needs to be disabled but I cannot figure out how to do this with a Drawable.
I did however find out that it is possible with Bitmaps but my game requires lots of sprite re-scaling and, although I found this Resize Bitmap in Android I do not think re-scaling bitmaps is a good idea.
I am new Android and no where near a professional programmer so please shed some light on me.
In my app I had to do the exact same thing!
Paint paint = new Paint();
paint.setDither(false);
paint.setAntiAlias(false);
And I used pixel-sized images to save space, and a Matrix to handle rotation and scaling (though that's your choice).
Hope this helps, good luck!
EDIT:
also if you're using the createScaledBitmap, or any similar functions, make sure you pass false for any filtering parameters.
Related
I'm new to android development so I have this novice question here:
I have a Canvas View, customized, in an activity. I want to programmatically display images (PNG drawables).
Clearly I have 2 ways of doing this, the first, more conventional way is:
Option I:
Find the "Activity Layout" (the layout for the entire activity)
Set params for the PNG ImageView.
ActivityLayout.addView(pngImageView)
Edit: So this way, the PNG will be shown, but not really "a part of" the Canvas, as it is not really drawn "in" the Canvas, but on top of it but to users, it's impossible to tell.
Option II:
Use a Drawable object, set its resource to my desired PNG drawable, then call
Drawable.draw(myCanvas)
Edit: In this way, the drawable will be "a part of" the Canvas and actually drawn "in" it. But then again, the users wouldn't be able to tell it from the first option.
Would I be better off with Option II? Particularly, I want to manipulate the png drawable, flip it, rotate it etc. probably using Matrix.
Thanks in advance!
Edit: I want as little hassle as possible, and I want to be able to export the entire canvas to bmp file in the future including everything on the canvas and the png drawable.
The differences is that the canvas drawing is done by hardware acceleration (GPU), and the Dynamic drawing is done by software (CPU). If you disable hardware acceleration, they become the exact same.I am not sure which one is the more accurate, they seem like just different implementations.
If I create a texture atlas 2048x2048, must I also make each and every texture imported into the atlas a square of 2 dimension.
Because I'm wasting a lot of space if I do that.
But my guess also is that I have to, because the MipMap filter scales it down diagonally... So if I make a rectangle, it wouldn't know how to scale it...
Any ideas?
From my experience you don't need to use n^2 images in libGDX. You can just put in any sized image in the atlas and libGDX will handle it correctly.
I never had any problems with scaling rectangular images, just using the libGDX code..
I hope this answers your question.
i am trying to implement some photo effects i try different effect like sketch painting effect, Emboss effect,
and now i m trying to implement Oil Painting Effect.
i found this link
http://supercomputingblog.com/graphics/oil-painting-algorithm/
but at my level this to hard to understand plz help me in this, or any other reference link for it.
Download JHLabs Library for Android from the following link.
https://code.google.com/p/android-jhlabs/
https://code.google.com/p/android-jhlabs/downloads/list
There are the effects given for oil painting, Emboss nad many more.
You can create pencil sketch effect from DoG Filter followed by GrayScale given in the library.
I think oil paintings are simulated best using a technique called "Stroke Based Rendering" (SBR) pioneered by Aaron Hertzmann. It's been around for a long time. Whether you do this in android or any other os doesn't make much of a difference.
What you need is a function that takes a rectangle and an orientation, and place a brush stroke on the current canvas. The brush itself is defined as a set of 2 texture grayscale images: one for the opacity and one for the height. You need one for the height so that you can use create a bump map alongside the canvas (the rendered image). Now, the tough part is to get good texture maps for your brushes so that it looks realistic. That's where you need to experiment quite a bit and see what you like best. Everybody has its own idea of what looks best.
To define the rectangle and its orientation, you can use image moments. The end result is that your brush strokes will kinda follow the contours of objects, which is usually what artists do (not always though).
In any case, this methodology is better explained here (this is link to my blog):
http://3dstereophoto.blogspot.com/2018/07/non-photorealistic-rendering-software.html
You can try the software called "The Painter" which I wrote (free and works on windows 64 bit) to see what can be done using SBR. Maybe it's not what you want at all. Here's the link to the software (also includes toon shading and watercolor rendering):
http://3dstereophoto.blogspot.com/p/painting-software.html
Again, this is a link to my blog which deals primarily with 3d photography. I happen to also like painting a lot.
I am trying to make a game for the android. I currently have all of my art assets loaded into the drawables folder, but my question is how do I actually reference a specific one to render it?
I know that the files each have a unique #id, and I probably have to implement in the #override of the onDraw(canvas) method. so the question is how do I actually display the image to the screen?
I have looked through a good half dozen books and all those talk about is getting an image off the web, or manually drawing it with the paint functionality, but I have the assets ready to go in .bmp, and they are complex enough that coding paint to draw them by hand will be a very great migrain.
I would prefer a direction to look in (specific book, tutorial, blog, open source code[assuming quality comments])I am still kinda learning java as my 2nd programming language and so I am not to the point of translating pseudocode directly to java yet.
[added in edit]
does drawing using Paint() every frame have a lower overhead then rendering a bitmap, and only changing the display when it changes?
for 2Dgames I would recommend you to use SurfaceView
load your image as a bitmap and let the canvas draw that bitmap.
to animate the images there are two possible way :
You could inflate the view
Create a looping thread to call the draw function
Here's some good starting tutorial about displaying image in Android, especially for games
You can use one of the drawBitmap variants of the Canvas class. A canvas object is passed in the onDraw method. You can use the BitmapFactory class to load a resourse.
You can read a nice tutorial here.
I'm writing an application that displays large bitmaps in tiles like Google Maps does. A server sends bitmaps that I draw into a scaled/translated canvas. I want this bitmaps to be drawn anti-aliased, but if I enable anti aliasing on the canvas, the edged of the bitmaps are mixed up with the background (none/black) and produce ugly dark lines between the tiles.
Is there a way to tell Android not to antialias the edges of the bitmap on drawing? Or what other soulutions exist for that problem?
You don't enable anti-aliasing on the canvas, you enable it on the Paint object you provide to Canvas.drawBitmap(). So the solution here, I believe, is to use two different Paint objects, the first with AA off for drawing bitmaps, and the second with AA on for drawing everything else.
You may still be interested in using Paint.setDither() or Paint.setFilterBitmap() to affect how the bitmaps are drawn.
Let me answer the question on my own: I got confused because I thought antialiasing was the feature I needed. In fact, setting antialias to false and bitmapfiltering to true on the Paint-object solved the problem. Antialiaising set to true made the ugly lines between the tiles.
Thanks!