EMF增强型图元文件“逻辑坐标”翻译 [英] EMF Enhanced Metafile "Logical Coordinates" Translation

查看:158
本文介绍了EMF增强型图元文件“逻辑坐标”翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个涉及Windows增强型图元文件(.EMF)的项目,我正在寻找对文件内文本记录的逻辑坐标的一些见解。我的目标是在.NET控件中显示EMF文件,然后允许用户选择图像的矩形部分,然后检索选择中包含的文本。据我了解,这将涉及将显示文件的设备上下文中用户点击的坐标转换为EMF文本记录的逻辑坐标。我正在枚举文件并使用以下代码从文本记录中提取数据:



  if (recordType == EmfPlusRecordType.EmfExtTextOutW)
{
Marshal.Copy(data,dataArray, 0 ,命令datasize);
Int32 nChars = Marshal.ReadInt32(data, 36 );
Int32 rclBounds_left = Marshal.ReadInt32(data, 0 );
Int32 rclBounds_top = Marshal.ReadInt32(data, 4 );
Int32 rclBounds_right = Marshal.ReadInt32(data, 8 );
Int32 rclBounds_bottom = Marshal.ReadInt32(data, 12 );

Int32 exScale = Marshal.ReadInt32(data, 20 );
Int32 eyScale = Marshal.ReadInt32(data, 24 );

Int32 ptlReferencex = Marshal.ReadInt32(data, 28 );
Int32 ptlReferencey = Marshal.ReadInt32(data, 32 );

Int32 rcl_left = Marshal.ReadInt32(data, 48 );
Int32 rcl_top = Marshal.ReadInt32(data, 52 );
Int32 rcl_right = Marshal.ReadInt32(data, 56 );
Int32 rcl_bottom = Marshal.ReadInt32(data, 60 );

System.Text.UnicodeEncoding TextUTF16 = new System.Text.UnicodeEncoding();
dataString = TextUTF16.GetString(dataArray,Marshal.ReadInt32(data, 40 ) - 8 ,nChars * 2 );
}





我对使用这些类型的文件不太熟悉,但我相信我会把所有这些文件都拉出来我需要的数据。但是,我发现很难找到文档来帮助我彻底理解所有这些内容。有没有人知道如何将此数据中指定的逻辑坐标转换为显示文件的设备的坐标?非常感谢任何帮助。

解决方案

元文件几乎是变态的遗留数据类型;它已经几乎已经过时了。你不会相信这一点,但是你需要解析图元文件,你需要玩它。使用:

http:// msdn。 microsoft.com/en-us/library/system.drawing.imaging.metafile.playrecord.aspx [ ^ ],

一些代码示例在这里: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.metafile.aspx [ ^ ]。



元文件由播放解析,并由绘图创建。您可以使用 System.Drawing.Graphics 的实例绘制到元文件surface上。

要解决所有问题,请需要根据您自己的GDI +对象创建矢量图形的一些数据表示。然后,您将现有元文件解析为此数据结构,并始终使用它。然后,如果需要,可以通过绘图将其保存在图元文件中。



-SA

>我正在开发涉及Windows的项目

>增强型图元文件(.EMF),我正在寻找一些

>洞察文本记录的逻辑坐标

>在文件内。我的目标是显示EMF文件

>在.NET控件中,然后允许用户选择

>图像的矩形部分,然后检索文本

>包含在选择中。据我所知,

>这将涉及翻译

>的坐标。用户在设备上下文中单击显示

>将文件存入EMF文本的逻辑坐标

>记录。我正在枚举文件并提取数据

>使用此代码的文本记录:



如果您愿意使用第三方.NET组件,我认为MetaDraw .NET Winforms控件将大大简化您的任务。



MetaDraw看起来像是表格上的图片框,但是专门用于处理EMF和WMF图像(注意:EMF +不支持普通的EMF)。



使用MetaDraw - 你会

1)加载你的EMF图像(使用LoadPicture方法),

2)然后设置EditMode属性以使用户进入选择模式。然后,用户可以拖动他的鼠标来绘制矩形选择区域。将选择完全在该区域内的所有元素,并且用户将看到选择标记以知道他/她选择了哪些对象。然后,还可以允许用户添加或删除该选择中的对象。

3)您可能还想设置EditFlags属性以防止用户移动他选择的对象。 EditFlags属性有助于在选择编辑模式下自定义启用的功能



4)然后您可以计算所选对象的数量(读取ObjCount属性,

5)循环遍历它们(使用ObjMove方法)

6)并识别哪些是Text对象而不是形状等)(检查ObjType属性),

7)最后你会读出每个选定文本对象的文本(阅读Text属性)。



如你所见,你不需要了解有关坐标的任何信息。

如果你喜欢MetaDraw会把你的每个坐标都交给你图元文件中的文本对象,但你甚至不需要打扰它 - 你只想知道用户选择了哪些文本对象。



由方式 - 所有这些都可以在可滚动的可缩放窗口中工作,使用户更容易在图像中导航。



我希望这有用。

有关MetaDraw的更多信息,请参阅 - www.bennet-Tec.com



请注意 - 我的公司是MetaDraw的发布者所以这个并不是完全没有偏见 - 我认为这会很快,很容易满足你的需求,但我希望你知道我从前面来的地方。



