Create a .png file at runtime and export.
Hi, I'm currently working on a non game app for my work. At the moment, I'm trying to generate a pdf file at runtime using PDFsharp. However, I thought of an idea and searched the forums and answers to see if it had been done already. Instead of trying to pull image file locations, set scales, set the location of text and draw boxes and blah blah blah. Is it possible to create a blank letter size image, add more images and text to it, then export the "image" with all it's other images and text in the correct spots as a .png? C# please.
I can't give you complete code, but i think with the methods of Texture2D, RenderTexture and Graphics.Blit() to combine them, it should be possible.
You could do them all in front of a camera and then use the CaptureScreenshot function
Answer by GearBreak · Jun 27, 2018 at 03:39 PM
Hi herCoder, I know it's been a while since you opened this thread but I'm interested in it by myself. After some research I found out, that the easiest method is to create a bitmap by width and height and export it with standard c# methods (unity does not have/need any for exporting .png) and combine your letter or other images with it by writing an array of bitmaps and a own method to combine those bitmaps in the right order. Here is a code for writing and exporting a .png file to any location.
//create the bitmap
Bitmap bmp = new Bitmap(50,50);
Graphics g = Graphics.FromImage(bmp);
//paint the bitmap here with g. …
//I just fill a recctangle here
g.FillRectangle(Brushes.Green, 0, 0, 50, 50);
//dispose and save the file
g.Dispose();
bmp.Save(@"filepath", System.Drawing.Imaging.ImageFormat.Png);
bmp.Dispose();
Your answer
Follow this Question
Related Questions
Having text be a child to a game object? 2 Answers
Loading an 'UI skin pack' 1 Answer
Making a in editor public writing prompt 0 Answers
Text to Texture2d / png 0 Answers
Display Hit Text On Collition 0 Answers