问题描述
在将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时会出现别名?
See how the conversion is done here via this question:How to enable anti-aliasing when rendering WMF to BitMap in C#/WPF/WinForms?
推荐答案
因此,我不得不将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 +而又不会丢失四分之三的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!