views:

92

answers:

1

I'm trying to render custom buttons in Android. However, I'm having issues getting my bitmaps to render without scaling. I have a few constraints that are forcing me to forgo a few possible solutions. First, my bitmaps are being generated using a byte array through BitmapFactory; which I'm passing in bitmap options that specify inScaled=false for that. Second I must do everything in code, and am unable to use layout XML.

When I go to draw my custom button (which extends View), along with using the default behavior, I've tried calling setDensity on the canvas with both DENSITY_NONE and bitmap.getDensity( ) (which is 160.) Despite this I can't get the bitmaps to render without scaling up. I've tried setting more options when creating my bitmaps (such as target density, screen density, etc.) However no combination of these has worked. This code 'fails' on the Samsung Galaxy S running 2.1 as well as HTC Droid Incredible on 2.1. When testing on an HTC Hero running 1.5 things work, but that was before the density stuff:/

Anyone out there have a suggestion?

Thanks!

Update:

I was a bit miss guided with my problem. It seems that the issue is with the underlying view. If I try to draw a normal line, I get scaling as well. This only happens in landscape, not portrait. Is there any way to disable the scaling between the two orientations?

+1  A: 
  1. Make sure you have screen compatibility mode turned off by targeting SDK >= 4 or explicitly settings android:anyDensity="true".
  2. Do NOT change the density of the Canvas. That has the screen density. It shouldn't lie about it.
  3. Set the density of your generated bitmap appropriately. Either the same density as the screen, or DENSITY_NONE.
hackbod