当前位置:文档之家› 将图片转换成HTML格式的文字图程序源代码

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

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

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

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

namespace https://www.doczj.com/doc/6613064363.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 strFileName = ofdPicture.FileName;
Picture2HtmlPicture clsHtmlPicture = new Picture2HtmlPicture();
txtTest.Text = clsHtmlPicture.MakeHtmlPicture(strFileName);


}

相关主题
文本预览
相关文档 最新文档