A generic error occurred in GDI+问题对应~
来源:互联网 发布:穆勒plc手动编程方法 编辑:程序博客网 时间:2024/06/06 19:55
Bitmap.save(): A generic error occurred in GDI+ Try the following code You will get the above mentioned error:A generic error occurred in GDI+.
Dim oBitmap As Bitmap
oBitmap = New Bitmap("c:/example.jpg")
Dim oGraphic As Graphics
oGraphic = Graphics.FromImage(oBitmap)
Dim oBrush As New SolidBrush(Color.Black)
Dim ofont As New Font("Arial", 8)
oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10)
oBitmap.Save("c:/example.jpg",ImageFormat.Jpeg)
oBitmap.Dispose()
oGraphic.Dispose()
oBitmap = New Bitmap("c:/example.jpg")
Dim oGraphic As Graphics
oGraphic = Graphics.FromImage(oBitmap)
Dim oBrush As New SolidBrush(Color.Black)
Dim ofont As New Font("Arial", 8)
oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10)
oBitmap.Save("c:/example.jpg",ImageFormat.Jpeg)
oBitmap.Dispose()
oGraphic.Dispose()
This problem occurs because until the bitmap object is disposed, it creates a lock on the underlying image file. So you can save the newly generated file with different name but not overwrite the file because of lock. Now suppose you want to overwrite the file then create another bitmap from old bitmap. dispose the object of old bitmap, process new bitmap object and save the new bitmap object with original file name. The above chunk of code should be written in the following way.
Dim oBitmap As Bitmap oBitmap = New Bitmap("c:/example.jpg")
Dim oGraphic As Graphics
' Here create a new bitmap object of the same height and width of the image.
Dim bmpNew As Bitmap = New Bitmap(oBitmap.Width, oBitmap.Height)
oGraphic = Graphics.FromImage(bmpNew)
oGraphic.DrawImage(oBitmap, New Rectangle(0, 0, _ bmpNew.Width, bmpNew.Height), 0, 0, oBitmap.Width, _ oBitmap.Height, GraphicsUnit.Pixel)
' Release the lock on the image file. Of course,
' image from the image file is existing in Graphics object
oBitmap.Dispose()
oBitmap = bmpNew
Dim oBrush As New SolidBrush(Color.Black)
Dim ofont As New Font("Arial", 8)
oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10)
oGraphic.Dispose()
ofont.Dispose()
oBrush.Dispose()
oBitmap.Save("c:/example.jpg", ImageFormat.Jpeg)
oBitmap.Dispose()
Dim oGraphic As Graphics
' Here create a new bitmap object of the same height and width of the image.
Dim bmpNew As Bitmap = New Bitmap(oBitmap.Width, oBitmap.Height)
oGraphic = Graphics.FromImage(bmpNew)
oGraphic.DrawImage(oBitmap, New Rectangle(0, 0, _ bmpNew.Width, bmpNew.Height), 0, 0, oBitmap.Width, _ oBitmap.Height, GraphicsUnit.Pixel)
' Release the lock on the image file. Of course,
' image from the image file is existing in Graphics object
oBitmap.Dispose()
oBitmap = bmpNew
Dim oBrush As New SolidBrush(Color.Black)
Dim ofont As New Font("Arial", 8)
oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10)
oGraphic.Dispose()
ofont.Dispose()
oBrush.Dispose()
oBitmap.Save("c:/example.jpg", ImageFormat.Jpeg)
oBitmap.Dispose()
0 0
- A generic error occurred in GDI+问题对应~
- 有关A generic error occurred in GDI+问题
- 解决A generic error occurred in GDI+的问题
- 解决A generic error occurred in GDI+的问题
- A generic error occurred in GDI+. 解决方法
- System.Drawing.Image.Save, A generic error occurred in GDI+.
- 异常A generic error occurred in GDI+的解决办法
- 图片处理报异常,A generic error occurred in GDI+
- AN ERROR OCCURRED IN A TRIGGERED SQL -723
- An error occurred when merging assemblies: ILMerge.Merge: ERROR!!: Duplicate type 'index' found in a
- IAR FOR STM8S 错误 An error occurred while retrieving GDI features: gdi-error [40201]解决方法
- IAR出现An error occurred while retrieving GDI features: gdi-error [40201]的解决方法
- A Generic - Reusable Diff Algorithm in C#.
- A Generic vector implementation in C
- Error in XmlSqlMapClientBuilder. Alias name conflict occurred.
- A configuration error occurred during startup. Please......
- ASIHTTPRequest "A connection failure occurred" error
- ASIHTTPRequest "A connection failure occurred" error
- iphone数据存储之-- Core Data的使用(二)
- JqueryEasyUI 解决IE下datagrid无法刷新的问题
- hdu 4036 - Rolling Hongshu
- KISS原则
- 嵌入式软件开发:笔试总结
- A generic error occurred in GDI+问题对应~
- DEDE采集规则过滤与替换
- iphone数据存储之--NSUserDefaults
- POJ 2763 Housewife Wind 树链剖分
- 嵌入式学习书籍大推荐
- 全文检索技术Lucene入门和学习、与数据库数据结合的demo实现
- java SAXParserFactory解析xml文件
- ARM常用汇编指令集
- My Site Clean Up Job介绍