System.drawing.image

G

Guest

Hi,

I have this question.
When I use the FileUpload WebControl to post an Image (= SourceFile) that I
want to resize and write to the server, I keep getting this situation.
If that SourceFile is located in My Documents (as in "C:\Documents and
Settings\29\Mijn documenten\SubFolderFolder\ImgName.jpg"), I keep getting a
'FileNotFoundException'. That doesn't happen when I get the SourceFile from
"C:\Folder\imgName".

What can I do about this ?

Actually I found a workaround, but this gives me an error as well....

I can save the PostedFile like this
PostedFile.SaveAs(imgPath + "DummyName");

After which I can do these steps without any problem

System.Drawing.Image srcImage =
System.Drawing.Image.FromFile(imgPath + DummyName);

Graphics graphicOrig = Graphics.FromImage(srcImage);
graphicOrig.CompositingQuality = CompositingQuality.HighQuality;
graphicOrig.SmoothingMode = SmoothingMode.AntiAlias;
graphicOrig.InterpolationMode =
InterpolationMode.HighQualityBicubic;

Rectangle rectOrig = new Rectangle();
graphicOrig.DrawImage(srcImage, rectOrig);
srcImage.Save(NewFileName, ImageFormat.Jpeg);

srcImage.Dispose();

The final srcImage is perfect, and everything I need but when I want to do
this
File.Delete(imgPath + dummyName);

I get the IOException that File cannot be deleted:
"The process cannot access the file 'ImgPAth\dummyName' because it is being
used by another process."

Does anyone know what I can do about these issues?
 
D

Daniel Fisher\(lennybacon\)

Try also

graphicOrig.Dispose();



--Daniel
http://staff.newtelligence.com/danielf/




-----Original Message-----
From: benoit [mailto:[email protected]]
Posted At: Monday, January 23, 2006 12:21 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: System.drawing.image
Subject: System.drawing.image

Hi,

I have this question.
When I use the FileUpload WebControl to post an Image (= SourceFile)
that I
want to resize and write to the server, I keep getting this situation.
If that SourceFile is located in My Documents (as in "C:\Documents and
Settings\29\Mijn documenten\SubFolderFolder\ImgName.jpg"), I keep
getting a
'FileNotFoundException'. That doesn't happen when I get the SourceFile
from
"C:\Folder\imgName".

What can I do about this ?

Actually I found a workaround, but this gives me an error as well....

I can save the PostedFile like this
PostedFile.SaveAs(imgPath + "DummyName");

After which I can do these steps without any problem

System.Drawing.Image srcImage =
System.Drawing.Image.FromFile(imgPath + DummyName);

Graphics graphicOrig = Graphics.FromImage(srcImage);
graphicOrig.CompositingQuality =
CompositingQuality.HighQuality;
graphicOrig.SmoothingMode = SmoothingMode.AntiAlias;
graphicOrig.InterpolationMode =
InterpolationMode.HighQualityBicubic;

Rectangle rectOrig = new Rectangle();
graphicOrig.DrawImage(srcImage, rectOrig);
srcImage.Save(NewFileName, ImageFormat.Jpeg);

srcImage.Dispose();

The final srcImage is perfect, and everything I need but when I want to
do
this
File.Delete(imgPath + dummyName);

I get the IOException that File cannot be deleted:
"The process cannot access the file 'ImgPAth\dummyName' because it is
being
used by another process."

Does anyone know what I can do about these issues?
 
Z

Zeeshan Muhammad

Try getting the actual path of your posted file from System.IO.Path
namespace. You can use it like this:

string FileName =
System.IO.Path.GetFileName(fileUpload.PostedFile.FileName); // fileUpload is
the id of fileupload html control

Zeeshan
http://zishu.blogspot.com
 
Z

Zeeshan Muhammad

Sorry forgot to mention. You cannot manipulate an image at client side,
therefore you need to save the image at server in order to resize it. And
for the delete problem, dispose the Graphics and Rectange object that you
have created before deleting the image.

graphicOrig.Dispose();
rectOrig.Dispose();

Zeeshan.
http://zishu.blogspot.com
 
G

Guest

thanks
it worked !

Zeeshan Muhammad said:
Sorry forgot to mention. You cannot manipulate an image at client side,
therefore you need to save the image at server in order to resize it. And
for the delete problem, dispose the Graphics and Rectange object that you
have created before deleting the image.

graphicOrig.Dispose();
rectOrig.Dispose();

Zeeshan.
http://zishu.blogspot.com
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top