[SOLVED]weird 3/2 ratio when displaying my PNG with a Rect

Problems with Canvas, OpenGL, etc...

[SOLVED]weird 3/2 ratio when displaying my PNG with a Rect

Postby oxyde » Wed Aug 11, 2010 1:39 pm

hey there,

I have a png (2100 width and 800 height) containing a whole card deck.
the colors are on each row and each card on a column + jokers for each color. so 14 cards with 4 differents colors
So if my maths are ok each card is 150 (width) by 200 (height)

But when i do :
canvas.drawBitmap(bitmap, graphic.getRectangle(), dest, null);
i see the card i want to display + 50% of the next card on the right and 50% of the card on the next row.
I checked my rectangle and it s like top = 0, left = 0, right = 150, bottom = 200. So everything should be fine !

When i set the rectangle to be x,y,x + 150*2/3, y + 200*2/3 everything works fine but i can t understand why !!

dest is a rectangle with half the dimensions of the source.

Thanks for ur help
Last edited by oxyde on Thu Aug 12, 2010 12:40 pm, edited 3 times in total.
oxyde
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 11, 2010 1:28 pm
Location: paris, france

Top

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby pskink » Wed Aug 11, 2010 2:03 pm

and you run your app on what display?

its not HVGA right?

btw HVGA resolution is 320x480...
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby oxyde » Wed Aug 11, 2010 2:33 pm

hey,

thanks for ur quick answer which really helped me.
hw.lcd.density = 160
I just copied the png in the drawable-ldpi and -mdpi folders and now it works.

So android tries to resize my resources to adap the screen resolution ? is that right ?

I never though my problem could be related to the screen resolution since i though the original file could not be modified !

thanks again.
oxyde
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 11, 2010 1:28 pm
Location: paris, france

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby pskink » Wed Aug 11, 2010 2:44 pm

oxyde wrote:I just copied the png in the drawable-ldpi and -mdpi folders and now it works.


its nice i helped, but you dont have to duplicate precious resources

how do you create your Bitmap? using BitmapFactory?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: [SOLVED] weird 3/2 ratio when displaying my PNG with a R

Postby oxyde » Thu Aug 12, 2010 9:47 am

Yep, what should i do to avoid duplicate my files ? I m not aware of other means to create bitmap :)
thanks for your help !
oxyde
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 11, 2010 1:28 pm
Location: paris, france

Re: [SOLVED] weird 3/2 ratio when displaying my PNG with a R

Postby pskink » Thu Aug 12, 2010 10:27 am

oxyde wrote:Yep, what should i do to avoid duplicate my files ? I m not aware of other means to create bitmap :)
thanks for your help !


1. put your image in res/drawable folder
2. when using BitmapFactory.decodeResource use BitmapFactory.Options: opts.inScaled = false, iirc
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby MichaelEGR » Thu Aug 12, 2010 11:00 am

keep in mind that this is only for devices running Android OS 1.6+. It will fail on OS 1.5 and below and there are still lots of devices out there.. The sneaky thing is that on 1.5 OS and below images in drawable are not scaled by default. For 1.6 + you do the BitmapFactory.Options approach.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby oxyde » Thu Aug 12, 2010 11:10 am

ok so the folders drawable-hdpi, drawable-ldpi and drawable-mdpi are only used for resources i want to scale by mylsef, otherwise i use the root folder (res/drawable) to put my files and i specify to android not to scale them. Am i right ?

Well, it was good to learn from you guys !
oxyde
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 11, 2010 1:28 pm
Location: paris, france

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby pskink » Thu Aug 12, 2010 11:28 am

oxyde wrote:ok so the folders drawable-hdpi, drawable-ldpi and drawable-mdpi are only used for resources i want to scale by mylsef, otherwise i use the root folder (res/drawable) to put my files and i specify to android not to scale them. Am i right ?


res/drawable-*dpi are folders where android looks first for given density, if not found looks in more generic folders like res/drawable and if found here scales images

did Options.inScaled work?
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby MichaelEGR » Thu Aug 12, 2010 11:29 am

If I recall off the top of my head images still in drawable will be treated as mdpi on the 1.6+ OS. You'll want to verify that or someone else can chime in. drawable is really the backwards compatible resource directory. Also if you need to maintain 1.5 OS compatibility and also need to 1.6+ screen support -120dpi is synonymous with -ldpi and -240dpi == -hdpi. It's a little trick cause 1.5 doesn't puke with the numeric dpi tags. This jogs my memory, so I do believe that drawable with no screen size distinction is treated as -mdpi on 1.6+ and will be scaled if used on devices with a hdpi screen.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby pskink » Thu Aug 12, 2010 12:03 pm

yes Mike, you are right - res/drawable is equivalent to res/drawable-mdpi

and scaling is done when image is found in the place that doesn't match actual resolution, unless you play a bit with BitmapFactory.Options
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Re: weird 3/2 ratio when displaying my PNG with a Rect

Postby oxyde » Thu Aug 12, 2010 12:37 pm

pskink wrote:did Options.inScaled work?


yes it works great !

But for the moment i ve only deployed my app on the emulator. I havent looked how to plug my phone. I m still in the learning/testing phase :)
oxyde
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Aug 11, 2010 1:28 pm
Location: paris, france

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 5 guests