Image.SetPropertyItem does not work

P

peter

I want to use Item.SetPropertyItem to save property changes. I found an
microsoft example at
http://msdn.microsoft.com/en-us/library/system.drawing.image.getpropertyitem(VS.80).aspx

I copy as following, and I modified the jpg files to my files and change the
property id to 40092, that is Comments of JPG property.

The code does not work. Could anybody tell me what is the problem or how can
I save property's values?

private void DemonstratePropertyItem(PaintEventArgs e)
{

// Create two images.
Image image1 = Image.FromFile("c:\\MyPhoto1.jpg");
Image image2 = Image.FromFile("c:\\MyPhoto2.jpg");

// Get a PropertyItem from image1.
PropertyItem propItem = image1.GetPropertyItem(40092);

// Change the ID of the PropertyItem.
propItem.Id = 40092;

// Set the PropertyItem for image2.
image2.SetPropertyItem(propItem);

// Draw the image.
e.Graphics.DrawImage(image2, 20.0F, 20.0F);
}
 
F

Family Tree Mike

peter said:
I want to use Item.SetPropertyItem to save property changes. I found an
microsoft example at
http://msdn.microsoft.com/en-us/library/system.drawing.image.getpropertyitem(VS.80).aspx

I copy as following, and I modified the jpg files to my files and change the
property id to 40092, that is Comments of JPG property.

The code does not work. Could anybody tell me what is the problem or how can
I save property's values?

private void DemonstratePropertyItem(PaintEventArgs e)
{

// Create two images.
Image image1 = Image.FromFile("c:\\MyPhoto1.jpg");
Image image2 = Image.FromFile("c:\\MyPhoto2.jpg");

// Get a PropertyItem from image1.
PropertyItem propItem = image1.GetPropertyItem(40092);

// Change the ID of the PropertyItem.
propItem.Id = 40092;

// Set the PropertyItem for image2.
image2.SetPropertyItem(propItem);

// Draw the image.
e.Graphics.DrawImage(image2, 20.0F, 20.0F);
}

Your code example does not actually save image2 back to disk after
modifying the comments. Put image2.Save("somefilename.jpg") in the code
after making the change to the comments.
 
P

peter

Hi Mike,

Thank u first.

I add the

image2.Save("D:\\PeterTemp\\pic\\d2.jpg");

in the code, but it cause an error message: A generic error occurred in
GDI+. and the comments was not saved.

code is copied below.

private void Form1_Paint(object sender, PaintEventArgs e)

{

ExtractMetaData(e);

// Create two images.

Image image1 = Image.FromFile("D:\\PeterTemp\\pic\\d1.jpg");

Image image2 = Image.FromFile("D:\\PeterTemp\\pic\\d2.jpg");

// Get a PropertyItem from image1.

PropertyItem propItem = image1.GetPropertyItem(40092);

// Change the ID of the PropertyItem.

//propItem.Id = 40092;

// Set the PropertyItem for image2.

image2.SetPropertyItem(propItem);

image2.Save("D:\\PeterTemp\\pic\\d2.jpg");

// Draw the image.

//e.Graphics.DrawImage(image2, 20.0F, 20.0F);

}
 
P

Peter Duniho

Hi Mike,

Thank u first.

I add the

image2.Save("D:\\PeterTemp\\pic\\d2.jpg");

in the code, but it cause an error message: A generic error occurred in
GDI+. and the comments was not saved.

I can't speak for the specific example, but I commonly run into all sorts
of problems with generic GDI+ errors when I try to do sophisticated things
with images. GDI+ is very limited in what it can handle, and usually when
you get one of these uninformative generic errors, it just means you've
asked GDI+ to do something that hasn't been implemented in it.

In your example, you appear to be trying to change the EXIF "Description"
tag's property value. I don't recall whether I've ever tried to modify
that particular property in a JPEG file before, but it may well be that
GDI+ simply just doesn't support that particular tag.

Pete
 
F

Family Tree Mike

peter said:
Hi Mike,

Thank u first.

I add the

image2.Save("D:\\PeterTemp\\pic\\d2.jpg");

in the code, but it cause an error message: A generic error occurred in
GDI+. and the comments was not saved.

