-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateImage.aspx.cs
79 lines (62 loc) · 2.65 KB
/
GenerateImage.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Slides;
namespace SlideImageGenerator
{
public partial class GenerateImage : System.Web.UI.Page
{
//Create an image from text using Aspose.Slides for .NET
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ImageGenerate(object sender, EventArgs e)
{
try
{
//here we're creating a title slide using Aspose.Slides' SlideLayoutType
Presentation pres = new Presentation();
ISlide slide = pres.Slides.AddEmptySlide(pres.LayoutSlides.GetByType(SlideLayoutType.Title));
//next, we take some text as input. You can use as much text as appropriate in your case.
//Setting title as author
((IAutoShape)slide.Shapes[0]).TextFrame.Text = TextBoxAuthor.Text;
//Setting session as sub-tilte
((IAutoShape)slide.Shapes[1]).TextFrame.Text = TextBoxSession.Text;
//You can also set scaling factor by your choice with Aspose.Slides API
float ScaleFactor = 1;
var image =slide.GetThumbnail(ScaleFactor, ScaleFactor);
//the resultant image created from the text is saved to memory stream, but you can save it to disk or storage as well
MemoryStream mem=SaveAsImage(image);
//the image memory stream is rendered to the user and the user can see the output image
Response.Clear();
Response.ContentType = "Application/png";
Response.AppendHeader("Content-Disposition", "attachment; filename="+TextBoxAuthor.Text+".png");
Response.BinaryWrite(mem.ToArray());
Response.Flush();
Response.Close();
Response.End();
}
catch (Exception ex)
{
}
}
private static void SaveAsImage(System.Drawing.Bitmap img, string path)
{
//save the image in the form of PNG
//Aspose.Slides provide different image formats in which you can save the output image
img.Save(path, ImageFormat.Png);
}
private static MemoryStream SaveAsImage(System.Drawing.Bitmap img)
{
MemoryStream mem =new MemoryStream();
img.Save(mem, ImageFormat.Png);
mem.Position = 0;
return mem;
}
}
}