我尝试将图像从1bpp转换为8bpp:
BitmapData dstData = dstImage.LockBits(
new Rectangle(0, 0, dstImage.Width, dstImage.Height),
ImageLockMode.ReadWrite, dstImage.PixelFormat);
try
{
int width = srcData.Width;
int height = srcData.Height;
unsafe
{
byte* srcBase = (byte*)srcData.Scan0.ToPointer();
byte* dstBase = (byte*)dstData.Scan0.ToPointer();
int srcStride = srcData.Stride;
int dstStride = dstData.Stride;
for (int y = 0; y < height; y++)
{
ushort* src = (ushort*)(srcBase + y * srcStride);
ushort* dst = (ushort*)(dstBase + y * dstStride);
for (int x = 0; x < width; x++)
{
byte mask = (byte)(0x80 >> (x & 0x07));
*dst = ((*src) & mask) != 0 ? (ushort)255 : (ushort)0;
if (mask == 1)
{
src++;
}
dst++;
}
}
}
}
finally
{
dstImage.UnlockBits(dstData);
}新的图像不是预期的灰度图像。用于设置像素值的algho似乎是错误的。
发布于 2019-05-27 20:09:10
变量src = srcBase +y* srcStride;var dst = dstBase +y* dstStride;
for (int x = 0; x < width; x++, dst++)
{
byte mask = (byte)(0x80 >> (x & 0x07));
*dst = ((*src) & mask) != 0 ? (byte)255 : (byte)0;
if (mask == 1)
{
src++;
}
}https://stackoverflow.com/questions/56331091
复制相似问题