Error in saving Image-A generic error occurred in GDI+. http://forums.asp.net/t/1273771.aspx/1?Error+in+saving+Image+A+generic+error+occurred+in+GDI+Mon, 26 Jul 2010 11:41:03 -040012737712415411http://forums.asp.net/p/1273771/2415411.aspx/1?Error+in+saving+Image+A+generic+error+occurred+in+GDI+Error in saving Image-A generic error occurred in GDI+. <p>hi all,</p> <p>Im saving a barcode in server.mappath.But its giving an error as <strong>A generic error occurred in GDI&#43;.</strong> Im trying to save it as Bmp format.</p> <p>Can anyone say why this error has come?</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ms2 As MemoryStream = New MemoryStream<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imgBarcode.Save(ms2, System.Drawing.Imaging.ImageFormat.Bmp)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim arr2(ms2.Length) As Byte<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ms2.Write(arr2, 0, arr2.Length)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imgBarcode.Save(Server.MapPath(&quot;~\Barcode\Data\&quot;) &amp; all &amp; &quot;.bmp&quot;, System.Drawing.Imaging.ImageFormat.Bmp)&nbsp; <strong>//Error is here.Cant Save Image</strong></p> &nbsp; 2008-06-11T07:59:49-04:002415547http://forums.asp.net/p/1273771/2415547.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Hi all,</p> <p>Check&nbsp; write permission&nbsp;of the folder you are trying to write your image&nbsp;on it.</p> <p>I hope this helps.</p> 2008-06-11T08:54:01-04:002415577http://forums.asp.net/p/1273771/2415577.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Everything is correct.The thing is that i cant save the image in folder. Wen it reaches the statement, </p> <p>it goes straight to catch message and displays the error.</p> <p>&nbsp;</p> 2008-06-11T09:04:11-04:002415774http://forums.asp.net/p/1273771/2415774.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Hi Jeen,</p> <p>I think the problem is one of two things:</p> <p>&nbsp;&nbsp; 1-try to remove the &quot;~\&quot; before the Barcode\Data and use Server.MapPath(&quot;Barcode/Data&quot;).</p> <p>&nbsp;&nbsp; 2- I had the same error and was&nbsp;because of&nbsp;write permission not&nbsp;allowed&nbsp;and i solved it by:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a. if you are using server add everyone user to folder users and set its permission to read and write.</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b. if you are using local machine make the folder shared and&nbsp;allow everyone user&nbsp;can change it.</p> <p>Best regards.</p> <p>Bilal</p> 2008-06-11T10:32:17-04:002415795http://forums.asp.net/p/1273771/2415795.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>I removed the &quot;~&quot; symbol. There wont be any permission problem because im using 2 folders to display the image. the first folder works fine. the problem is with this folder only.I had made like this.</p> <font color="#0000ff" size="2">Dim</font><font size="2"> imgBarcode </font><font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea)</font><font size="2"> <p>imgBarcode.Save(Server.MapPath(&quot;Barcode\Datamatrix\&quot;) &amp; all &amp; &quot;.bmp&quot;, System.Drawing.Imaging.ImageFormat.Bmp)</p> <p>imgBarcode.Dispose()</p> </font> 2008-06-11T10:40:59-04:002415909http://forums.asp.net/p/1273771/2415909.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Here is where i have the problem </p> <p>imgBarcode.Save(Server.MapPath(&quot;Barcode\Datamatrix\&quot;) &amp; all &amp; &quot;.bmp&quot;, System.Drawing.Imaging.ImageFormat.Bmp) </p> <p>I cant save. I got the error as here. Else everything is fine</p> 2008-06-11T11:28:27-04:002420879http://forums.asp.net/p/1273771/2420879.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>&nbsp;Hi there,</p> <p>I got the same error but just fixed.</p> <p>Check the permission again. <br> </p> <p>The file going to write is already opened by some script or it's not closed properly. (very possible if you are trying to reuse the same file name)<br> </p> <p>Hope this help.<br> </p> 2008-06-13T06:13:22-04:002421244http://forums.asp.net/p/1273771/2421244.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>try to change your fileformat.. some time.. few properties and settings&nbsp;don't work with certain fileformat.</p> 2008-06-13T09:30:09-04:002425022http://forums.asp.net/p/1273771/2425022.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Actually im saving another bmp image in another folder, it works good.The problem is in this only.Pls help.Im working with this for last 4-5 days...</p> <pre class="prettyprint">Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp.Code = all bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.DataMatrix bcp.BarHeight = 1.0F bcp.BarWidth = 0.01F bcp.DisplayCode = True Dim dpi As Single = 300.0F Dim targetArea As New System.Drawing.SizeF(1.0F, 0.5F) Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea) bcp.Font.Bold = True 'Add the Barcode control PlaceHolder1.Controls.Add(bcp) Dim ms As MemoryStream = New MemoryStream Dim bm As Bitmap = New Bitmap(imgBarcode) bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp) Dim arr(ms.Length) As Byte ms.Write(arr, 0, arr.Length) imgBarcode.Save(Server.MapPath(&quot;\Barcode\Matrix\&quot;) &amp; all &amp; &quot;.bmp&quot;, System.Drawing.Imaging.ImageFormat.Bmp) <strong>//Here is the problem.</strong></pre>&nbsp; 2008-06-16T07:34:17-04:002427427http://forums.asp.net/p/1273771/2427427.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Hi jeen,</p> <p>I tryed your code and discovered what was causing the error,it is&nbsp;when using Server.MapPath(&quot;\Barcode\Matrix\&quot;) it takes you to the wrong folder.</p> <p>Just use Server.MapPath(&quot;Barcode\Matrix\&quot;) without&nbsp;\&nbsp; or / before the Barcode,</p> <p>this is the code i used:</p> <font color="#0000ff" size="2"> <p>Dim</font><font size="2"> imgBarcode </font><font color="#0000ff" size="2">As</font><font size="2"> System.Drawing.Image = Image.FromFile(Server.MapPath(</font><font color="#800000" size="2">&quot;&quot;</font><font size="2">) &amp; </font><font color="#800000" size="2">&quot;\img.png&quot;</font><font size="2">) </font><font color="#008000" size="2">'bcp.GetBarcodeImage(dpi, targetArea)</p> </font><font size="2"> <p></font><font color="#008000" size="2">'bcp.Font.Bold = True</p> </font><font size="2"> <p></font><font color="#008000" size="2">'Add the Barcode control</p> </font><font size="2"> <p></font><font color="#008000" size="2">'PlaceHolder1.Controls.Add(bcp)</p> </font><font size="2"></font><font color="#0000ff" size="2">Dim</font><font size="2"> ms </font><font color="#0000ff" size="2">As</font><font size="2"> MemoryStream = </font> <font color="#0000ff" size="2">New</font><font size="2"> MemoryStream</font><font size="2"></font><font color="#0000ff" size="2">Dim</font><font size="2"> bm </font><font color="#0000ff" size="2">As</font><font size="2"> Bitmap = </font><font color="#0000ff" size="2">New</font><font size="2"> Bitmap(imgBarcode)</font><font size="2"> <p>bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)</p> <p></font><font color="#0000ff" size="2">Dim</font><font size="2"> arr(ms.Length) </font><font color="#0000ff" size="2">As</font><font size="2"> </font><font color="#0000ff" size="2">Byte</p> </font><font size="2"> <p>ms.Write(arr, 0, arr.Length)</p> <p>imgBarcode.Save(Server.MapPath(</font><font color="#800000" size="2">&quot;imagesww/m&quot;</font><font size="2">) &amp; </font><font color="#800000" size="2">&quot;\newImg.bmp&quot;</font><font size="2">, System.Drawing.Imaging.ImageFormat.Bmp) </font><font color="#008000" size="2">' not error </p> </font><font size="2"> <p>imgBarcode.Save(Server.MapPath(</font><font color="#800000" size="2">&quot;/imagesww/m&quot;</font><font size="2">) &amp; </font><font color="#800000" size="2">&quot;\newImg.bmp&quot;</font><font size="2">, System.Drawing.Imaging.ImageFormat.Bmp) </font><font color="#008000" size="2">' causes error</p> </font><font size="2"> <p>imgBarcode.Dispose()</p> <p>----------------------------------</font>&nbsp;</p> <p>Trace the your code and make sure the you are saving the image in the right place.</p> <p>Best Regards,</p> <p>Bilal.</p> 2008-06-17T07:27:15-04:002678397http://forums.asp.net/p/1273771/2678397.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>&nbsp;Hi </p> <p>&nbsp;I got the same error on this line&nbsp;</p> <p>newBmp.Save(Server.MapPath(filePath), Imaging.ImageFormat.Png)</p> <p>let anyone give solution it works locally fine but , when i work it on live&nbsp;</p> <p>it shows generic error?? <br> </p> 2008-10-13T06:22:05-04:003963090http://forums.asp.net/p/1273771/3963090.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Hello Friends,</p> <p>as me was blocked on the same issue from last 3-4 days n tried a lot of different attempts for the same but not a single one turned out to be successful.<br> But finally today i got the solution.</p> <p><b>After making it double sure that all the permissions are set to WRITE.</b></p> <p><br> USE string filepath = Server.MapPath(&quot;./Images/&quot;);<br> instead of <br> string filepath = Server.MapPath(&quot;~//Images//&quot;);<br> <br> the main issue was while mapping a virtual path<br> it starts the path from site folder<br> so&nbsp; we need to map with &quot;<b>.</b>&quot; instead of &quot;<b>~</b>&quot;<br> <br> I have tried the same solution on 3 different projects for the same problem.<br> all of them started working very smoothly.<br> All the best.....&nbsp; :)</p> 2010-07-08T10:21:19-04:003967911http://forums.asp.net/p/1273771/3967911.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>rohitmahadik</h4> USE string filepath = Server.MapPath(&quot;./Images/&quot;);<br> instead of <br> string filepath = Server.MapPath(&quot;~//Images//&quot;);</blockquote> &nbsp; <p></p> <p>Yes it should be ~ it will resolve the url.. of the image from the images folder..</p> 2010-07-12T04:32:08-04:003992291http://forums.asp.net/p/1273771/3992291.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Hi <strong>jeenajos</strong><strong>,</strong></p> <p>Please check the link below regarding the issue which you illustrate:</p> <p><a title="http://www.anujtripathi.net/BlogListing.aspx?Id=6" href="http://www.anujtripathi.net/BlogListing.aspx?Id=6" target="_blank">&nbsp;A generic error occured in GDI&#43;</a></p> <p>Hope this will help you.</p> <p>Thanks</p> 2010-07-26T11:03:44-04:003992357http://forums.asp.net/p/1273771/3992357.aspx/1?Re+Error+in+saving+Image+A+generic+error+occurred+in+GDI+Re: Error in saving Image-A generic error occurred in GDI+. <p>Anju,</p> <p>Nice ellaborated answer. really too much helpful....</p> <p>Thanks<br> </p> 2010-07-26T11:41:03-04:00