Jeff

Bennet-Tec信息系统





**

**如有任何回复,请附上此信息的副本。

**



====================


I am working on a project involving Windows Enhanced Metafiles (.EMF) and am looking for some insight on the "logical coordinates" of text records withinin the file. My goal is to display the EMF file in a .NET control, then allow the user to select a rectangular portion of the image, then retrieve the text contained within the selection. As I understand it, this will involve translating the coordinates of the user''s click within the device context displaying the file into the "logical coordinates" of the EMF text records. I''m enumerating the file and pulling the data out of the text records with this code:

if (recordType == EmfPlusRecordType.EmfExtTextOutW)
{
    Marshal.Copy(data, dataArray, 0, dataSize);
    Int32 nChars = Marshal.ReadInt32(data, 36);          
    Int32 rclBounds_left = Marshal.ReadInt32(data, 0);
    Int32 rclBounds_top = Marshal.ReadInt32(data, 4);
    Int32 rclBounds_right = Marshal.ReadInt32(data, 8);
    Int32 rclBounds_bottom = Marshal.ReadInt32(data, 12);

    Int32 exScale = Marshal.ReadInt32(data, 20);
    Int32 eyScale = Marshal.ReadInt32(data, 24);

    Int32 ptlReferencex = Marshal.ReadInt32(data, 28);
    Int32 ptlReferencey = Marshal.ReadInt32(data, 32);

    Int32 rcl_left = Marshal.ReadInt32(data, 48);
    Int32 rcl_top = Marshal.ReadInt32(data, 52);
    Int32 rcl_right = Marshal.ReadInt32(data, 56);
    Int32 rcl_bottom = Marshal.ReadInt32(data, 60);

    System.Text.UnicodeEncoding TextUTF16 = new System.Text.UnicodeEncoding();
    dataString = TextUTF16.GetString(dataArray, Marshal.ReadInt32(data, 40) - 8, nChars * 2);
}



I am not too familiar with working with these types of files, but I believe I am pulling all of the data I need. However, I''m finding it difficult to find documentation to help me understand all of it thoroughly. Does anyone have any insight on how to convert the "logical coordinates" specified in this data into the coordinates of the device displaying the file? Any assistance would be greatly appreciated.

解决方案

Metafile is pretty much perverted legacy data type; it it''s pretty much obsolete already. You not going to believe that, but of you need to parse the metafile, you need to "play" it. Use:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.metafile.playrecord.aspx[^],
some code sample is here: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.metafile.aspx[^].

The metafile is parsed by "playing", and it is created by "drawing". You can "draw" onto the metafile "surface" using an instance of System.Drawing.Graphics.
To solve all of your problem, you need to create some data presentation of your vector graphics based on GDI+ object, your own one. Then you parse an existing metafile into this data structure and work with it all the time. Then, if you need, you can "save" it in a metafile by "drawing" on it.

—SA


> I am working on a project involving Windows
> Enhanced Metafiles (.EMF) and am looking for some
> insight on the "logical coordinates" of text records
> withinin the file. My goal is to display the EMF file
> in a .NET control, then allow the user to select a
> rectangular portion of the image, then retrieve the text
> contained within the selection. As I understand it,
> this will involve translating the coordinates of the
> user''s click within the device context displaying the
> file into the "logical coordinates" of the EMF text
> records. I''m enumerating the file and pulling the data
> out of the text records with this code:

If you are open to using a 3rd party .NET component, I think the MetaDraw .NET Winforms control will greatly simplify your task.

MetaDraw looks like a picturebox on your form but is specially designed for working with EMF and WMF images ( Note: EMF+ is NOT supported just plain EMF ) .

With MetaDraw - you''ll
1) load your EMF image ( use LoadPicture method ),
2) and then set the EditMode property to put user into a selection mode. The user can then drag his mouse to draw out a rectangular selection region. All elements that are fully within that region will be selected, and the user will see selection markers to know which objects he / she has selected. The user can then also be allowed to add or remove objects from that selection.
3) You''ll probably also want to set the EditFlags property to prevent the user from moving objects he has selected. The EditFlags property helps to customize the functionality enabled
in Selection edit mode.
4) You can then count the number of selected objects ( read ObjCount property ,
5) loop through them ( use ObjMove method)
6) and identify which are Text objects rather than shapes etc) ( check the ObjType property ),
7) and finally you''ll read out the text for each of the selected text objects ( read the Text property ).

As you see you don''t need to know anything about coordinates.
If you like MetaDraw will hand you back coordinates of each text object in the metafile, but you shouldn''t even need to bother with that - you just want to know which text objects the user has selected.

By the way - all of this will work in a scrollable, zoomable window making it easier for the user to navigate around the image.

I hope this is helpful.
For more information on MetaDraw see - www.bennet-Tec.com

Please note - My company is the publisher of MetaDraw so this is not entirely unbiased - I do think this will meet your needs really quick and easy but I want you to know where I''m coming from up front.

Jeff
Bennet-Tec Information Systems


**
** Please include a copy of this message with any reply.
**

====================


这篇关于EMF增强型图元文件“逻辑坐标”翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