-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poor exported PNG quality and text cutting #168
Comments
At the moment, I can't guarantee that this would be a good solution (because we're still working on improving the rendering quality), but you could try it out if you want to. //The code sample below is in "WpfMath/TexRenderer.cs
//If the method you're using calls the method below, the x and y values should be enough to prevent the text from getting cut (I could suggest 3.5 for both x and y).
public BitmapSource RenderToBitmap(double x, double y)
{
var visual = new DrawingVisual();
using (var drawingContext = visual.RenderOpen())
{
//this.Render(drawingContext, x, y);
drawingContext.DrawGeometry(Brushes.Black,new Pen(Brushes.Black,0.7),this.RenderToGeometry(x, y));
}
var width = (int)Math.Ceiling(2*x+this.RenderSize.Width);
var height = (int)Math.Ceiling(2*y+this.RenderSize.Height);
var bitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default);
bitmap.Render(visual);
return bitmap;
} |
Thank you for your quick response, @B3zaleel. Sadly it's not possible for me to use this code. I'm coding for a webpage. I'm using Visual Studio when coding and can't see the files. Installed Wpf-math as a socalled Nuget package. I'm coding in vb.net. Tried to convert your code, but I cant get it to work. But thanks anyway. I'm also using a memorystream, because I'm not allowed/it's not possible to use an image. It's working. But the image quality is not good. calling the latex2png function like this:
Kind regards. The text does not get cut off, when using a scaling factor below 16. |
If you you're using and have Visual Studio 2017 (version 15.7.5+) for coding, just click the Clone button, download the files, extract them at your working folder and you have the complete project with you(the built version is what you get from nuget, but you can't edit the files). If you try to build it, there won't be bugs waiting for you. You won't be able to convert the code if you don't have the project files. |
Ok. Thank you again. I’ll try to look into it. For now I have fixed it. I use scale 50 first and then shrink it afterwards. Images now look much better. I use wpf-math together with Gembox extension in VS2017. |
@troelschristensen one of the quality solutions for now would be to use SVG instead of PNG. Take a look at our example project: it has the stuff to render the formula into SVG image, it will scale much better. I was able to reproduce your "cutting" issue and I'm investigating it. |
@ForNeVeR Instead of using a TranslateTransform, why can't the origin be changed? It could prevent the text from getting cut. |
@troelschristensen You can save as svg without the sample project.
|
@B3zaleel well the origin could be changed, too, but for now there's another issue because our PNG rendering code was ignoring the user-provided origin. I'll fix that, too 😄 |
@ForNeVeR That's why in my first code sample here, I multiplied the origin by two and added it to the width, so that the end doesn't get taken out. |
FYI, the changes were published in WPF-Math 0.6.0. |
Thank you so much for this great extension.
First issue
My text gets cutted. Se the numbers in the images.
Next "issiue"
I have installed the extension on my vb.net server and I am linking to a function (called latex2png - see below) in the code:
Everything is working great, but sadly the quality of the image could be much better. Is there any way to get a higher quality of the png image that is created? Hope you can help me.
Seems like making the scale bigger is better. But the image gets to large in the end.
SCALE 12
SCALE 15
SCALE 25
BTW. I am writing the code in vb.net in aspx, and I am a novice. So go easy on me, when explaining. :)
Kind regards
Troels Christensen
The text was updated successfully, but these errors were encountered: