I'm opening a JPG file to read and write its EXIF properties. I'm using very
simple code to open the file:
myBitmap = new Bitmap(filePath );
Reading and writing the properties is working fine, but when I go to save
the file, I'm getting an exception that reads "A generic error occurred in
GDI+." Here's the code I'm using to save the file back to the same name it
was opened from:
myBitmap.Save(f ilePath, ImageFormat.Jpe g);
I tried saving to a different file name, and that save works with no
problems. That suggests a file-locking problem.
Presumably, my app is putting a lock on the JPG file when I open it. How can
I release the lock, so I can write modified properties back to the file?
Thanks in advance for your help. 5 2103
Presumably, my app is putting a lock on the JPG file when I open it. How
can I release the lock, so I can write modified properties back to the
file?
Open the image using a FileStream.
"David Veeneman" <da****@nospam. comwrote in message
news:uZ******** ******@TK2MSFTN GP06.phx.gbl...
I'm opening a JPG file to read and write its EXIF properties. I'm using
very simple code to open the file:
myBitmap = new Bitmap(filePath );
Reading and writing the properties is working fine, but when I go to save
the file, I'm getting an exception that reads "A generic error occurred in
GDI+." Here's the code I'm using to save the file back to the same name it
was opened from:
myBitmap.Save(f ilePath, ImageFormat.Jpe g);
I tried saving to a different file name, and that save works with no
problems. That suggests a file-locking problem.
Presumably, my app is putting a lock on the JPG file when I open it. How
can I release the lock, so I can write modified properties back to the
file? Thanks in advance for your help.
On Oct 1, 1:48 pm, "David Veeneman" <dav...@nospam. comwrote:
I'm opening a JPG file to read and write its EXIF properties. I'm using very
simple code to open the file:
myBitmap = new Bitmap(filePath );
Reading and writing the properties is working fine, but when I go to save
the file, I'm getting an exception that reads "A generic error occurred in
GDI+." Here's the code I'm using to save the file back to the same name it
was opened from:
myBitmap.Save(f ilePath, ImageFormat.Jpe g);
I tried saving to a different file name, and that save works with no
problems. That suggests a file-locking problem.
Presumably, my app is putting a lock on the JPG file when I open it. How can
I release the lock, so I can write modified properties back to the file?
Thanks in advance for your help.
David,
Check this out: http://www.bobpowell.net/imagefileconvert.htm
-Jay
Thanks! I'm pretty sure that's where the problem lies.
For the benefit of anyone else reading this thread, GDI+ apparently keeps an
image file open so long as the Image is used, even if the file is opened
with a stream reader and the stream reader is properly closed and disposed.
The workaround is to save the image file under a different name, close and
dispose of the image, delete the original, rename the copy with the original
name, and reload the renamed copy. Kind of clunky, but it seems to work.
More details are in the Bob Powell article.
David Veeneman wrote:
Thanks! I'm pretty sure that's where the problem lies.
For the benefit of anyone else reading this thread, GDI+ apparently keeps an
image file open so long as the Image is used, even if the file is opened
with a stream reader and the stream reader is properly closed and disposed.
The workaround is to save the image file under a different name, close and
dispose of the image, delete the original, rename the copy with the original
name, and reload the renamed copy. Kind of clunky, but it seems to work.
More details are in the Bob Powell article.
For what it's worth, I have worked around similar issues by simply
copying the opened bitmap to a new Bitmap instance (one created from
scratch rather than by reading from a file), and then discarding the
original. This is different technique that also has the effect of
releasing the opened file, allowing it to be overwritten.
Personally, I think it's a simpler way to do it than dealing with
writing a second file. Not difficult, but you'll need to use something
like the Path.GetTempFil eName() and managing the extra copies of the
image seem to me to be more awkward using that technique.
Just an alternative to consider.
Pete
Thanks--that was the problem. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Erwin |
last post by:
At the moment I'm using a report which contains an indicator to show
if a Service group of the company isn't working well or is working
perfectly. This indicator is a "*" which looks like a traffic light.
Example:
When a Service groep does hit the target, the indicator will lit up
using the following Control Source:
=IIf(>0,8*10*;"*")
But now, I would like the use a real bitmap, trafficlight bitmaps, to
|
by: |
last post by:
Hello All,
I am writing a web application that reads a bitmap from a file and outputing
it to a HTTP response stream to return the image to the requesting client.
The image file is a regular bitmap file (filename.bmp)
I am experiencing some difficulties with writing a bitmap to a http response
stream.
I load the bitmap from a file. and i use the following snippet of code to
write to HTTP response stream
|
by: Joaquin Corchero |
last post by:
Hi, I have this code which it should change the EXIF file properties of
images, but there is something that doesn't work, any ideas???
Private Sub ShowBitMapProp(ByVal sFile As String)
Dim sExt = LCase(sFile).Substring(sFile.LastIndexOf("."))
If sExt = ".jpg" Or sExt = ".gif" Then
Response.Write("ShowBitMapProp<br>" & vbCrLf)
|
by: Lance |
last post by:
I need to create a Drawing.Bitmap from an array of integer
values. My current technique creates a bitmap that
eventually becomes corrupt (i.e., the bitmap's pixels
change to a different color after a while). Can somebody
please tell me what I'm doing wrong? Here is a sample:
Public Shared Function CreateBitmapFromArray( _
ByVal width As Integer, _
ByVal height As Integer, _
ByVal pixelFormat As Drawing.Imaging.PixelFormat, _
|
by: Mad Scientist Jr |
last post by:
I have a bitmap (32 pixels high, 8192 pixels wide) that contains 255
images, each 32 pixels wide, that I would like to chop up into
individual 32x32 bitmap files. Rather than spending hours in Paint or
Photoshop I would like to do this programmatically. My code below
attempts to load in the original bitmap, crop it at the desired
location, and save it to the correct file. I don't think I'm doing this
right, I tried messing with different...
| |
by: Dave Harvey |
last post by:
I have developed a standard .NET control which displays medical images and
works fine in applications, but increasingly, my customers are wishing to use
it in an ASP.NET environment, so I am looking to make a WebControl based
equivalent.
So, assuming that I need to render using HTML - how can I pass "bitmap" data
into such a control for it to be displayed. I'm open to all possible routes,
but I've not yet found one which works. Ideas...
|
by: active |
last post by:
I need to know how many colors in the color table are actually used.
Do I need to use Windows API?
I been searching the Bitmap doc and can't find a property that would help.
Is there a way other than Windows API to get that information?
|
by: raylopez99 |
last post by:
I have a minor problem locating an image file to load as a Bitmap.
A resource file "NudeSusan.jpeg" (which I think is actually a bmp
file, originally taken from a jpeg of model Susan Spears) is loaded
onto the "Resources" tree of the Visual Studio Solutions Explorer, and
correctly works. However, another file, "MyImageFile.png" (which is
also a bmp file, sorry for the confusion, but originally was a png
file), does not work.
How can...
|
by: bradyounie |
last post by:
I'm writing a program that displays a user-supplied Bitmap and then writes text fields to it. These "text fields" are things that the user can move around on the image, but to render them efficiently, I draw the text directly to the image. It's faster that way.
The problem is that right now I have to redraw the original (unwritten-to) bitmap and redraw the text whenever the user moves the text because I haven't figured out how to properly...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |