【问题标题】:Bitmap getPixels returns -1 for the whole array位图 getPixels 为整个数组返回 -1
【发布时间】:2011-09-24 22:04:49
【问题描述】:

我正在创建临时 Bitmap 以在其上绘制 Text,并且我想得到它 Pixels 以便我可以操纵这些像素(我不在屏幕上显示此图像)。 这是代码

Bitmap tempBitmap=Bitmap.createBitmap(200, 400, Bitmap.Config.ARGB_8888);//i've tested all Configs
Canvas tempCanvas=new Canvas(tempBitmap);
tempCanvas.drawColor(Color.WHITE);
tempCanvas.drawText("Hello", 0, 0, mPaint);//mPaint color set to Black

int[] pixels=new int[tempBitmap.getWidth() * tempBitmap.getHeight()];

tempBitmap.getPixels(pixels, 0, tempBitmap.getWidth(), 0, 0, tempBitmap.getWidth(), tempBitmap.getHeight());

但是当我打印所有像素时,它们都是 -1 值!为什么?

【问题讨论】:

    标签: android bitmap pixel


    【解决方案1】:

    您将文本的基线定位在 (0,0),因此您将其绘制在位图顶部。把它往下移一点。您可以使用Paint.getTextBounds 测量文本大小,然后使用返回的高度将文本向下移动。

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2019-12-07
      • 1970-01-01
      • 2011-05-27
      • 2016-07-10
      • 2012-07-11
      • 1970-01-01
      • 2017-01-29
      • 2020-10-20
      相关资源
      最近更新 更多