我想获取位图的像素列表。
我已经成功在屏幕上显示了位图,但是每次尝试获取像素列表时,数组总是为0。
我不确定为什么会这样。 我已经搜索并尝试了几天不同的答案。 数组的长度存在且不为null。因此,我不确定为什么它不起作用。
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
line = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.line);
sun = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.circle);
line = Bitmap.createBitmap(line, 0, 0, line.getWidth(), line.getHeight());
canvas.drawBitmap(line, 0, 0, null);
canvas.drawBitmap(sun, 0,0, null);
Log.d("BITMAP","WIDTH:"+line.getWidth()+" HEIGHT:"+line.getHeight());
pixelAmount = new int[line.getHeight()*line.getRowBytes()];
line.getPixels(pixelAmount,0,line.getWidth(),0,0,line.getWidth()-1,line.getHeight()-1);
Log.d("Line", "Pixel: " + pixelAmount.length + " Index" + 0);
Log.d("Line", "Pixel: " + pixelAmount[10] + " Index" + 0);
Log.d("Line", "Pixel: " + pixelAmount[100] + " Index" + 0);
Log.d("Line", "Pixel: " + pixelAmount[56] + " Index" + 0);
Log.d("Line", "Pixel: " + pixelAmount[76] + " Index" + 0);
}
}
createBitmap
去掉了,它仍然会在屏幕上显示,但是不起作用。我之前尝试过所有这些方法,似乎都不能让我得到图像的像素位置。 - Edon Freinerline = Bitmap.createBitmap(line.getWidth(), line.getHeight(), Bitmap.Config.ARGB_8888);
并用line = createBitmap(line, 0, 0, line.getWidth(), line.getHeight());
替换它? - Edon Freiner