Getting the real dimensions of an image with titanium - android

I'm trying to create a cross-platform app.
So I have an image 1000x200 and I want to position it as image on background.
I try to calculate a real image size, to get it perfect on each screen. Because titanium resizes images and scales them in some magic way...
menuBottomImageView.toImage().width works fine on iOS and I get 1000px, but on android I get not the real size, only the displayed size and that's not what I need.
Is there a way to get the real dimensions of a file for both systems?

for Android there is no better method, if you use getWidth() method, it will give createImageView()'s width, mentioned in the object. best one is your method menuBottomImageView.toImage().width .

I don't have Android set up to test it, but on iOS I've discovered you can use:
var imgBlob = menuBottomImageView.toBlob(),
imgWidth = imgBlob.width,
imgHeight = imgBlob.height;
Using toBlob() is also much faster than using toImage(). According to the docs this is supported on Android, but then the docs say lots of things that don't always work out.

If the controller you are asking for toImage() is added and loaded on window then only it will give you proper size.

Related

MuPDF fit to screen issue android

I am creating an application where I need to show PDFs rendering.
For that purpose I successfully installed the MuPDF library and I'm able to see PDFs successfully.
Now I am facing an issue.
I am not able to see PDFs fit to screen.
I followed this also, but no success.
I think I need to do some thing with this method.
private void measureView(View v) {}
Can anyone guide me?
How can I achieve this?
I would have called what the Android app does by default "fit to screen", so I'm not sure what you are trying to achieve, but if you want (say) the page to fit the width of the screen, you could try replacing, within measureView,
float scale = Math.min((float)getWidth()/(float)v.getMeasuredWidth(),
(float)getHeight()/(float)v.getMeasuredHeight());
by
float scale = (float)getWidth()/(float)v.getMeasuredWidth();

How to support multiple screen sizes with my app in both Android and IOS Actionscript 3.0

I'm working on an game and after alot of progress i tested the game on my phone (Samsung s3 mini). When i tested it i realized the game didnt fit the screen, i used 2048*1536 stage size because i wanted to fit the ipad which has the biggest resolution i think, after seing this happen i have been looking all over the internet for help and i think i found the following links the most useful:
http://developer.android.com/guide/practices/screens_support.html
http://www.adobe.com/devnet/flash/quickstart/loading_images_library_as3.html
But i still have many questions but first of all let me clarify, what im making is a game, i just want the game to fit the screen (it will work on landscape by the way) i dont want different UIs for each resolution. So my questions are:
If I'm planning to make bitmaps for small, normal, large and xlarge
wouldnt that make the App unnecessarily heavy?
Why cant i simply make bitmaps for xlarge and scale them? and how
do you scale them.
From what i understood from the first link, Android will load the
best fitting assets automatically but how will i Access those
assets?
Im not very experienced so make it simple please or teach me what i dont know :P . Also i need an answer quick or else i wont get my drawings done :(.
You should use a framework like Starling that will handle this for you. If you don't want to use Starling, maybe you can see how it works there:
// create a suitable viewport for the screen size
//
// we develop the game in a *fixed* coordinate system of 320x480; the game might
// then run on a device with a different resolution; for that case, we zoom the
// viewPort to the optimal size for any display and load the optimal textures.
var viewPort:Rectangle = RectangleUtil.fit(
new Rectangle(0, 0, stageWidth, stageHeight),
new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight),
ScaleMode.SHOW_ALL);
var scaleFactor:int = viewPort.width < 480 ? 1 : 2; // midway between 320 and 640
var appDir:File = File.applicationDirectory;
var assets:AssetManager = new AssetManager(scaleFactor);
assets.verbose = Capabilities.isDebugger;
assets.enqueue(
appDir.resolvePath("audio"),
appDir.resolvePath(formatString("fonts/{0}x", scaleFactor)),
appDir.resolvePath(formatString("textures/{0}x", scaleFactor))
);
https://github.com/PrimaryFeather/Starling-Framework/blob/master/samples/scaffold_mobile/src/Scaffold_Mobile.as

Cocos2D android background image gets messed up

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 );
}

Android - extract pixel color from screen

I can't seem to find a good answer for this anywhere.
Is it possible to extract the a single pixel rgb directly from an android screen? (Not by taking a screen dump)
I need direct access to what's on the screen.
Any thoughts?
Thanks.
I don't know exactly but I can give you an approach.
if the view's drawingCache enabled you can get bitmap from getDrawingCache and you can get pixel data from that.
If you are using custom views and canvases, you definitely can:
have a look:
http://developer.android.com/reference/android/graphics/Bitmap.html#getPixel(int,int)

How to access pixels of a Bitmap image on Android?

In short I am unable to access all the pixels of a bitmap image.
I have used an intent to fire the native Camera app and returned a Bitmap image to my application activity. The data is definitely a bitmap object and I am able to display, get the height/width etc and access some pixels using getPixel(). However when I use the values of getHeight() and getWidth() I get an array out of bounds error. By trail and error I have found I can only access a reduced number of pixels of the image, for example with one image which returned a height and width value of 420,380, I could also access 200,100. I then do some image processing and used setPixel() on the original image. When I display the image it shows the, say 200,100, processing pixels and the rest normal, therefore the pixels are obviously there and accessible by android but not by me. I have to spoken to other people who have also had this problem with images.
Does anyone know anything more about this, reasons? or a work around?
Many thanks in advance.
It seems that there's no way around this, does anyone think it would be better/possible to access the image directly in memory maybe using the NDK?
You won't be able to access the pixel at (getWidth(),getHeight()) in any image because like everything else they are 0-indexed. The valid range of pixels is (0 to getWidth()-1, 0 to getHeight()-1), and thus the bottomrightmost pixel is obtained by b.getPixel(b.getWidth()-1, b.getHeight()-1).
Got an answer from Albert Pucciani on the Android forums. I now create an int buffer and copy the pixels to it, then use get() and put() to extract the pixels. It's also much quicker to use get() and put() instead of the get/setPixel() from the Bitmap class. Need to test now whether this does return all the pixels to the buffer for all images.
After more testing I have discovered this is simply a memory issue as the amount allocated for each process includes all bitmaps.

Categories

Resources