code is copied below.

private void Form1_Paint(object sender, PaintEventArgs e)

{

ExtractMetaData(e);

// Create two images.

Image image1 = Image.FromFile("D:\\PeterTemp\\pic\\d1.jpg");

Image image2 = Image.FromFile("D:\\PeterTemp\\pic\\d2.jpg");

// Get a PropertyItem from image1.

PropertyItem propItem = image1.GetPropertyItem(40092);

// Change the ID of the PropertyItem.

//propItem.Id = 40092;

// Set the PropertyItem for image2.

image2.SetPropertyItem(propItem);

image2.Save("D:\\PeterTemp\\pic\\d2.jpg");

// Draw the image.

//e.Graphics.DrawImage(image2, 20.0F, 20.0F);

}


I yield to Pete on the GDI+ (and most other!) issues.

Are you sure you know where the error occurs? You added a new method
(ExtractMetaData(e)) which would appear to work with the PaintEventArgs.
You also moved this into a paint handler. Changing image properties
in a paint handler is not a normal place. I would try and narrow down
where the error actually happens.
 
P

peter

Family Tree Mike said:
I yield to Pete on the GDI+ (and most other!) issues.

Are you sure you know where the error occurs? You added a new method
(ExtractMetaData(e)) which would appear to work with the PaintEventArgs.
You also moved this into a paint handler. Changing image properties in a
paint handler is not a normal place. I would try and narrow down where
the error actually happens.


The ExtractMetaData(e) was copied from MSDN, it just display the Id, type of
properties. I removed the function anyway.

The error : A generic error occurred in GDI+. was positively from
image2.Save("D:\\PeterTemp\\pic\\d2.jpg"); Because I put a breakpoint on it.

Thanks

Peter
 
K

kndg

peter said:
The ExtractMetaData(e) was copied from MSDN, it just display the Id, type of
properties. I removed the function anyway.

The error : A generic error occurred in GDI+. was positively from
image2.Save("D:\\PeterTemp\\pic\\d2.jpg"); Because I put a breakpoint on it.

Thanks

Peter

Hi Peter,

I did try the MSDN example and it work flawlessly.
The problem you are having is due to the file "d2.jpg" is being locked
by the GDI+ and cause the saving operation to fail.
One solution is to create another folder in "pic" folder and save the
updated image to that folder.

image2.Save("D:\\PeterTemp\\pic\\output\\d2.jpg")

Regards.
 
P

peter

kndg said:
Hi Peter,

I did try the MSDN example and it work flawlessly.
The problem you are having is due to the file "d2.jpg" is being locked by
the GDI+ and cause the saving operation to fail.
One solution is to create another folder in "pic" folder and save the
updated image to that folder.

image2.Save("D:\\PeterTemp\\pic\\output\\d2.jpg")

Regards.


Hi,

Thanks very much!!!

d2.jpg was downloaded from a web site. I saved it to somewhere else it still
not working.
Rather than use d2.jpg, I use MyPic.jpg that comes from my camera, then if I
save it to somewhere else, it worked!

So, the question is how can I let the picture not locked by GDI+, so that I
don't have to save the picture to other location?

Second question is why the picture from internet cannot be modified?
 
P

Peter Duniho

d2.jpg was downloaded from a web site. I saved it to somewhere else it
still
not working.
Rather than use d2.jpg, I use MyPic.jpg that comes from my camera, then
if I
save it to somewhere else, it worked!

So, the question is how can I let the picture not locked by GDI+, so
that I
don't have to save the picture to other location?

You can release the lock by creating a duplicate of the image you loaded
from the file and then disposing the original.

My apologies for not noticing the identical load and save filenames; I
should have caught that as a potential problem.
Second question is why the picture from internet cannot be modified?

Can you please clarify? From your post, it sounds like you have a file
that even if you don't try to overwrite the original, still cannot be
saved. Is that correct? Do you get the exact same error you got when you
try to write over a locked file? Can you provide a concise-but-complete
code example, along with a link to download the specific image file?

Pete
 
K

kndg

