我们可以将这个字符串转换为Image/.ppt吗? [英] Can We Convert this string into Image/.ppt?

查看:65
本文介绍了我们可以将这个字符串转换为Image/.ppt吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将以下字符串转换为Image/.ppt吗?

Can We Convert Folowing string into Image/.ppt?

<div id="contentsDiv"  runat="server" style=" width: 311px; height: 388px; background-color: Red;"> <asp:Label ID="lblText" runat="server" style=" color:Black; font-size:12px; font-family:Arial;" Text="Write some thing"><br /><img align="right" alt="Koala" height="100" src="Images/no%20preview.png" width="100" /> <asp:Label ID="lbltextNew" runat="server" style=" color:Black; font-size:12px; font-family:Arial;" Text="Some thing means any thing">



请快速回复...



Please reply fast...

推荐答案

下面的分步代码将文本转换为图像并将其显示在网页上. br/>
第0步-包括命名空间
使用System.Drawing;
使用System.Drawing.Imaging;

第1步-声明属性
声明一些变量,这些变量将控制图像的行为和颜色.

字符串Text = Request.QueryString ["Text"];
颜色FontColor = Color.Blue;
彩色BackColor = Color.White;
字符串FontName ="Times New Roman";
int FontSize = 10;
int高度= 150;
int宽度= 150;

第2步-创建位图对象以保存图像
位图位图=新位图(宽度,高度);

第3步-使用此Bitmap对象创建一个Graphics对象
图形graphics = Graphics.FromImage(bitmap);

第4步-创建Color,Font和PointF对象.
颜色color = Color.Gray; ;
字体font = new Font(FontName,FontSize);
//定义文本将在图像的指定区域中显示的位置
PointF point =新的PointF(5.0F,5.0F);

第5步-创建画笔和笔
SolidBrush BrushForeColor =新的SolidBrush(FontColor);
SolidBrush BrushBackColor =新的SolidBrush(BackColor);
笔边框笔=新笔(彩色);

第6步-使用图形"对象绘制矩形
矩形displayRectangle =新Rectangle(新Point(0,0),新Size(宽度-1,高度-1));
graphics.FillRectangle(BrushBackColor,displayRectangle);
graphics.DrawRectangle(BorderPen,displayRectangle);

第7步-使用Graphics对象在指定的矩形上绘制文本字符串
//定义字符串格式
StringFormat format1 =新的StringFormat(StringFormatFlags.NoClip);
StringFormat format2 =新的StringFormat(format1);
//使用文本格式绘制文本字符串
graphics.DrawString(文本,字体,Brushes.Red,(RectangleF)displayRectangle,format2);

第8步-将位图以JPEG格式发送到页面输出流
Response.ContentType ="image/jpeg";
bitmap.Save(Response.OutputStream,ImageFormat.Jpeg);
The below step by step code converts the text into image and displays it onto the web page.

Step 0 - Include Namespaces
using System.Drawing;
using System.Drawing.Imaging;

Step 1 - Declare Properties
Declare some variables that will control the behavior and color of the image.

string Text = Request.QueryString["Text"];
Color FontColor = Color.Blue;
Color BackColor = Color.White;
String FontName = "Times New Roman";
int FontSize = 10;
int Height = 150;
int Width = 150;

Step 2 - Create a Bitmap Object to Hold The Image
Bitmap bitmap = new Bitmap(Width, Height);

Step 3 - Create a Graphics object using this Bitmap object
Graphics graphics = Graphics.FromImage(bitmap);

Step 4 - Create Color, Font, and PointF objects.
Color color = Color.Gray; ;
Font font = new Font(FontName, FontSize);
//define where the text will be displayed in the specified area of the image
PointF point = new PointF(5.0F, 5.0F);

Step 5 - Create Brushes and Pen
SolidBrush BrushForeColor = new SolidBrush(FontColor);
SolidBrush BrushBackColor = new SolidBrush(BackColor);
Pen BorderPen = new Pen(color);

Step 6 - Draw Rectangle using Graphics object
Rectangle displayRectangle = new Rectangle(new Point(0, 0), new Size(Width - 1, Height - 1));
graphics.FillRectangle(BrushBackColor, displayRectangle);
graphics.DrawRectangle(BorderPen, displayRectangle);

Step 7 - Draw Text string on the specified rectangle using Graphics object
//Define string format
StringFormat format1 = new StringFormat(StringFormatFlags.NoClip);
StringFormat format2 = new StringFormat(format1);
//Draw text string using the text format
graphics.DrawString(Text, font, Brushes.Red, (RectangleF)displayRectangle, format2);

Step 8 - Send the bitmap to page output stream in JPEG format
Response.ContentType = "image/jpeg";
bitmap.Save(Response.OutputStream, ImageFormat.Jpeg);


这篇关于我们可以将这个字符串转换为Image/.ppt吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