XuGang

记录一个程序员的成长

 

图片合成的方法


#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
}

posted on 2008-03-08 15:45  钢钢  阅读(1517)  评论(1编辑  收藏  举报

导航