嵌入的 Jpg 图像高度有误,导致文档结构查看器无法查看图像
作者: Charltsing创建于 2025年12月27日更新于 2025年12月29日
标签改进
for (int i = 0; i < bytes.Length - 1; i++)
{
if (bytes[i] == 0xff && bytes[i + 1] == 0xc0) // Find the SOF0 segment. 2 marks + 2 lengths + 1 precision + 2 heights + 2 widths + 1 number of components
{
int jpgheight = (bytes[i + 5] << 8) | bytes[i + 6];
int jpgwidth = (bytes[i + 7] << 8) | bytes[i + 8];
if (info.Width > 0 && info.Width <= 65535 && info.Width != jpgwidth)
{
// Prefer the PDF dictionary
bytes[i + 7] = (byte)(info.Width >> 8);
bytes[i + 8] = (byte)(info.Width & 0xFF);
}
if (info.Height > 0 && info.Height <= 65535 && info.Height != jpgheight)
{
// Prefer the PDF dictionary
bytes[i + 5] = (byte)(info.Height >> 8);
bytes[i + 6] = (byte)(info.Height & 0xFF);
}
break;
}
}
内容来源: wmjordan/PDFPatcher