There is a dynamic text (or in a more complex version-table) and you need to generate a .jpg image.
How to implement it?
Or somehow from rtf / doc format to generate a picture, but only through C #
- oneI love these questions. No details, apparently, so as not to restrain the imagination of the respondents. - Igor
- Well, writing text on bitmap is not a problem, but you will have to format it yourself. Do you need WinForms or WPF? - VladD 4:05 pm
- It is necessary to take the data of the to-do list, an example, cook borsch, buy bread .... from the base and form a list, which is then generated in the picture, and the picture is put on the desktop - Rakzin Roman
- Wpf is better. In fact, I would like to generate a picture for the desktop from the data, but if there is an option that my program would always be displayed, this one is certainly better ... as before the widgets were, but now I won’t find one like this - Rakzin Roman
|
1 answer
If we are talking about WPF, you can build a table using ordinary controls and then draw it into an image:
private void RenderControlToFile(UIElement control, string outputFilename) { control.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); control.Arrange(new Rect(0d, 0d, control.DesiredSize.Width, control.DesiredSize.Height)); var bitmap = new RenderTargetBitmap((int)control.DesiredSize.Width, (int)control.DesiredSize.Height, 96, 96, PixelFormats.Default); bitmap.Render(control); bitmap.SaveAsPng(outputFilename); } If you use this function, do not forget to specify the size of the table - here Measure() is invoked without restrictions, expecting that the control itself will calculate what size it will be.
UPD: If you want the application to be tied to the desktop, you can use SetParent() from user32.dll with the desktop handle, but this will not work with WPF. Although this article may help.
|