本文介绍了如何将.txt和.docx文件转换为图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi, is there any way to convert whole .txt and .doc and .docx file to images file using c# for mvc web application? please help

推荐答案

public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/png";

        var text = context.Request.Params["text"];
        if (text == null) text = string.Empty;
        var image = CreateBitmapImage(text);

        image.Save(context.Response.OutputStream, ImageFormat.Png);
    }





页面布局:





page layout:

<asp:TextBox runat="server" ID="MyTextBox"></asp:TextBox>
   <asp:Button runat="server" OnClick="RenderImageButtonClicked" Text="Change text"/>
   <asp:Image runat="server" ID="MyTextImage" />





页面事件:





page event:

protected void RenderImageButtonClicked(object sender, EventArgs e)
    {
        MyTextImage.ImageUrl = "CreateImageText.ashx?text=" + HttpContext.Current.Server.UrlEncode(MyTextBox.Text);
    }


这篇关于如何将.txt和.docx文件转换为图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:32
查看更多