我想将VerticalResolution
和位图的HorizontalResolution更改为固定值300
。更改图像对象的DPI
我有一个Windows服务需要一些TIFF并执行一些条形码相关的操作。除此之外,我从单页页面创建了多页TIFF。
问题是原来的DPI总是300,结果有96 DPI。
即使解析度相同且文件大小不变(考虑附加页面),这似乎是唯一相关的区别。
这是相关的,因为我需要在每个文件300 DPI。
这是我认为原因在于代码,从这里取:https://www.codeproject.com/Articles/16904/Save-images-into-a-multi-page-TIFF-file-or-add-ima
private Bitmap ConvertToBitonal(Bitmap original)
{
Bitmap source = null;
// If original bitmap is not already in 32 BPP, ARGB format, then convert
if (original.PixelFormat != PixelFormat.Format32bppArgb)
{
source = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb);
source.SetResolution(original.HorizontalResolution, original.VerticalResolution);
using (Graphics g = Graphics.FromImage(source))
{
g.DrawImageUnscaled(original, 0, 0);
}
}
else
{
source = original;
}
// some stuff here
// Create destination bitmap
Bitmap destination = new Bitmap(source.Width, source.Height, PixelFormat.Format1bppIndexed);
// other stuff
}
调试它,我看到指令之前:
Bitmap destination = new Bitmap(source.Width, source.Height, PixelFormat.Format1bppIndexed);
位图有VerticalResolution 300水平分辨率300. 它变成96x96。
我该如何改变这些图片属性,以使图片具有300 DPI?
使用SetResolution方法来设置原始Xdpi和Ydpi解决,默认DPI为新的位图对象是96x96的如在下面的答案指出。
显示我们一个[MCVE],我们可以帮助你。 – TheLethalCoder
我们不是在这里为你写代码 – MickyD
我在问是否有方法来设置我不能直接设置的属性。不要为我写代码。我将添加更多信息 – refex