使用asp.net转换为图像 [英] Convert to image using asp.net

查看:128
本文介绍了使用asp.net转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我需要代码来解决如何将富文本框/自由文本框内容(包含文本和图像)转换为图像文件并使用asp.net将其保存在本地系统中。请帮我把这个转发。

提前感谢...



示例代码:



 受保护  void  Button1_Click( object  sender,EventArgs e)
{
string Text = FreeTextBox1.Text;
Color FontColor = Color.Black;
Color BackColor = Color.SkyBlue;
string FontName = Times New Roman ;
int FontSize = 14 ;
int 高度= 500 ;
int 宽度= 500 ;
string FileName = txtFilename2save.Text;
位图objBitmap = 位图(宽度,高度);
Graphics objGraphics = Graphics.FromImage(objBitmap);
Color objColor;
Font objFont = new 字体(FontName,FontSize);
PointF objPoint = new PointF(5f,5f);
SolidBrush objBrushForeColor = new SolidBrush(FontColor);
SolidBrush objBrushBackColor = new SolidBrush(BackColor);
objGraphics.FillRectangle(objBrushBackColor, 0 0 ,宽度,高度);
objGraphics.DrawString(Text,objFont,objBrushForeColor,objPoint);
// string From = ConfigurationManager.AppSettings [FromPath]。ToString();
// string To = ConfigurationManager.AppSettings [ToPath]。ToString();
string FromPath = @ E:\\ \\ + FileName + 。GIF;
/// string ToPath = @To + FileName +.JPG;
objBitmap.Save(FromPath,ImageFormat.Gif);
// Image1.ImageUrl =〜/ Questions / Original /+ FileName +.JPG;
string mainImage = @ E:\ + FileName + 。GIF;
// ImageSetting(txtwatermark.Text,,mainImage);
Image1.ImageUrl = 〜/ Image / + FileName + _ new + 。GIF ;
// convert2image();
}

public void convert2image()
{
位图bit1 = new 位图( 200 300 ,System.Drawing.Imaging .PixelFormat.Format64bppArgb);
图形gph1 = Graphics.FromImage(bit1);
string text;
gph1.Clear(Color.Orange);
text = FreeTextBox1.Text;
gph1.DrawString(text, new 字体( Arial 12 ,FontStyle.Bold),
new SolidBrush (Color.SkyBlue), new PointF( 0 .4F, 2 .4F));
Response.ContentType = image / Jpeg;
bit1.Save(Response.OutputStream,ImageFormat.Jpeg);
bit1.Dispose();
}

解决方案

点击此链接即可获得一个想法。



将文本转换为图像 [ ^ ]



http://codesimplified.com/2011/12/13/ convert-text-in-to-image-using-c / [ ^ ]



http://www.fordevs.com/2009/02/convert-text-to-image-using-c.html [ ^

Hello,
I need code for how to convert rich textbox/free text box content(which contains text as well as images) to image file and save it in my local system using asp.net. Please help me to convet this.
thanks in advance...

sample code:

protected void Button1_Click(object sender, EventArgs e)
    {
        string Text = FreeTextBox1.Text;
        Color FontColor = Color.Black;
        Color BackColor = Color.SkyBlue;
        string FontName = "Times New Roman";
        int FontSize = 14;
        int Height = 500;
        int Width = 500;
        string FileName = txtFilename2save.Text;
        Bitmap objBitmap = new Bitmap(Width, Height);
        Graphics objGraphics = Graphics.FromImage(objBitmap);
        Color objColor;
        Font objFont = new Font(FontName, FontSize);
        PointF objPoint = new PointF(5f, 5f);
        SolidBrush objBrushForeColor = new SolidBrush(FontColor);
        SolidBrush objBrushBackColor = new SolidBrush(BackColor);
        objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height);
        objGraphics.DrawString(Text, objFont, objBrushForeColor, objPoint);
        //string From = ConfigurationManager.AppSettings["FromPath"].ToString();
        //string To = ConfigurationManager.AppSettings["ToPath"].ToString();
        string FromPath = @"E:\" + FileName + ".GIF";
        ///string ToPath = @To + FileName + ".JPG";
        objBitmap.Save(FromPath, ImageFormat.Gif);
        //Image1.ImageUrl ="~/Questions/Original/" + FileName + ".JPG";
        string mainImage = @"E:\" + FileName + ".GIF";
       // ImageSetting(txtwatermark.Text, "", mainImage);
        Image1.ImageUrl = "~/Image/" + FileName + "_new" + ".GIF";
        //convert2image();
    }

public void convert2image()
    {
        Bitmap bit1 = new Bitmap(200, 300,      System.Drawing.Imaging.PixelFormat.Format64bppArgb);
        Graphics gph1 = Graphics.FromImage(bit1);
        string text;
        gph1.Clear(Color.Orange);
        text = FreeTextBox1.Text;
        gph1.DrawString(text, new Font("Arial", 12, FontStyle.Bold),
        new SolidBrush(Color.SkyBlue), new PointF(0.4F, 2.4F));
        Response.ContentType = "image/Jpeg";
        bit1.Save(Response.OutputStream, ImageFormat.Jpeg);
        bit1.Dispose();
    }

解决方案

Follow this link you get an idea.

Convert Text to Image[^]

http://codesimplified.com/2011/12/13/convert-text-in-to-image-using-c/[^]

http://www.fordevs.com/2009/02/convert-text-to-image-using-c.html[^]


这篇关于使用asp.net转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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