文档库 最新最全的文档下载
当前位置:文档库 › 将图片转换成HTML格式的文字图程序源代码

将图片转换成HTML格式的文字图程序源代码

将图片转换成HTML格式的文字图程序源代码.txt喜欢我这是革命需要,知道不?! 你不会叠衣服一边呆着去!以后我来叠! 我一定要给你幸福,谁也别想拦着。 ■ 将图片转换成HTML格式的文字图

————————————————以下为程序代码—————————————

using System;
using System.Drawing;
using System.Text;

namespace https://www.wendangku.net/doc/e311060798.html,.ClassLib
{
///


/// 将图片转换为Html
///

public class Picture2HtmlPicture
{
///
/// 构造函数
///

public Picture2HtmlPicture()
{
//构造函数
}

///
/// 将图片转换为HTML
///

/// 图片文件名
/// HTML内容
public string MakeHtmlPicture(string FileName)
{
try
{
int intX;
int intY;
int intWidth;
Color clrPicture;
Bitmap bmpPicture;
StringBuilder sb = new StringBuilder();
//检测文件名是否为空,如果为空,则返回空
if (FileName == "")
{
return null;
}
//打开图片文件
bmpPicture = new Bitmap(FileName);
sb.Append("\r\n");
sb.Append("\r\n");
sb.Append("\r\n");
intWidth = bmpPicture.Size.Width;
if (intWidth < 100)
{
intWidth = 100;
}
else
{
intWidth = bmpPicture.Size.Width + 50;
}
sb.Append("\r\n");
//通过循环,将图片的颜色提取出来
for (intY = 0; intY < bmpPicture.Size.Height; intY++)
{
for (intX = 0; intX < bmpPicture.Size.Width; intX++)
{
clrPicture = bmpPicture.GetPixel(intX,intY);
string strColor = clrPicture.ToArgb().ToString("x5");
string strHexColor = "#" + strColor.Substring(2);
//将图片颜色写到HTML中
sb.Append("");
sb.Append("x");
sb.Append("
");
sb.Append("\r\n");
}
sb.Append("
\r\n");
}
sb.Append("
\r\n");
sb.Append("\r\n");
sb.Append("");

//返回HTML内容
return sb.ToString();
}
catch(Exception err)
{
throw(new Exception("发生异常:" + err.Message));
}
}
}
}





————————————————————————————————————

private void button1_Click(object sender, System.EventArgs e)
{
ofdPicture.ShowDialog();
string s

trFileName = ofdPicture.FileName;
Picture2HtmlPicture clsHtmlPicture = new Picture2HtmlPicture();
txtTest.Text = clsHtmlPicture.MakeHtmlPicture(strFileName);
}

相关文档
相关文档 最新文档