在C#.net中没有位图转换的矢量文件(.emf)中找到一个点 [英] find a point in vector file(.emf) without bitmap converting in C#.net

查看:91
本文介绍了在C#.net中没有位图转换的矢量文件(.emf)中找到一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i在一个项目中工作,我们必须在文本的第一行找到第一个字符的位置,我们将它存储在emf文件中。

我们还有另一个问题,有时我们的文本行可能有一个方程式,这个方程可能有一个非正常的高度。这意味着,距离图像顶部(y = 0)的顶部距离是浮动的:(



因为这个原因,我为你解释它们,我们必须找到第一个角色的位置,我们必须在一个很大的范围内(如1000分钟),并将emf文件转换为位图不利于我们的程序性能..



任何人都可以帮助我吗?


i worked on a project that in a step we must find a first character's position in a first line of a texts that we store it in a emf file .
also we have a another problem that , some times our text line may have a Equation and this Equation may have a anormal height . this means that , the lines top Distance from top of image (y=0) is Floating :(

for this reasons that I explain them for you , we must find a first characters position and also we must do this on a big range (like 1000 in a minute) and converting of emf file to bitmap is not good for our programs performance ..

any body can help me ?

推荐答案

这很可能但不是很简单.EMF文件并不是矢量图形原语的容器。一系列事件,可以播放,就像一个视频,可以显示。您可以使用 System.Drawing.Imaging.Metafile.PlayRecord 。请参阅 http://msdn.microsoft.com/en- us / library / system.drawing.imaging.metafile.playrecord.aspx [ ^ ]。





回答后续问题:



EMF中没有像素;它们仅在EMF在屏幕中呈现时创建。结果还取决于你渲染元文件的比例 - 它实际上没有自己的大小。



你需要获得一个位图来按像素计算任何东西。您可以使用 System.Drawing.Graphics.FromImage 创建位图,获取 System.Drawing.Graphics 的实例。然后,您需要在此实例上播放图元文件并在位图中获取像素图形。要查找像素,请勿使用 GetPixel 。始终使用 System.Drawing.Bitmap.LockBits ,请参阅此处的代码示例:http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx。< br $> b $ b

请参阅:

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx [ ^ ]。



-SA
This is quite possible but not quite trivial. EMF file is not exactly a container of vector graphical primitive. It is rather a sequence of events and can be "played", much like a video, to get displayed. You can find the EMF's elements by using the method System.Drawing.Imaging.Metafile.PlayRecord. See http://msdn.microsoft.com/en-us/library/system.drawing.imaging.metafile.playrecord.aspx[^].


Answering a follow-up question:

There are no pixels in EMF; they are created only when EMF is rendered in screen. The result also depends on the scale you render a metafile — it does not really have its own size.

You need to obtain a bitmap to calculate anything by pixels. You can create a bitmap, obtain an instance of System.Drawing.Graphics using System.Drawing.Graphics.FromImage. Then, you need to play a metafile on this instance and obtain a pixel graphics in the bitmap. To find pixels, never use GetPixel. Always use System.Drawing.Bitmap.LockBits, see the code sample here: http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx.

See:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

—SA


看来你正试图获得文本的左上角像素?



如果您只有文本而其他所有内容都是透明的,您只需加载Metafile并调用 .GetBounds(Imaging。它上面有MetafileFrameUnit.Pixel)



Kris
It seems you are trying to get the top left pixel of text?

If you just have text and everything else is transparent you can just load the Metafile and call .GetBounds(Imaging.MetafileFrameUnit.Pixel) on it!

Kris


这篇关于在C#.net中没有位图转换的矢量文件(.emf)中找到一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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