473,473 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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?

Jan 23 '06 #1
5 2302
Try also

graphicOrig.Dispose();

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


-----Original Message-----
From: benoit [mailto:be****@discussions.microsoft.com]
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?

Jan 23 '06 #2
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.F ileName); // fileUpload is
the id of fileupload html control

Zeeshan
http://zishu.blogspot.com
"benoit" <be****@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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?

Jan 23 '06 #3
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

"benoit" <be****@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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?

Jan 23 '06 #4
thanks
it worked !

"Zeeshan Muhammad" wrote:
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

"benoit" <be****@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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?


Jan 23 '06 #5
thanks
it worked !

"Daniel Fisher(lennybacon)" wrote:
Try also

graphicOrig.Dispose();

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


-----Original Message-----
From: benoit [mailto:be****@discussions.microsoft.com]
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?

Jan 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
7
by: Toby Mathews | last post by:
Hi, In an ASP.Net application I want to convert open create a FileStream object from a System.Drawing.Image - is this possible? I create an instance of an Image object using the FromFile method,...
0
by: John via .NET 247 | last post by:
Hi, I'm using the System.Drawing.Bitmap namespace to load an image,and the RotateNoneFlipY method to flip that image before saving.However I have noticed that the saved image appears cropped...
4
by: Darrel | last post by:
I'm grabbing a file from a file upload form field. This is a 'system.web.httppostedfile' I would like to modify the image (Cropping/scaling) using system.drawing.image. Is there anyway to go...
3
by: J | last post by:
I tried to inherit 'Shot' class from 'Image' class, only to fail. It gives me the CS0122 error, which says that it can't access 'System.Drawing.Image.Image()'. What am I missing? using...
5
by: Jerry J | last post by:
I want to use the System.Drawing.Image class. According to the help file, this is an abstract base class. Because it is supposedly abstract, I created another class that inherits from it. However,...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
3
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
2
by: ThatsIT.net.au | last post by:
I have this code that writes a pie chart in a asp.net page, but I want to use it in a server control. When I try I get a error on the last line "Response.OutputStream" Obviously there is no...
0
marktang
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.