gpt4 book ai didi

java - 绘制位图最快的方法

转载 作者:行者123 更新时间:2023-12-01 11:04:34 25 4
gpt4 key购买 nike

protected Bitmap createBufferedImageFromImageTransport() {
int k = 0, i = 0, j = 0;
int[] pixelData;
Canvas canvas;
Paint paint;

Bitmap newImage = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
canvas = new Canvas(newImage);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);

pixelData = imageTransport.getInt32PixelData();

canvas.drawBitmap(pixelData, 0, width, 0, 0, width, height, false, null);

MainActivity.handler.sendEmptyMessage(1);

return newImage;
}

我有一个从像素数据创建位图的函数。但图像很大,所以这种方法对于我的程序来说太慢了。我想用 OpenGL ES 或更快速的方式来实现。你能给我任何关于它的建议或任何样本吗?

最佳答案

尝试锁定位图数据,使用指针手动设置值。这是最快的。

public override void PaintPoint(Layer layer, Point position)
{
// Rasterise the pencil tool

// Assume it is square

// Check the pixel to be set is witin the bounds of the layer

// Set the tool size rect to the locate on of the point to be painted
m_toolArea.Location = position;

// Get the area to be painted
Rectangle areaToPaint = new Rectangle();
areaToPaint = Rectangle.Intersect(layer.GetRectangle(), m_toolArea);

Bitmap bmp;
BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = data.Stride;
unsafe
{
byte* ptr = (byte*)data.Scan0;
// Check this is not a null area
if (!areaToPaint.IsEmpty)
{
// Go through the draw area and set the pixels as they should be
for (int y = areaToPaint.Top; y < areaToPaint.Bottom; y++)
{
for (int x = areaToPaint.Left; x < areaToPaint.Right; x++)
{
// layer.GetBitmap().SetPixel(x, y, m_colour);
ptr[(x * 3) + y * stride] = m_colour.B;
ptr[(x * 3) + y * stride + 1] = m_colour.G;
ptr[(x * 3) + y * stride + 2] = m_colour.R;
}
}
}
}
bmp.UnlockBits(data);
}

关于java - 绘制位图最快的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33079810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com