图片合成的方法
#region 图片合成
public byte[] WritePic(ArrayList _al,int _width,int _height)
{
//System.Collections.ArrayList;
byte[] pic_by;
System.IO.MemoryStream Ms,imgms;
Bitmap bmp;
System.Drawing.Image img0;
try
{
Ms=new System.IO.MemoryStream();
bmp=new Bitmap(_width,_height);
bmp.Save(Ms,System.Drawing.Imaging.ImageFormat.Jpeg);
img0=System.Drawing.Image.FromStream(Ms);
int i_top=0;
for(int pic_i=0;pic_i<_al.Count;pic_i++)
{
Graphics gp=Graphics.FromImage(img0);
System.Drawing.Image img=System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte[])_al[pic_i]));
Bitmap bmp1=new Bitmap(img);
gp.DrawImage(bmp1,new System.Drawing.Rectangle(0,i_top,bmp1.Width,bmp1.Height),0,0,bmp1.Width,bmp1.Height,System.Drawing.GraphicsUnit.Pixel);
i_top+=bmp1.Height;
gp.Dispose();
img.Dispose();
bmp1.Dispose();
}
imgms=new System.IO.MemoryStream();
img0.Save(imgms,img0.RawFormat);
imgms.Position=0;
pic_by=new byte[imgms.Length];
imgms.Read(pic_by,0,pic_by.Length);
Ms.Close();
imgms.Close();
bmp.Dispose();
img0.Dispose();
return pic_by;
}
catch(Exception pic_e)
{
// WriteLog(DateTime.Now+"\t"+str_pz_wfbh+"\t图片合成失败"+pic_e.Message);
return null;
}
}
#endregion
}
public byte[] WritePic(ArrayList _al,int _width,int _height)
{
//System.Collections.ArrayList;
byte[] pic_by;
System.IO.MemoryStream Ms,imgms;
Bitmap bmp;
System.Drawing.Image img0;
try
{
Ms=new System.IO.MemoryStream();
bmp=new Bitmap(_width,_height);
bmp.Save(Ms,System.Drawing.Imaging.ImageFormat.Jpeg);
img0=System.Drawing.Image.FromStream(Ms);
int i_top=0;
for(int pic_i=0;pic_i<_al.Count;pic_i++)
{
Graphics gp=Graphics.FromImage(img0);
System.Drawing.Image img=System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte[])_al[pic_i]));
Bitmap bmp1=new Bitmap(img);
gp.DrawImage(bmp1,new System.Drawing.Rectangle(0,i_top,bmp1.Width,bmp1.Height),0,0,bmp1.Width,bmp1.Height,System.Drawing.GraphicsUnit.Pixel);
i_top+=bmp1.Height;
gp.Dispose();
img.Dispose();
bmp1.Dispose();
}
imgms=new System.IO.MemoryStream();
img0.Save(imgms,img0.RawFormat);
imgms.Position=0;
pic_by=new byte[imgms.Length];
imgms.Read(pic_by,0,pic_by.Length);
Ms.Close();
imgms.Close();
bmp.Dispose();
img0.Dispose();
return pic_by;
}
catch(Exception pic_e)
{
// WriteLog(DateTime.Now+"\t"+str_pz_wfbh+"\t图片合成失败"+pic_e.Message);
return null;
}
}
#endregion
}
作者: XuGang 网名:钢钢 |
出处: http://xugang.cnblogs.com |
声明: 本文版权归作者和博客园共有。转载时必须保留此段声明,且在文章页面明显位置给出原文连接地址! |