本文介绍了使用double值而不是int Android创建位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我需要使用双精度值创建一个位图.重要的是使用正确的值.

In my code I need create a Bitmap using double values. It´s important use the correct value.

我正在使用:

Bitmap bmp = Bitmap.createBitmap(int, int, Bitmap.Config.ARGB_8888);

...当我需要类似的东西时:

... When i would need something like:

Bitmap bmp = Bitmap.createBitmap(double, double, Bitmap.Config.ARGB_8888);

我尝试进行的所有转换(可能吗?)仅返回初始值或整数

Everything I've trying to make the conversion ( possible ? ) Only returns the initial value or integer

创建位图时如何使用双精度值?

How I can use double values ​​when creating the bitmap?

推荐答案

也许我误解了这个问题,但是位图是整个像素的栅格.您不能有像素的分数,因此createBitmap的参数中只能有整数行和列.

Perhaps I misunderstand the question, but bitmaps are rasters of whole pixels. You can't have fractions of pixels, so you can only have integer numbers of rows and columns in the parameters for createBitmap.

话虽如此,您可以使用通过Matrix drawBitmap方法应用的浮动比例因子来重新缩放位图的绘制方式,例如

Having said that, you can rescale how the bitmap is drawn using float scale factors applied via Matrix drawBitmap methods, e.g.

Canvas.drawBitmap(位图位图,矩阵矩阵,油漆)

Matrix matrix = new android.graphics.Matrix();
matrix.postScale(3.14f, 3.14f);
canvas.drawBitmap(bitmap, matrix, paint);

但是,在屏幕上渲染时,它将再次仅绘制整个像素,因此仍然不会显示小数像素.

However, when it comes to rendering this on screen, it will again draw only whole pixels, so you still don't get fractional pixels displayed.

这篇关于使用double值而不是int Android创建位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:51