I do have a small 100X100 texture for my game, what my question is can i scale that image excluding its corner so that i can make different size window out of it. I am attaching the image so that u will have a better understanding, any help is appreciated, thanks :hug:
Here is the tool to create 9 patch images
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html
Try this. It should work.
Related
I am working on a project in which I am using a lot of images. My friend has designed all the images in photoshop and all those images are of my required size.
But the problem is that when my friend exported those images from the photoshop, he exported those images with a transparent background and that transparent background with the image makes the frame size bigger than required. And when I set that image to some ImageView, it expands to the whole screen due to its bigger frame size.
Now my question is that Is there a way to set image in imageview so that the transparent part is automatically ignored and the image of my required size just sets into the imageview. Or It is required to crop those images in photoshop and then use those images.
I am sorry if someone couldn't understand the question but I can elaborate if asked.
The way I would do it would be just edit them in photoshop, but I found another way if you want to look into it. Its called webP and you can check it out here. With this you can skip the transparency, but I think the size would stay the same, You can try it out if you want though.
Hope this helps!
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.
Reference the image attached. How to set such an image as background?
Does using 9-patch makes it possible?
Yes, Please Use 9-Patch image and Please check this on how to draw 9-patch image and also this Video Tutorial
Refer to your ldpi, mdpi, hdpi, xhdpi, and xxhdpi folders there you will have to format your image to fit the particular sizes of each screen. Another way of doing it would be android:setbackground="#drawable:example"; in your xml and testing your app out in the emulator on all the different screen sizes to see if it really matters that much due to the simplicity of your image.
It would be much simpler to create a high res .png file in your case. and might end up working better (just a thought)
If attached image is the only case, then you could try and create your own drawable by extending Drawable class.
It's just a rectangle with circles cutout on each side. This can be easily drawn using drawRect and drawCircle. This way you'll get perfect quality on every screen.
so im trying to make a game with just a simple static background at the moment, but when i draw it to the screen (no scaling being done as the resolution of the image is the same as the screen) it draws the bottom portion of the image incorrectly where the bottom few hundred pixels of the image are exactly the same going down the image. Sorry it's so difficult to explain but being new here i cant actually post an image of what is going wrong.
Now im just using a simple sprite to render this background image. Here is the code being used:
// background layer: another image
background = CCSprite.sprite("WaterBackground.png");
// change the transform anchor point (optional)
background.setPosition(CGPoint.make(GAME_WIDTH/2, GAME_HEIGHT/2));
addChild(background);
am i doing something wrong here? Does Cocos2D not support such large images for sprites? (resolution of 800*1280)
Any help would be greatly appreciated!
Since i am now able to upload images, here are visuals of what is going wrong:
And the problem in my game:
As you can see, the problem is hard to describe. The problem only exists with this larger image; i scaled it down manually in GIMP and then scaled it up for the game and it looked fine (except for being a lower resolution). I also tried scaling down this larger image which still resulted in the same problem. Hopefully you guys can help me as I have no clue what could possibly cause this error. Especially since i read that Cocos2D's max supported image size is 2048*2048 and my image is well within that.
Thanks for any help you guys can provide!
This is due to limitations on the size of textures. Coсos2d-android supports images with a maximum size of 1024 x 1024 pixels.
I faced the same problem and looking for a way to solve it.
EDIT
I found the solution
In cocos2d project open file CCTexture2d.java in org.cocos2d.opengl package and change kMaxTextureSize from 1024 to 2048
I'm not certain, as from your code and looking at the cocos2d code I can't see a definite reason why this would be happening, but given the number of sprites you've got on the screen, i'd definitely take a look at my answer to this question as you may well be hitting one of cocos2d's quirky little rendering faults around multiple sprites. can't hurt to try spritesheets, and it's certainly the correct way to actually do sprites in cocos.
also, definitely create yourself a helper utility to determine the scaling ratio of a device compared to your original image sizes, as unlike on iphone, android does have a pretty much unlimited variation of screen resolutions, and a simple bit of "scale as you load" utility code now will save you lots of time in the future if you want to use this on any other device.
you should try to make one method for adding background,i am doing this this like this way try this hope it will help full for you...here addBackGroundScene is my method and i am adding my background with this method,scrXScaleFactor is maintaining scaling part of my screen try this...
private void addBackGroundScene() {
CCSprite bgForLevel1 = addBackgroundAtOrigin("prelevel1/bgMenu.jpg");
bgForLevel1 .setScaleX(scrXScaleFactor);
bgForLevel1 .setAnchorPoint(0, 0);
addChild(bgForLevel1 );
}
I am creating 9 patch images using draw9patch tool and saving images with extension .9.png but when I am using created 9 patch images in app it is giving error.
But when I downloaded an 9 patch image from net & used in my same app it is working properly.
I am not getting what I am doing wrong .
Please Help
You must be creating the 9-patch wrongly. I had also the same issue . You must be drawing the black patch on one side of image. Try to draw the black patch by dragging your mouse two side of image. I hope you can understand my words...........
Nine-patch images on Android must have transparent 1-pixel edge, and have opaque pixels in left-top border (1 pixel wide) specifying which part of image is stretched, and which do not.
More here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch