我有一个 HBitmap,我正在使用一个 API 来转换 PDF 文档中的页面。生成的位图是 24 位彩色位图。我正在尝试使用制作成 pdf 的黑白扫描图像来确定 Foxit 生成的位图上的黑白图像。Foxit 是 PDF API。这是一些代码!(c++/cli)
// Get HBITMAP using Foxit's RenderPage function
// to convert to dib later
IntPtr hbitmap = FlattenPageToHBitmap(filename, page);
if (hbitmap == IntPtr::Zero)
return IntPtr::Zero;
Bitmap^ b = Bitmap::FromHbitmap(hbitmap);
bool isColor = false;
for (int y = 0; y < b->Height; y++)
{
for (int x = 0; x < b->Width; x++)
{
Color^ c = b->GetPixel(x, y);
unsigned int bits = (int)c->ToArgb();
bits = bits << 8;
bits = bits >> 8; //should get rid of A in ARGB
bool white = (bits == 0xFFFFFF);
bool black = (bits == 0);
if (!black && !white)
{
isColor = true;
break;
}
}
if (isColor)
break;
}
}
一旦我有了这个 HBitmap 并确定了它的颜色,我会将 HBitmap 转换为一个与设备无关的位图,我可以使用我们的内部工具包将其写回各种文档格式。
问题
Foxit 生成的 HBitmap 似乎从来都不是全黑或全白的。有没有一种算法可以用来查看它是否“足够接近”并进行转换?位图的像素格式在将其保存回 pdf 以确定使用的压缩时使用。