different ppi's for X and Y axis?

Monkey Targets Forums/Android/different ppi's for X and Y axis?

Midimaster(Posted 2012) [#1]
I gave my first app to my wife and all the images inside the app look streched on her smartphone.

We both have 320x240pix displays, but my display is 44mm x 58mm (Samsung GT5300) and hers is 45mm x 68mm (Huawei u8510). Her display is nearer to 1:1.5

When we open pictures on both smartphones, it seems, that the gallery app knows the ppi's, because we can see perfect shaped pictures with black borders if necessary.

So my question is: Does anybody know, where to get the ppi's values for x and y axis with monkey?


Xaron(Posted 2012) [#2]
That's what I do, I usually work with a fix resolution of 480x320 (iPhone 3gs):

Function CheckForResolution:Void()
  gScaleRatioX = 1.0
  gScaleRatioY = 1.0
  gTranslateX = 0.0
  gTranslateY = 0.0
  'Seitenverhaeltnis bestimmen
  Local dWidth:Float = Float( DeviceWidth() )
  Local dHeight:Float = Float( DeviceHeight() )
  gResX = DeviceWidth()
  gResY = DeviceHeight()
  Local imgSetHeight:Float = 480.0
  Local imgSetWidth:Float = 320.0
  gAspectRatio = dHeight / dWidth
  If( gAspectRatio > 1.5 )
    'Typisch fuer mein Desire mit 800x480 (=1,67)
    'In diesem Fall wird das Bild in X-Richtung in die Mitte geschoben
    gScaleRatioX = dWidth / imgSetWidth
    gScaleRatioY = dWidth / imgSetWidth
    gTranslateY = ( dHeight - imgSetHeight * gScaleRatioY ) / 2.0
  Else If( gAspectRatio <= 1.5 )
    'Typisch fuer das Wildfire mit nur 320x240 (=1,33)
    'In diesem Fall wird das Bild in Y-Richtung in die Mitte geschoben
    gScaleRatioX = dHeight / imgSetHeight
    gScaleRatioY = dHeight / imgSetHeight
    gTranslateX = ( dWidth - imgSetWidth * gScaleRatioX ) / 2.0
  Else
    gScaleRatioX = dWidth / imgSetWidth
    gScaleRatioY = dHeight / imgSetHeight
  End If
End Function


And in the main loop:

  Method OnRender:Int()
    Cls()
    SetScissor( gTranslateX, gTranslateY, Float(gResX)*gScaleRatioX, Float(gResY)*gScaleRatioY )
    PushMatrix()
      Translate( gTranslateX, gTranslateY )
      Scale( gScaleRatioX, gScaleRatioY )

      'Do your stuff here
    PopMatrix()
  End Method


The converted mouse coordinates are:

  gCurrentMouseX = Float( MouseX() ) / gScaleRatioX - gTranslateX / gScaleRatioX
  gCurrentMouseY = Float( MouseY() ) / gScaleRatioY - gTranslateY / gScaleRatioY


Or you can use Diddy or another framework like Ignition. ;)


Gerry Quinn(Posted 2012) [#3]
As a last resort, you could let the user shrink the image horizontally or vertically in steps.


Midimaster(Posted 2012) [#4]
Thanks Xaron,

but this is not the problem I have. Also my GUI uses 2 scaling factors, which calculate betwenn different DeviceWidth()'s and DeviceHeight()'s.

But as you see in my explanation: Both smartphones tell me 320x240, but have a different real physical dimension of the screen! So DeviceWidth() and DeviceHeight() alone does not bring the solution.

There must be a android value or function that knows the ppi (pixel per INCH!) for X- and Y- axis.

p.s.
you are german? Are you also member of blitzforum.de?


Xaron(Posted 2012) [#5]
I'm an evil Kraut, yes. Und ja, bin im Blitzforum und im Monkeycoder.de. ;)

In your case it looks like DeviceHeight and DeviceWidth return wrong values which I had in the past when the AndroidManifest.xml missed some values. But I can't remember which these were... Damnit!


Midimaster(Posted 2012) [#6]
Hi Xaron,

thats not the point. Both smartphones really have this physical resolution of 320x240pix. So not the returned values are wrong, but the ratio of the real screen differs. My Samsung GT5300 offerns 320x240 with a height of 44mm and therefore the width should be 66mm, but has only 58mm.


Amon(Posted 2012) [#7]
Have you tried implementing Autofit by DruggedBunny(Boydee)?


Xaron(Posted 2012) [#8]
So you mean it has non quadratic pixels? Never heard of this but in that case you don't have a chance at all. Failure by design I'd say. That is so rare I'd just ignore it.