怎么将图片转换成HTML源码
发布网友
发布时间:2022-04-24 15:25
我来回答
共3个回答
热心网友
时间:2023-10-19 03:13
<img src="图片路径" alt="标题" width"图片宽" height="图片高"/>
热心网友
时间:2023-10-19 03:14
PSD 切图 然后布局成含有HTML CSS JS 的静态 HTML页面,最后结合动态程序。形成网站
热心网友
时间:2023-10-19 03:15
using System;
using System.Drawing;
using System.Text;
namespace Blood.Com.ClassLib
{
/// <summary>
/// 将图片转换为Html
/// </summary>
public class Picture2HtmlPicture
{
/// <summary>
/// 构造函数
/// </summary>
public Picture2HtmlPicture()
{
//构造函数
}
/// <summary>
/// 将图片转换为HTML
/// </summary>
/// <param name="FileName">图片文件名</param>
/// <returns>HTML内容</returns>
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("<Html>\r\n");
sb.Append("<Body>\r\n");
sb.Append("<style>\r\n");
sb.Append(".Font{font-family: Arial; font-size: 1px}\r\n");
sb.Append("</style>\r\n");
intWidth = bmpPicture.Size.Width;
if (intWidth < 100)
{
intWidth = 100;
}
else
{
intWidth = bmpPicture.Size.Width + 50;
}
sb.Append("<Font Class=\"Font\">\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("<Font Color=\"" + strHexColor + "\">");
sb.Append("x");
sb.Append("</Font>");
sb.Append("\r\n");
}
sb.Append("<br>\r\n");
}
sb.Append("</Font>\r\n");
sb.Append("</Body>\r\n");
sb.Append("</Html>");
//返回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);
}