[...]
d2.jpg was downloaded from a web site. I saved it to somewhere else it still
not working.
Rather than use d2.jpg, I use MyPic.jpg that comes from my camera, then if I
save it to somewhere else, it worked!

So, the question is how can I let the picture not locked by GDI+, so that I
don't have to save the picture to other location?

By releasing the lock. :)
Actually, it is not easy and require some works.

One way is by putting some indirection to the original file.
Example,

string filename1 = "D:\\PeterTemp\\pic\\d1.jpg";
string filename2 = "D:\\PeterTemp\\pic\\d2.jpg";

FileStream fileStream = new FileStream(filename2, FileMode.Open);
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0 , buffer.Length);
fileStream.Dispose(); // release the lock

MemoryStream memoryStream = new MemoryStream(buffer);
Image image1 = Image.FromFile(filename1);
Image image2 = Image.FromStream(memoryStream);

PropertyItem propItem = image1.GetPropertyItem(40092);
propItem.Id = 40092;
image2.SetPropertyItem(propItem);
image2.Save(filename2);

Another is by actually re-draw the original image.

Image image1 = Image.FromFile(filename1);
Image image2 = Image.FromFile(filename2);
Image image3 = new Bitmap(image2.Width, image2.Height);

Graphics g = Graphics.FromImage(image3);
g.DrawImage(image2, 0, 0);

PropertyItem[] metadatas = image2.PropertyItems;

foreach(var metadata in metadatas)
{
image3.SetPropertyItem(metadata);
}

PropertyItem property = image1.GetPropertyItem(40092);
property.Id = 40092;

image2.Dispose(); // release the lock

image3.SetPropertyItem(property);
image3.Save(filename2, ImageFormat.Jpeg);

But, take note that the above two methods will put some pressure on your
system if the image file is very large. Memory is expensive while disk
space is not. You have to weight the options.

Regards.
 
P

Peter Duniho

[...]
Another is by actually re-draw the original image.

Image image1 = Image.FromFile(filename1);
Image image2 = Image.FromFile(filename2);
Image image3 = new Bitmap(image2.Width, image2.Height);

Graphics g = Graphics.FromImage(image3);
g.DrawImage(image2, 0, 0);

First, if you're going to do the above, you need to remember to dispose
the Graphics instance. Second, if you're just duplicating the image
exactly, there's no need to get a Graphics instance in the first place.
Just use the Bitmap constructor that takes an Image as an argument, and
..NET will do the copying for you automatically (added bonus: no Graphics
instance at all, never mind one you need to dispose :) ).
PropertyItem[] metadatas = image2.PropertyItems;

foreach(var metadata in metadatas)
{
image3.SetPropertyItem(metadata);
}

PropertyItem property = image1.GetPropertyItem(40092);
property.Id = 40092;

image2.Dispose(); // release the lock

image3.SetPropertyItem(property);
image3.Save(filename2, ImageFormat.Jpeg);

But, take note that the above two methods will put some pressure on your
system if the image file is very large. Memory is expensive while disk
space is not. You have to weight the options.

The memory/disk space disparity is somewhat of a fallacy, and especially
on a 64-bit OS (which is becoming more and more common). As long as one
is not approaching the limits of the process's virtual address space (as
is often the case even on 32-bit Windows, and this is especially true when
dealing with image files, as they aren't usually large enough to put
pressure on the available address space, at least not on their own),
available memory and available disk space are basically the same thing.

Now, all that said...there's no need to copy the bitmap in order to avoid
the locked file. I suggested that earlier because it's the easiest
approach. But if one is really concerned about memory usage, then neither
of the methods suggested here (copying the file contents into a
MemoryStream, or copying the image itself) are appropriate. Instead, one
should simply open the file directly, using a FileStream constructor
overload that allows specification of the FileShare.ReadWrite value, so
that the file is not actually locked in the first place. For example:

string strFilename = ...;
FileStream stream = new FileStream(strFilename, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);

using (Image imgOriginal = Image.FromStream(stream))
{
// do stuff to image here

imgOriginal.Save(strFilename);
}

That way you only ever have one copy of the file in memory.

Pete
 
P

Peter Duniho

[...] For example:

