Note that there are some explanatory texts on larger screens.

plurals
  1. POBitmap.Save "Generic Error"
    primarykey
    data
    text
    <p>When I run my application the following error get's thrown in my face "A generic error occurred in GDI+." I've looked around and seen people have similar errors, but have found no real solution, or it is a real pain in the butt to implement. And those that have not gotten a solution have not posted their code.</p> <p>So I thought I might as well give it a shot and throw another thread up about how to fix this error. This is my Code &amp; Error</p> <pre><code> Random r = new Random(); DirectoryInfo di = new DirectoryInfo(folderbrowser.SelectedPath); FileInfo[] fi = di.GetFiles().Where(f =&gt; extensions.Contains(f.Extension.ToLower())).ToArray(); for (int i = 0; i &lt; imageCount; i++) { int img1 = r.Next(imageCount); int img2 = r.Next(imageCount); while (img2 == img1) img2 = r.Next(imageCount); pic1.Image = Image.FromFile(fi[img1].FullName); pic2.Image = Image.FromFile(fi[img2].FullName); Image i1 = pic1.Image; Image i2 = pic2.Image; Bitmap bitmap = new Bitmap(i1.Width + i2.Width, 1080); using (Graphics g = Graphics.FromImage(bitmap)) { g.DrawImage(i1, 0, 0); g.DrawImage(i2, i2.Width, 0); } bitmap.Save(@"C:\TEST\Image_"+i.ToString()); } </code></pre> <p>And here's the Error code</p> <pre><code>System.Runtime.InteropServices.ExternalException was unhandled Message=A generic error occurred in GDI+. Source=System.Drawing ErrorCode=-2147467259 StackTrace: at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) at System.Drawing.Image.Save(String filename, ImageFormat format) at System.Drawing.Image.Save(String filename) at WallpaperMerger.Form1.btn_merge_Click(Object sender, EventArgs e) in C:\Users\PeppeJ\documents\visual studio 2010\Projects\WallpaperMerger\WallpaperMerger\Form1.cs:line 113 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message&amp; m) at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m) at System.Windows.Forms.Button.WndProc(Message&amp; m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at WallpaperMerger.Program.Main() in C:\Users\PeppeJ\documents\visual studio 2010\Projects\WallpaperMerger\WallpaperMerger\Program.cs:line 18 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: </code></pre> <p>So what do you guys here at StackOverflow think. Am I the same boat as the others and have to type a ridiculously complex code to solve this problem, or have I made a simple mistake and it's easy to correct?</p> <p>If you want to test it yourself if that might somehow help, here's a link to the <a href="https://dl.dropbox.com/u/14970061/WallpaperMerger.exe" rel="nofollow">Debug Build</a></p> <p>Simply tick "Use Multiple Files", select a folder containing image files (C:\Users\Public\Pictures\Sample Pictures) for instance. Hit Merge.</p> <p>I'd like to add that I use Bitmap.Save in this function, and it works flawlessly.</p> <pre><code> Bitmap bitmap = new Bitmap(pic1.Image.Width + pic2.Image.Width, 1080); using (Graphics g = Graphics.FromImage(bitmap)) { g.DrawImage(pic1.Image, 0, 0); g.DrawImage(pic2.Image, pic1.Image.Width, 0); } if (savepicfile.ShowDialog() == DialogResult.OK) bitmap.Save(savepicfile.FileName); </code></pre> <p>In the above function files are loaded like this:</p> <pre><code> DialogResult result = pic1file.ShowDialog(); if (result == DialogResult.OK) pic1.Image = Image.FromFile(pic1file.FileName); </code></pre> <p>Something else worth mentioning is that "picX" is a "System.Windows.Forms.PictureBox" object.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload