C# 图像合成

        我已经将以下的代码测试通过,符合要求
       
首先给你一个函数;用来将图片保存到内存中  
        /// <summary>
        ///
首先给你一个函数;用来将图片保存到内存中  
        /// </summary>
        /// <param name="strPhotoPath"></param>
        /// <returns></returns>
        private Image ReturnImage(string strPhotoPath)
        {
            FileStream fstream = new FileStream(strPhotoPath, FileMode.OpenOrCreate, FileAccess.Read);
            byte[] byData = new byte[fstream.Length];
            fstream.Read(byData, 0, System.Convert.ToInt32(fstream.Length));
            fstream.Close();
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byData, true);
            stream.Write(byData, 0, byData.Length);
            Bitmap bmp = new Bitmap(stream);
            System.Drawing.Image image = bmp;
            return bmp;
        }  

        private void Form1_Load(object sender, EventArgs e)
        {
            //
下面的是进行图像合成的代码:  
            string str0 = System.IO.Directory.GetCurrentDirectory() + "//" + "
像框文件的名称";//像框文件的路径  
            string str1 = System.IO.Directory.GetCurrentDirectory() + "//" + "
照片的名称";//照片文件的全路径  
            Image img0 = ReturnImage(str0);
            Image img1 = ReturnImage(str1);
            System.Drawing.Image newImage = img0.GetThumbnailImage(
合成后图像的宽, 合成后图像的高, null, new IntPtr());
            Graphics g = Graphics.FromImage(img0);
            g.DrawImage(img0, 0, 0,
相框图片的宽, 像框图片的高);
            g.DrawImage(img1,
照片与相框左边距, 照片与相框顶边距, img1.Width, img1.Height);
            //
执行完以上的代码img0就是你要的合成图片了,你可以把它保存成一个图片文件或是做其他处理!
            this.pictureBox1.Image = img0;
        }


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值