string strFilename = ...;
FileStream stream = new FileStream(strFilename, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);

using (Image imgOriginal = Image.FromStream(stream))
{
// do stuff to image here

imgOriginal.Save(strFilename);
}

That way you only ever have one copy of the file in memory.

And of course, don't forget to dispose the FileStream too, once you're
really done with it (I failed to show that in the little snippet above).
 
K

kndg

Peter said:
[...]
Another is by actually re-draw the original image.

Image image1 = Image.FromFile(filename1);
Image image2 = Image.FromFile(filename2);
Image image3 = new Bitmap(image2.Width, image2.Height);

Graphics g = Graphics.FromImage(image3);
g.DrawImage(image2, 0, 0);

First, if you're going to do the above, you need to remember to dispose
the Graphics instance. Second, if you're just duplicating the image
exactly, there's no need to get a Graphics instance in the first place.
Just use the Bitmap constructor that takes an Image as an argument, and
..NET will do the copying for you automatically (added bonus: no
Graphics instance at all, never mind one you need to dispose :) ).

Hi Pete,

I had tried this before, but it will throw GDI+ exception

Image image3 = new Bitmap(image2);
....
image3.Save(filename2, ImageFormat.Jpeg);

I also had tried Image.Clone(), but no go.
PropertyItem[] metadatas = image2.PropertyItems;

foreach(var metadata in metadatas)
{
image3.SetPropertyItem(metadata);
}

PropertyItem property = image1.GetPropertyItem(40092);
property.Id = 40092;

image2.Dispose(); // release the lock

image3.SetPropertyItem(property);
image3.Save(filename2, ImageFormat.Jpeg);

But, take note that the above two methods will put some pressure on
your system if the image file is very large. Memory is expensive
while disk space is not. You have to weight the options.

[...]

Now, all that said...there's no need to copy the bitmap in order to
avoid the locked file. I suggested that earlier because it's the
easiest approach. But if one is really concerned about memory usage,
then neither of the methods suggested here (copying the file contents
into a MemoryStream, or copying the image itself) are appropriate.
Instead, one should simply open the file directly, using a FileStream
constructor overload that allows specification of the
FileShare.ReadWrite value, so that the file is not actually locked in
the first place. For example:

string strFilename = ...;
FileStream stream = new FileStream(strFilename, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite);

using (Image imgOriginal = Image.FromStream(stream))
{
// do stuff to image here

imgOriginal.Save(strFilename);
}

That way you only ever have one copy of the file in memory.

This is my first take, but the strange thing is the GDI+ keeps the file
locked. Here is my code.

string filename1 = "D:\\Temp\\output1.jpg";
string filename2 = "D:\\Temp\\output2.jpg";

Image image1 = Image.FromFile(filename1);

using (FileStream stream = new FileStream(filename2, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite))
{
using (Image image2 = Image.FromStream(stream))
{
PropertyItem property = image1.GetPropertyItem(271);
property.Id = 40092;
image2.SetPropertyItem(property);

image2.Save(filename2);
}
}

Am I missing something?

Regards,
 
P

Peter Duniho

[...] Just use the Bitmap constructor that takes an Image as an
argument, and ..NET will do the copying for you automatically (added
bonus: no Graphics instance at all, never mind one you need to dispose
:) ).

Hi Pete,

I had tried this before, but it will throw GDI+ exception

Image image3 = new Bitmap(image2);
...
image3.Save(filename2, ImageFormat.Jpeg);

Did you dispose "image2" before trying to save over its file?

I've used that exact technique before, so I know it works in the general
case. If you're seeing an exception, either you've left something out, or
there's something unique about your specific scenario.
[...]
This is my first take, but the strange thing is the GDI+ keeps the file
locked. Here is my code.

string filename1 = "D:\\Temp\\output1.jpg";
string filename2 = "D:\\Temp\\output2.jpg";

Image image1 = Image.FromFile(filename1);

using (FileStream stream = new FileStream(filename2, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite))
{
using (Image image2 = Image.FromStream(stream))
{
PropertyItem property = image1.GetPropertyItem(271);
property.Id = 40092;
image2.SetPropertyItem(property);

image2.Save(filename2);
}
}

