#region 图片合成
/// <summary>
/// 合成图片
/// </summary>
/// <param name="fileFoldUrl">文件夹url</param>
/// <param name="fileName">文件名</param>
/// <param name="_alMemo">要合成的每张图片的大小数组</param>
/// <param name="_width">合成后的宽度</param>
/// <param name="_height">合成后的高度</param>
public void tphc(string fileFoldUrl, string fileName, ArrayList _alMemo, int _width, int _height)
{
byte[] tp = get_tphcMemo(_alMemo, _width, _height);
this.view_picture(fileFoldUrl, fileName, tp);
}
/// <summary>
/// 获取合成图片后的字节大小
/// </summary>
/// <param name="_al">要合成的每张图片的大小数组</param>
/// <param name="_width">合成后的宽度</param>
/// <param name="_height">合成后的高度</param>
/// <returns>byte[]</returns>
private byte[] get_tphcMemo(ArrayList _al, int _width, int _height)
{
//byte[]
byte[] tp = null;
//MemoryStream
MemoryStream ms = null;
MemoryStream imgms = null;
//Bitmap
Bitmap bmp = null;
//image
System.Drawing.Image img = null;
//Graphics
Graphics gp = null;
try
{
ms = new MemoryStream();
bmp = new Bitmap(_width, _height);
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
img = System.Drawing.Image.FromStream(ms);
int i_top = 0;
for (int pic_i = 0; pic_i < _al.Count; pic_i++)
{
if (pic_i == 3)
break;
gp = Graphics.FromImage(img);
MemoryStream ms1 = new MemoryStream(((byte[])_al[pic_i]));
System.Drawing.Image img1 = System.Drawing.Image.FromStream(ms1);
Bitmap bmp1 = new Bitmap(img1);
Rectangle rtl = new Rectangle(i_top, 0, bmp1.Width, bmp1.Height);
gp.DrawImage(bmp1, rtl, 0, 0, bmp1.Width, bmp1.Height, GraphicsUnit.Pixel);
i_top += bmp1.Width;
ms1.Dispose();
img1.Dispose();
bmp1.Dispose();
gp.Dispose();
}
imgms = new MemoryStream();
img.Save(imgms, img.RawFormat);
imgms.Position = 0;
tp = new byte[imgms.Length];
imgms.Read(tp, 0, Convert.ToInt32(imgms.Length));
return tp;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
#endregion 图片合成
/// <summary>
/// 保存图片
/// </summary>
/// <param name="fileFoldUrl">文件夹url</param>
/// <param name="fileName">文件名</param>
/// <param name="zp">文件的字节数组</param>
public void view_picture(string fileFoldUrl, string fileName, byte[] zp)
{
MemoryStream ms = new MemoryStream(zp);
Bitmap btp = new Bitmap(ms);
DirectoryInfo dti = new DirectoryInfo(fileFoldUrl);
string fileUrl = fileFoldUrl + fileName + ".jpg";
btp.Save(fileUrl);
}