How to draw math symbols? - c#

I need draw some pictures and save it into a JPG file.
I know that the C# GDI can draw string with method Graphics.DrawString.
But what troubles me is that I need draw some math symbols, like below:
So are there some libraries can help me to do that? How can I get the math symbols with GDI?

In case you don't find a pure .NET solution, I would look for a command-line tool or a native DLL library which can render standard formattings like MathML or LaTeX math expressions. You will find plenty of FOSS stuff for these and I don't think it would be too hard to integrate. In case you work with bitmaps, you can just tell the 3rd party to render a given size bitmap. If you need vectorized drawings, then you could aim to produce your entire output in LaTeX or maybe you can turn MathML/LaTeX formulas to RTF/HTML.

Related

Dicom Images non square

I'm working with a set of DICOM images that are 512(columns) X 384(rows)
Is there a tool that would make the images 512X512? That is, filling the rows in this case to make it 512.
I've researched VTK with no luck.
Thanks!
Argh, you was almost there! In fact, VTK is not the proper tool for that. ITK is.
To be precise, VTK is for 3D visualization (that is, rendering of 3D objects), while ITK is specifically concerned for image processing.
So, using ITK, you could use a padding filter, here's a complete example from the official wiki, ready to be compiled and executed: http://public.kitware.com/pub/itk/Examples/src/Filtering/ImageGrid/PadAnImageWithAConstant/Documentation.html.
But, if you want to do the things in an easier way, I suggest MATLAB (ITK could be difficult to configure). In this case, this post could help: Padding an image in MATLAB.
Good luck!

How can I display mathematical expressions in WPF labels or panels?

I am writing software which displays a lot of mathematical content. As in windows forms it is already hard to set a subscript or a Greek letter in a label, I am thinking of switching to WPF.
At the moment I am searching for the best way to render a mathematical expression, a formula or just a symbol inside my graphical user interface. They have to be shown in labels or drawn graphs/pictures. No live/just-in-time renderings but beautiful fix symbols.
What is the best way to do that? I thought, that MathML should be supported well, but I can't find a lot regarding that. I would be glad to hear some advice.
Here is, where I can get my symbols from (or what I would prefer):
LaTeX-code (First choice! Code is already there and same appearance in Software and documentation would be marvellous)
MathML-code (LaTeX-code in Word 2007 or higher -> Word equations -> copy as plain MathML to clipboard)
SVG (some rendering of LaTeX in Inkscape and export to XAML)
xmcd Files (Mathcad XML Document. Don't know how, but at least it's XML)
html Files (written by LaTeX->html or Mathcad->html
What I wouldn't consider personally, but maybe there are good solutions to:
Images (png-icons, pdf, dvi, eps, svg directly imported)
Symbols (like copy pasted from Character Map. Don't like the fonts, wouldn't find all I need and exchange of formula syntax would not be given)
I think using LaTeX, MathML or html would be great as they could be used for documentation as well. I also could think about exporting calculation results to *.tex files or internally generate graphics completely with LaTeX (tikz, pgfplots...)
Consider using open-source WPF-Math library (disclaimer: I'm its' current maintainer).
It can help you to display the LaTeX expression in a WPF window. It also uses vector graphic instead of bitmaps, so the formulae will scale nice on the modern displays.
I would go with pure xaml approach using datatemplates. There is no need for another vector format or rednering engine.
You can use datatemplate for each expression in expression tree. Using viewboxes you can achieve stretching, so topmost expressions will be larger then inner expressions. Your datatemplates will generate visual tree from you expression tree. I mean there will be contentpresenters inside contentpresenter.
The great advatage is that the expression visualisation can be responsive and interactive, just like math expression in MS Word, or Excel.
I could help you with implementation, since this is not trivial, if you are not familiar with wpf datatemplates
As far as I can see, the best rendering (on paper) is achieved with a late conversion from a vector file. I would prefer using either GDI+ (System.Drawing) or WPF (System.Media) to render a formula. Let me know if we can collaborate on a WPF solution.
I used https://github.com/std8590/xmcd2cs to convert most of my Mathcad xmcd files to C#.
Then I used the formulas in code and make the input variables available in UI.

How to convert GDI+ GraphicsPath to HTML5 canvas Path?

Is there a library that would help to convert GDI+ GraphicsPath to HTML5 canvas Path? Or do I have to manually run through all GraphicsPath.PathPoints and GraphicsPath.PathTypes to emit corresponding HTML5 code (if so please share any hints)?
Unfortunately I couldn't find anything useful. Some people suggested using SVG as a way to "transport" curves from GDI to Canvas, but I couldn't find any decent SVG library for .NET. It took me quite some time to understand how the data inside GraphicsPath is stored because it is not as straightforward as you might think. This is what I've came up to.
Knowing how GraphicsPath actually work I've managed to recreate it using bunch of HTML5 functions: .moveTo(), .lineTo() and .bezierCurveTo(). The result was pretty neat although final string building takes some time and resulting JS files sometimes contain tenths of thousands lines of code if source GraphicsPath represents long text written with fancy font. Surprisingly Firefox handles them without problems.
I won't paste the code that I'm using as it is nothing special as long as you read and understand my answer from another SO question.

recognizing letter in image OCR

i searched with no result. If i copy other topic, please delete, not making mess.
I have question about image recognition OCR using C#
I am working on image which shows the scrabble.
First i converted image to grayscale, thresholded to find out only black letters and then I used median to avoid the walls around letters.
Now, how to start to get at the end function which will recognize letter? Should i somehow now separate 'foreach' letters :-) or just start recognizing ? On what problem should i take attention before start recognizing? Any sources will be welcome. :-)
Any idea will be also very helpful.
Well, this is a big, vast discussion...
If you don't want to reinvent the wheel, I suggest you use Tesseract, an open source OCR in C++, or Tessnet2 which is a .NET wrapper around it.
I had the same approach as yours, i.e. grayscale then thresholds etc in .NET, then I adapted a bit Tesseract (Tessnet2 is a wrapper around Tesseract 2.0, not 3.x which is the actual version) to have a good interface for OCR output then I have good results.
Here is another subject on OCR and Tesseract on Stack Overflow which describes more precisely what it consists in.
Of course if what you want is play with OCR concepts to make them work by yourself, this is not the good way :-)