Am I missing something?

In that specific example, I don't see anything obviously wrong. Assuming
that there's nothing important in the code you left out, we're either back
to some issue with the PropertyItem itself, or an OS/.NET version
difference.

I'm testing on Windows 7 RTM, .NET 3.5 SP1. I've included a
concise-but-complete code example below that demonstrates the use of
FileShare.ReadWrite to successfully modify and save over the original
file, without the need for an in-memory copy. You should be able to use
that without any additional effort to see whether you see a locking issue
on your configuration; if not, then there's something about the specific
usage your code has that's causing problems, rather than a general failure
with a locked file (and even in that latter case, it would be some sort of
version-specific issue, as I don't have any locking issues with the code
I'm posting).

Pete


using System;
using System.Windows.Forms;
using System.Drawing;
using System.IO;

namespace TestImageFileShareMode
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}

public class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

// For deleting temp file before exiting
private string _strDelete;

protected override void OnFormClosed(FormClosedEventArgs e)
{
if (_strDelete != null)
{
File.Delete(_strDelete);
}

base.OnFormClosed(e);
}

private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofn = new OpenFileDialog())
{
ofn.Multiselect = false;
if (ofn.ShowDialog() == DialogResult.OK)
{
string strTemp = Path.GetTempFileName();

try
{
// Verify the original file is actually an image
file before bothering
// with processing
using (Image imgOriginal =
Image.FromFile(ofn.FileName)) { }

// Make a copy that we can write over later
File.Copy(ofn.FileName, strTemp, true);

// Load image from copy, modify it, and save it
using (FileStream stream = new FileStream(strTemp,
FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (Image imgOriginal =
Image.FromStream(stream))
{
using (Graphics gfx =
Graphics.FromImage(imgOriginal))
using (Font font = new
Font(FontFamily.GenericSansSerif, 18, FontStyle.Bold))
using (Brush brush = new SolidBrush(Color.Red))
{
gfx.DrawString("This is a test", font,
brush, new PointF());
}

imgOriginal.Save(strTemp);
}

// Update our GUI to display the modified image
(for
// verification purposes...not critical to the
example)
pictureBox1.ImageLocation = strTemp;

// Clean up previous temp file, reset to current
one
if (_strDelete != null)
{
File.Delete(_strDelete);
}
_strDelete = strTemp;
}
catch (Exception exc)
{
MessageBox.Show(string.Format("Failed: \"{0}\"",
exc.Message));
File.Delete(strTemp);
}
}
}
}

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// panel1
//
this.panel1.Anchor =
((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(13, 43);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(513, 342);
this.panel1.TabIndex = 1;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(4, 4);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(506, 335);
this.pictureBox1.SizeMode =
System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(538, 397);
this.Controls.Add(this.panel1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Button button1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox pictureBox1;
}
}
 
K

kndg

Peter said:
[...] Just use the Bitmap constructor that takes an Image as an
argument, and ..NET will do the copying for you automatically (added
bonus: no Graphics instance at all, never mind one you need to
dispose :) ).

Hi Pete,

I had tried this before, but it will throw GDI+ exception

Image image3 = new Bitmap(image2);
...
image3.Save(filename2, ImageFormat.Jpeg);

Did you dispose "image2" before trying to save over its file?

Yes, I did as you see from my previous code. I just modify the images
variable and comment out the drawing operations.

Image image3 = new Bitmap(images2);

//Graphics g = Graphics.FromImage(image3);
//g.DrawImage(image2, 0, 0);
..
..
..
image2.Dispose(); // release the lock

image3.SetPropertyItem(property);
image3.Save(filename2, ImageFormat.Jpeg);

However when I restart the PC, the exception gone... wierd.
I've used that exact technique before, so I know it works in the general
case. If you're seeing an exception, either you've left something out,
or there's something unique about your specific scenario.
[...]
This is my first take, but the strange thing is the GDI+ keeps the
file locked. Here is my code.

string filename1 = "D:\\Temp\\output1.jpg";
string filename2 = "D:\\Temp\\output2.jpg";

Image image1 = Image.FromFile(filename1);

using (FileStream stream = new FileStream(filename2, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite))
{
using (Image image2 = Image.FromStream(stream))
{
PropertyItem property = image1.GetPropertyItem(271);
property.Id = 40092;
image2.SetPropertyItem(property);

image2.Save(filename2);
}
}

Am I missing something?

In that specific example, I don't see anything obviously wrong.
Assuming that there's nothing important in the code you left out, we're
either back to some issue with the PropertyItem itself, or an OS/.NET
version difference.

I'm testing on Windows 7 RTM, .NET 3.5 SP1. I've included a
concise-but-complete code example below that demonstrates the use of
FileShare.ReadWrite to successfully modify and save over the original
file, without the need for an in-memory copy. You should be able to use
that without any additional effort to see whether you see a locking
issue on your configuration; if not, then there's something about the
specific usage your code has that's causing problems, rather than a
general failure with a locked file (and even in that latter case, it
would be some sort of version-specific issue, as I don't have any
locking issues with the code I'm posting).

Pete


[...]

I had copied exactly your code (no modification made) but it throws GDI+
exception. I did restart the PC but still the same. I'm using Windows XP
with .NET 3.5 SP1. I tried this on Vista but also same error. I have
no Windows 7 to test, but if what you said is true then I think it is
version-specific issue.

Regards.
 
P

Peter Duniho

[...]
I had copied exactly your code (no modification made) but it throws GDI+
exception. I did restart the PC but still the same. I'm using Windows XP
with .NET 3.5 SP1. I tried this on Vista but also same error. I have
no Windows 7 to test, but if what you said is true then I think it is
version-specific issue.

I was able to verify the exception on my XP SP3, .NET 3.5 SP1 computer. I
didn't spend any time actually trying to debug the error; I hate the lack
of information in the GDI+ exceptions, and since I've usually been
successful finding work-arounds without too much trouble, I try to avoid
spending time debugging them in more detail.

Obviously, if it's a versioning issue, it's with the OS version and not
..NET. I suppose the good news is that whatever it is, Microsoft fixed it
in Windows 7. :)

Pete
 
K

kndg

Peter said:
[...]
I had copied exactly your code (no modification made) but it throws
GDI+ exception. I did restart the PC but still the same. I'm using
Windows XP with .NET 3.5 SP1. I tried this on Vista but also same
error. I have no Windows 7 to test, but if what you said is true then
I think it is version-specific issue.

I was able to verify the exception on my XP SP3, .NET 3.5 SP1 computer.
I didn't spend any time actually trying to debug the error; I hate the
lack of information in the GDI+ exceptions, and since I've usually been
successful finding work-arounds without too much trouble, I try to avoid
spending time debugging them in more detail.

Obviously, if it's a versioning issue, it's with the OS version and not
..NET. I suppose the good news is that whatever it is, Microsoft fixed
it in Windows 7. :)

