问题描述
在将 WMF 转换为 EMF+ 以获得抗锯齿渲染后,转换为 EMF+ 后仅包含我的 WMF 的左上象限.
After converting WMF to EMF+ in order to get anti-aliased rendering, only the upper left quadrant of my WMF is included after conversion to EMF+.
使用 EnumerateMetafile 绘制 WMF(转换前)有效,但不能消除锯齿,这正是我在这里所追求的.
Drawing the WMF (before conversion) with EnumerateMetafile works, but doesn't anti-alias, which is what I'm gunning for here.
知道为什么转换时会丢失四分之三的图像吗?
Any ideas why three quarters of the image is lost on conversion?
WMF 由 AutoCAD LT 生成,大小为 32640x14586 像素,单位/英寸=1632.
The WMF was generated by AutoCAD LT and 32640x14586 pixels sized, with units/inch=1632.
EMF 中的记录类型(转换后)是:
The record types in the EMF (after conversion) are:
EmfMin
Header
SetAntiAliasMode
SetPixelOffsetMode
SetTextRenderingHint
MultiplyWorldTransform
Save
MultiplyWorldTransform
SetWorldTransform
BeginContainerNoParams
SetAntiAliasMode
SetPixelOffsetMode
SetTextRenderingHint
SetPageTransform
SetWorldTransform
SetWorldTransform
SetWorldTransform
SetWorldTransform
SetWorldTransform
Object
Object
DrawPath
...
SetClipRegion
EndContainer
Restore
SetWorldTransform
EndOfFile
EmfEof
我试过在元文件回调中跳过 SetPageTransform 和 SetClipRegion,并且之前也缩放过图形,但没有任何帮助.
I've tried skipping SetPageTransform and SetClipRegion in the metafilecallback, and also scaling the graphics before, but nothing helps.
我看看能不能把原来的WMF分享给大家看看.
I'll see if I can share the original WMF for inspection.
通过这个问题看看这里的转换是如何完成的:如何启用反- 在 C#/WPF/WinForms 中将 WMF 渲染为 BitMap 时出现锯齿?
推荐答案
所以,我不得不将 SetWorldTransform 记录的矩阵缩放 0.75,然后就可以了吗??!
So, I had to scale the matrix of SetWorldTransform record by 0.75, then it's all ok??!
这就是我的 EnumerateMetafile 调用代码的外观,以及周围的代码,如果其他人发生这种情况.
This is how my EnumerateMetafile call code looks, with the surrounding code, if anyone else happens upon this.
graphics.EnumerateMetafile(emfPlusMetaFile, new PointF(0, 0),
(recordType, flags, dataSize, data, callbackData) =>
{
var dataArray = GetDataArray(data, dataSize);
AdjustWorldTransformScale(recordType, dataArray, 0.75f);
emfPlusMetaFile.PlayRecord(recordType, flags, dataSize, dataArray);
return true;
}
);
private static void AdjustWorldTransformScale(EmfPlusRecordType recordType, byte[] dataArray, float wtfScale)
{
if (recordType == EmfPlusRecordType.SetWorldTransform)
{
using (var stream = new MemoryStream(dataArray))
using (var reader = new BinaryReader(stream))
using (var writer = new BinaryWriter(stream))
{
var m11 = reader.ReadSingle();
var m12 = reader.ReadSingle();
var m21 = reader.ReadSingle();
var m22 = reader.ReadSingle();
stream.Position = 0;
writer.Write(m11*wtfScale);
writer.Write(m12*wtfScale);
writer.Write(m21*wtfScale);
writer.Write(m22*wtfScale);
}
}
}
private static byte[] GetDataArray(IntPtr data, int dataSize)
{
if (data == IntPtr.Zero) return null;
// Copy the unmanaged record to a managed byte buffer that can be used by PlayRecord.
var dataArray = new byte[dataSize];
Marshal.Copy(data, dataArray, 0, dataSize);
return dataArray;
}
(缩放参数的命名是有意的.)
这篇关于如何使用 GdipConvertToEmfPlus 将 WMF 转换为 EMF+ 而不会丢失四分之三的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!