How to load EPS files and draw them using WinForms

Is it possible to load and display EPS file using plain WinForms GDI+? If not, is there a free library to help out?
I seem to remember that Windows GDI supported EPS files, but after Googling around a bit, I am starting to doubt that memory.
All I want to do is load the file and draw it using a Graphics context.
I am aware that I can just use any program to convert the file to PNG or something and render it that way, but because I am trying to render at multiple resolutions, I would prefer to keep the vector data in the EPS file.
Thanks!
All the free or open source libraries I know that can convert EPS to other vector or raster format are all based on Ghostscript. You can invoke ghostscript directly, with wrapper provided or alternatively look at imagemagick. It is a very popular library for manipulating image graphics and has been around for a long time. It also internally relies on Ghostscript for handling EPS format. There is a .NET wrapper for it that you can find at http://imagemagick.codeplex.com/. You can read a bit about its background here too http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx. There is also pstoedit that is also based on ghostscript to read EPS and allow export to format like WMF. You will need to the call to pstoedit API using interop in .NET
Besides Ghostscript there are several commercial products that I known of like ImageGear and LeadTools which will let you take EPS to almost any other kind of graphic formats.
You can use GhostScript to produce images from an EPS. Once you have an image you can then display that within your application.
In your question you indicated you want the output in a vector format which would preclude bitmaps, jpeg etc. Here are a couple of ways of getting a XAML file which is a vector file with extensive support by Microsoft.
Microsoft Expression Blend 3 and Design 3 can both open .ai (eps) files and convert them to vector formats, design and XAML respectively, so it is definitely possible.
I know it is relatively easy to automate most Microsoft Office applications like Word and Excel, but I have not seen any documented com inter-op assemblies for these Expression products.
Perhaps you can use the converters that are part of Expression in an undocumented way?
If that doesn't work here is plan B:
Here is a free converter that will convert .ai (eps) files to XAML. To use it you need Adobe Illustrator however.

Categories

Resources