Yeah, can hardly wait the Windows 7 to reach the shelf :)
 
P

Peter Duniho

[...] I suppose the good news is that whatever it is, Microsoft
fixed it in Windows 7. :)

Yeah, can hardly wait the Windows 7 to reach the shelf :)

Just a month and a week to go! :)

In the meantime, you could still be running the RC...it's practically the
same bits, and won't expire until well after the RTM version is out.

Pete
 
P

peter

Peter Duniho said:
[...] I suppose the good news is that whatever it is, Microsoft
fixed it in Windows 7. :)

Yeah, can hardly wait the Windows 7 to reach the shelf :)

Just a month and a week to go! :)

In the meantime, you could still be running the RC...it's practically the
same bits, and won't expire until well after the RTM version is out.

Pete

Thanks!!!

I heared if using WPF can avoid the problem. The problem is in GDI+. But I
don't know how to write WPF application.

Peter
 
P

Peter Duniho

I heared if using WPF can avoid the problem. The problem is in GDI+. But
I
don't know how to write WPF application.

WPF and Forms are both APIs for dealing with the GUI. On the other hand,
the graphics stuff is independent of either (in the System.Drawing
namespace). I don't think that WPF provides an API for saving bitmaps, so
no...I doubt you can avoid the problem using it. :)

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top