Im saving a barcode in server.mappath.But its giving an error as A generic error occurred in GDI+. Im trying to save it as Bmp format.
Can anyone say why this error has come?
Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea)
Dim ms2 As MemoryStream = New MemoryStream
imgBarcode.Save(ms2, System.Drawing.Imaging.ImageFormat.Bmp)
Dim arr2(ms2.Length) As Byte
ms2.Write(arr2, 0, arr2.Length)
imgBarcode.Save(Server.MapPath("~\Barcode\Data\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
//Error is here.Cant Save Image
I removed the "~" 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.
Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea)
imgBarcode.Save(Server.MapPath("Barcode\Datamatrix\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
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...
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("\Barcode\Matrix\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp) //Here is the problem.
I tryed your code and discovered what was causing the error,it is when using Server.MapPath("\Barcode\Matrix\") it takes you to the wrong folder.
Just use Server.MapPath("Barcode\Matrix\") without \ or / before the Barcode,
this is the code i used:
Dim
imgBarcode As System.Drawing.Image = Image.FromFile(Server.MapPath("") &
"\img.png") 'bcp.GetBarcodeImage(dpi, targetArea)
'bcp.Font.Bold = True
'Add the Barcode control
'PlaceHolder1.Controls.Add(bcp)
Dim ms
As MemoryStream =
New MemoryStreamDim bm
As Bitmap = New Bitmap(imgBarcode)
jeenajos
Member
34 Points
141 Posts
Error in saving Image-A generic error occurred in GDI+.
Jun 11, 2008 07:59 AM|LINK
hi all,
Im saving a barcode in server.mappath.But its giving an error as A generic error occurred in GDI+. Im trying to save it as Bmp format.
Can anyone say why this error has come?
Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea)
Dim ms2 As MemoryStream = New MemoryStream
imgBarcode.Save(ms2, System.Drawing.Imaging.ImageFormat.Bmp)
Dim arr2(ms2.Length) As Byte
ms2.Write(arr2, 0, arr2.Length)
imgBarcode.Save(Server.MapPath("~\Barcode\Data\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp) //Error is here.Cant Save Image
GDI+
Jeen
Bilal_Salih
Member
144 Points
34 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 11, 2008 08:54 AM|LINK
Hi all,
Check write permission of the folder you are trying to write your image on it.
I hope this helps.
jeenajos
Member
34 Points
141 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 11, 2008 09:04 AM|LINK
Everything is correct.The thing is that i cant save the image in folder. Wen it reaches the statement,
it goes straight to catch message and displays the error.
Jeen
Bilal_Salih
Member
144 Points
34 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 11, 2008 10:32 AM|LINK
Hi Jeen,
I think the problem is one of two things:
1-try to remove the "~\" before the Barcode\Data and use Server.MapPath("Barcode/Data").
2- I had the same error and was because of write permission not allowed and i solved it by:
a. if you are using server add everyone user to folder users and set its permission to read and write.
b. if you are using local machine make the folder shared and allow everyone user can change it.
Best regards.
Bilal
jeenajos
Member
34 Points
141 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 11, 2008 10:40 AM|LINK
I removed the "~" 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.
Dim imgBarcode As System.Drawing.Image = bcp.GetBarcodeImage(dpi, targetArea)imgBarcode.Save(Server.MapPath("Barcode\Datamatrix\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
imgBarcode.Dispose()
Jeen
jeenajos
Member
34 Points
141 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 11, 2008 11:28 AM|LINK
Here is where i have the problem
imgBarcode.Save(Server.MapPath("Barcode\Datamatrix\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
I cant save. I got the error as here. Else everything is fine
Jeen
onion
Member
60 Points
10 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 13, 2008 06:13 AM|LINK
Hi there,
I got the same error but just fixed.
Check the permission again.
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)
Hope this help.
blurearc
Contributor
3710 Points
692 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 13, 2008 09:30 AM|LINK
try to change your fileformat.. some time.. few properties and settings don't work with certain fileformat.
"There are NO shortcuts for success, better stop taking one."
Ravi Kant Srivastava
jeenajos
Member
34 Points
141 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 16, 2008 07:34 AM|LINK
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...
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("\Barcode\Matrix\") & all & ".bmp", System.Drawing.Imaging.ImageFormat.Bmp) //Here is the problem.Jeen
Bilal_Salih
Member
144 Points
34 Posts
Re: Error in saving Image-A generic error occurred in GDI+.
Jun 17, 2008 07:27 AM|LINK
Hi jeen,
I tryed your code and discovered what was causing the error,it is when using Server.MapPath("\Barcode\Matrix\") it takes you to the wrong folder.
Just use Server.MapPath("Barcode\Matrix\") without \ or / before the Barcode,
this is the code i used:
Dim
imgBarcode As System.Drawing.Image = Image.FromFile(Server.MapPath("") & "\img.png") 'bcp.GetBarcodeImage(dpi, targetArea) 'bcp.Font.Bold = True 'Add the Barcode control 'PlaceHolder1.Controls.Add(bcp) Dim ms As MemoryStream = New MemoryStreamDim bm As Bitmap = New Bitmap(imgBarcode)bm.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
Dim arr(ms.Length) As Bytems.Write(arr, 0, arr.Length)
imgBarcode.Save(Server.MapPath(
"imagesww/m") & "\newImg.bmp", System.Drawing.Imaging.ImageFormat.Bmp) ' not errorimgBarcode.Save(Server.MapPath(
"/imagesww/m") & "\newImg.bmp", System.Drawing.Imaging.ImageFormat.Bmp) ' causes errorimgBarcode.Dispose()
----------------------------------
Trace the your code and make sure the you are saving the image in the right place.
Best Regards,
Bilal.