合并图像保存的问题 [英] A problem of merging images saving

查看:71
本文介绍了合并图像保存的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void MergeImages(string ImageBack,string ImageFore)
		{
                       try
             {
                 string outputFile = Path.GetFileName(tbxImageName.Text.Trim());
                 string fullFile = Path.GetFullPath(tbxImageName.Text);
                 string backFile = Path.GetFileName(tbxBackImage.Text.Trim());
                 string fullBack = Path.GetFullPath(tbxBackImage.Text);
                  System.Drawing.Graphics myGraphic = null;
                 Image imgB;
		  imgB = Image.FromFile(ImageBack);
                 FileInfo fileInfoBack = new FileInfo(ImageBack);
                 FileInfo fileInfoForward=new FileInfo(ImageFore);
                 string aa= Path.GetFullPath(tbxImageName.Text);
                 Image imgF;
		 imgF = Image.FromFile(ImageFore);
                Image m;
                m = Image.FromFile(ImageBack);
                myGraphic = System.Drawing.Graphics.FromImage(m);
			    myGraphic.DrawImageUnscaled(imgB,0,0);
			    myGraphic.DrawImageUnscaled(imgF,posX,posY);

                myGraphic.Save();
               int opnselctn = openFileDialog2.FilterIndex;
			    switch(opnselctn)
                {
                   case 1:
                       m.Save(ImageBack.Replace(fullBack, fullFile), System.Drawing.Imaging.ImageFormat.Jpeg);
                     break;
                  case 2:
                      m.Save(ImageBack.Replace(fullBack, fullFile), System.Drawing.Imaging.ImageFormat.Bmp);
                     break;
                  case 3:
                      m.Save(ImageBack.Replace(fullBack, fullFile), System.Drawing.Imaging.ImageFormat.Gif);
                    break;
                  case 4:
                    m.Save(ImageBack.Replace(fullBack, fullFile), System.Drawing.Imaging.ImageFormat.Png);
                    break;
                   }
                   imgB.Dispose();
                   imgF.Dispose();
                 m.Dispose();
           }
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}


首先,我通过提供2个图像输入和x,y位置来合并2个图像.然后合并图像显示.再次,如果我想合并先前的图像和新的x,y位置并从先前的保存名称保存图像,则会出现问题.
"A generic error occurred in GDI+"
我的合并方法如上所示.我的麻烦的原因是什么?


1stly I merge 2 images by giving 2 images input and x,y position. Then merge image display. Again, if i want to merge the both previous images and the new x,y positions and save the image from previous saving name there is occurred an issue.
It is "A generic error occurred in GDI+"
My merge method is shown in above. What''s reason for my trouble???

推荐答案

遇到此问题时,总是因为我试图保存文件在不存在的文件夹中.

例子:

When I have come across this problem, it has always been because I''ve tried to save a file in a folder that doesn''t exist.

An example:

image.Save(@"c:\Documents\Test\Test.bmp",...)



如果文件夹"C:\ Documents"或"C:\ Documents \ Test"不存在,则会失败并显示"GDI +中发生一般错误".

验证您要写入的完整路径是否存在.您不妨先验证字符串替换是否按预期工作.



This fails with ''A generic error occurred in GDI+'' if the folders ''C:\Documents'' or ''C:\Documents\Test'' do not exist.

Verify the complete path you are trying to write to exists. You may wish to start by verifying that your string replacements are working as you expect.


这篇关于合并图像保存的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