Libgdx - textures - android

If I create a texture of .PNG 1024 x 1024 and draw a circle in the middle that is 124 x 124, around it would be empty, does it use the same amount of RAM as if I would draw a circle 124 x 124 on a 124x124 space?
I could make all sprites in photoshop on a 1920 x 1080, and lay it out there already and then import all in game at a 0, 0 coordinate and all would lay out perfectly!

Transparency has nothing to do with RAM usage - it depends on how big in decoded image it means that for picture 16x16 it will need 4 times more memory than for 8x8 no matter if it is transparent or not
Second thing is that by using pictures like this you will impact rendering performance because renderer will need to "iterate" over all pixels - also these transparent

Related

Resizing a SurfaceView such that a grid of squares can perfectly fit inside it

I'm working on an android game almost exactly the same as flood-it. I'm drawing a grid of coloured squares in a surface view via calls to Canvas.drawRect. The problem I encounter is when the size of the grid of squares (eg. 14 squares x 14 squares) is not evenly divisible into the dimensions of the surface view in pixels, I end up with a small empty border around the surface view.
For instance, (Looking at things on a very small scale for demonstration purposes) if I needed to draw a grid of 2 squares x 2 squares on a surface view that was 15 pixels x 15 pixels, I could draw the squares as 7 pixels x 7 pixels each, but that would make all 4 squares cover an area of 14 pixels squared, leaving me with a small 1 pixel border around the right and bottom of the surface view that looks bad.
My question is how I go about solving this. I have the surface view defined in my layout file as 350dp x 350dp.

Large bitmap not being drawn

I'm in the works of a game and I'm loading a large image that is 5120 wide and 116 high. When I try to draw it to the screen using
canvas.drawBitmap(land, 0, 0, paint);
nothing gets drawn. However when I use a smaller file (512x116) with the same method call, it gets drawn. Is there a image size limit? My image is 750 KB. Also the max canvas width and height is 8192. Thanks in advance!
EDIT:
I noticed this in the log:
Bitmap too large to be uploaded into a texture (20480x464, max=8192x8192)
as if my bitmap is 4 times larger than its actual size. Why would that be?
EDIT 2: Found the issue. Bitmapfactory is returning a larger file because is multiplies the dimensions by my screen density. So the file ends up being too large.
I haven't used Canvas layout but try using largeHeap = "true" in your Manifest

How to blur some portion of Image in Android?

I am working in a project where I have to show some portion of the image clear and make rest part of the image blur. The blur should be managed by slider. Means it can be increase or decrease. The final result image should look alike below.
During my research for this I found below links useful
http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android/
https://github.com/kikoso/android-stackblur
http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android/
But the issue in above links is they all make complete image blur. Not some part of image.
Kindly suggest some solution to achieve this. Thanks in advance.
do a masked blur few times ....
create mask
0 means blur (black) and >=1 means not blur (white). Init this part by big enough value for example w=100 pixels
create masked blur function
just a common convolution with some matrix like
0.0 0.1 0.0
0.1 0.6 0.1
0.0 0.1 0.0
but do it only for target pixels where mask is ==0 after image is blurred blur also the mask. This should enlarge the white area a bit (by pixel per iteration but losing magnitude on borders that is why w>1).
loop bullet #2 N times
N determines blur/non-blur gradient depth the w is only to assure that burred mask will grow... Each time the blur mask will increase its white part
That should do the trick, You can also use dilatation of the mask instead of blurring it.
[edit1] implementation
Have played with this a bit today and found out that the mask is not growing enough with smooth so I change the algo a bit (here mine code C++):
picture pic0,pic1,pic2;
// pic0 - source
// pic1 - output
// pic2 - mask
int x0=400,y0=330,r0=100,dr=200;
// x0,y0,r0 - masked area
// dr - blur gradient size
int i,r;
// init output as sourceimage
pic1=pic0;
// init mask (size of source image) with gradient circles
pic2.resize(pic0.xs,pic0.ys);
pic2.clear(0);
for (i=1;i<=255;i++)
{
r=r0+dr-((dr*i)>>8);
pic2.bmp->Canvas->Brush->Color=TColor(i<<16); // shifted because GDI has inverse channel layout then direct pixel access
pic2.bmp->Canvas->Pen ->Color=TColor(i<<16);
pic2.bmp->Canvas->Ellipse(x0-r,y0-r,x0+r,y0+r);
}
for (i=1;i<255;i+=10) pic1.rgb_smooth_masked(pic2,i);
here the smooth function:
//---------------------------------------------------------------------------
void picture::rgb_smooth_masked(const picture &mask,DWORD treshold)
{
int i,x,y;
color *q0,*q1,*m0,c0,c1,c2;
if ((xs<2)||(ys<2)) return;
for (y=0;y<ys-1;y++)
{
q0=p[y ]; m0=mask.p[y];
q1=p[y+1];
for (x=0;x<xs-1;x++)
if (m0[x].dd<treshold)
{
c0=q0[x];
c1=q0[x+1];
c2=q1[x];
for (i=0;i<4;i++)
q0[x].db[i]=DWORD((DWORD(c0.db[i])+DWORD(c0.db[i])+DWORD(c1.db[i])+DWORD(c2.db[i]))>>2);
}
}
}
//---------------------------------------------------------------------------
create gradient mask with circles increasing in color from 1 to 255
rest is black the gradient width is dr and determine the smoothing sharpness.
create smooth masked with mask and threshold
smooth all pixels where mask pixel is < threshold. See the function rgb_smooth_masked. It uses 2x2 convolution matrix
0.50,0.25
0.25,0.00
loop threshold from 1 to 255 by some step
the step determines the image blur strength.
And finally here some visual results this is source image I taken with my camera:
And here the output on the left and mask on the right:
the blue color means values < 256 (B is lowest 8 bits of color)
I use my own picture class for images so some members are:
xs,ys size of image in pixels
p[y][x].dd is pixel at (x,y) position as 32 bit integer type
clear(color) - clears entire image
resize(xs,ys) - resizes image to new resolution

Repeat texture on all surface without stretch jogl ES

i want repeat a texture automat without stretch , example , if have a texture 256x256 and one 512x512 , secound texture (512 x 512) is big like square and no repeat , but first need repet 4 time , but i want do automat , i know if i set param to texture like
{0,0 ,0,4,4,4,4,0}
first texture will repeat 4 time , but if change texture dimension need change again coord. Any suggestion ?
You can use glTexParameteri with GL_REPEAT, GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T.
You have to pass some texture coordinates from 0.0 to 2.0 so that the texture is repeated 4 times (2 * 2).

how to use background image for texture in openGL

i want to use background image with texture but texture get images with power of 2 so i made image size (800x480 to 512x512).
but now it is showing image with some blank space.
how can i show image on entire screen. and also want to horizontally scrollable .
Well, if this is on Android, that means you don't have glDrawPixels, so the only way you could be "showing" an image would be to render a textured quad. So just make the quad whatever size you need.
You can also draw multiple textures, just by drawing one texture to one location, then drawing another texture to another location.
You need to use the right texture coordinates when rendering your background. You need to compute the texture coordinates so that you are having an offset for the axis perpendicular to the black borders.
I guess you resized your 800x480 image so that it fits in 512x512 pixels, making you end up with the actual background image (inside the 512x512 texture) being 512x307?
This would mean that your u texture coordinate offset would need to be (512.0 - 307.0) / 2.0 / 512.0 ~ 0.2, so your texture coordinates would need to be (0.0,0.0), (0.0,0.2), (1.0,0.2), (1.0,0.0).

Categories

Resources