OxyPlot WPF generate image in background - c#

I have the following problem:
I have a plot in one of my Prism views. My goal is to generate report from my application which includes generated OxyPlot chart. I use the following line to save the plot to the image:
plot.SaveBitmap(fileName, 960, 540, OxyColor.FromRgb(255, 255, 255));
The problem occurs when I try to save bitmap without previously see the plot in user interface. In this case I get only the blank plot, white bitmap with correct size but without content. There is no axis, no title (the bitmap is simply blank). When I use function to generate XAML instead of Bitmap, the result is the same: no content at all.
I had also noticed that the plot have both Width and Height set to 0 when plot is saving. Setting this values before Save function does not change the result file.
I have tried following codes just before saving image:
plot.InvalidatePlot();
Or even:
plot.InvalidatePlot();
Action emptyAction = delegate { };
plot.Dispatcher.Invoke(DispatcherPriority.Render, emptyAction);
plot.InvalidatePlot();
When I navigate the user interface that I can see the plot: the save function come back to correct behaviour. There are no exceptions, the plot has my data to plot just before saving.
Please, help...

I've had the same issue using oxyplot. I was trying to export the image to a file, but it was only working when I showed it at the screen first. To make it work you will have to define all the model programatically, and bind the model to the XAML. This way you will not have to pass through the view to export correctly.

Related

Not getting sharp image of rectangles on canvas

I am parsing a .sym extension font file to get the character shapes. Characters are to made using pixels and hence this font file contains information in such form that it shows which pixel is to be shown in black color and which is not be colored.
I have written logic to draw these pixels using Rectangles on a WPF canvas and everything works fine except for the fact that I am not getting a sharp image.
The purpose ultimately is to take the screenshot of this image of this canvas and paste wherever the user wants it to be pasted hence very clear image is required.
Also, when this image is exported in XPS and zoomed in, I get a very sharp image like below and hence I don't think there is any problem with the character making logic:
I don't understand why this mismatch in clarity is happening.

C# - Create an updating bitmap from a 2D array and display it in a picturebox

I currently have a complete game of life program written where nearly everything is done in classes. I'm trying to figure out how to display my 2D array (which is my Game of Life grid) in a windows form picturebox, as currently I only know how to run it in the console.
I'm very new to windows forms so as detailed of help as possible would be great :)
I have a class called Cell which represents each cell in the grid, and a class called GOL which represents a grid. Gol contains methods for setting the live cells and for updating each iteration of the grid in the game.
I know that I need to create a bitmap out of the 2D array, and somehow also use my methods on it, and then display that in the picturebox. No idea how to do any of it.
Thanks :)
The example for System.Drawing.Bitmap shows setting some pixels and displaying it with a PictureBox. Instead of creating a Bitmap from file you can just create one the same size as your grid new Bitmap(width, height)

Adding image to rtf doc being resized

We're using migradoc api to create an rtf document.. intermittently when we add an image it;s being resized and coming out absolutely tiny.
Code sample as follows:
MigraDoc.DocumentObjectModel.Shapes.Image image = section.AddImage(imagePath);
image.WrapFormat.Style = MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;
If I set LockAspectRatio to true and set a width it does stop is from rendering very small but ideally would like to be able to set a MaxWidth.
Has anyone experiences similar issue?
You have a choice of either changing the image itself by storing a different DPI value in it.
The .Net command to do so with a Bitmap bmp is:
bmp.SetResolution(newHRes , newVRes);
This should not involve reencoding, but I'm not sure.
However you also can simply set the desired DPI value in the Migradoc Image by using its Image.Resolution Property, which
Gets or sets a user defined resolution for the image in dots per inch.
I am not familiar with it at all but I found this code that might help you :
image.RelativeVertical = RelativeVertical.Page;
image.RelativeHorizontal = RelativeHorizontal.Page;

Bars in Bar graph are of different size

I am drawing a bar chart and I saw some of them have different width than others.
I tried changing PointWidth and PixelPointWidth properties. But of no use. Here is the graph I got :
The only configure I done is barChart1.Series["DeltaE"]["PointWidth"] = (0.6).ToString();
You may have too many data and the chart is too small. Try delete some data or make the chart bigger.
I made an example. I created a c# project, put a chart in the form, randomly add some data and run the program.
When the chart is big enough, it looks well.
When the chart is smaller, not all the columns are the same width.

Print coordinates in VB.NET or C#

I have to print invoices from my software. I created the layout with Adobe Illustrator and saved it as a PNG image. My original idea was printing the layout as a background and then print the actual data taken from the database. I printed my layout inside my function and then I measured the various boxes of the layout for correctly placing my text. The problem is that my text is not printed in the correct position that I've found. I tried to change the margins to 0 but it seems to have no effect. I want this: if I choose to print my text line at x=10 mm and y=20mm the text must be phisically printed in this position without scaling/translating, also my background image.
Can you help me?
Try using (e.g.) e.Graphics.PageUnit = GraphicsUnit.Milimeter, and then simply specify the desired values using the Graphics.DrawString Method

Categories