开发者

Android, rotate 18x18 pixel circle icon, result: icons of different sizes?

开发者 https://www.devze.com 2023-04-10 08:22 出处:网络
I\'m drawing a bunch of icons on a map. Actually the icons come from the same image rotated. But on the map the images take on two different sizes, I don\'t know why. This is what the result looks lik

I'm drawing a bunch of icons on a map. Actually the icons come from the same image rotated. But on the map the images take on two different sizes, I don't know why. This is what the result looks like: http://orangesoftware.net/iconmap.png

The image file looks like this: http://orangesoftware.net/arrow18.png

The code to rotate the icon:

Matrix mtx = new Matrix();
mtx.postRot开发者_JS百科ate(unit.heading);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), 
                     R.drawable.arrow18);
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                       bmp.getHeight(), mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);

Any magically insights appreciated, thanks


The cause of the variation in sizes is when a rotation is not a multiple of 90 degrees. The bmp becomes a diamond who's corners stick out beyond the ImageView holding it, thus it gets resized to fit the ImageView. The easiest way to take care of this discrepancy is to set the ImageView's scaleType to CENTER. This will simply center the image inside without scaling it to fit.

0

精彩评论

暂无评论...
验证码 换一张
取 消