System.drawing.image

Discussion in 'ASP .Net' started by =?Utf-8?B?YmVub2l0?=, Jan 23, 2006.

  1. 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?
    =?Utf-8?B?YmVub2l0?=, Jan 23, 2006
    #1
    1. Advertising

  2. Try also

    graphicOrig.Dispose();



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




    -----Original Message-----
    From: benoit [mailto:]
    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?
    Daniel Fisher\(lennybacon\), Jan 23, 2006
    #2
    1. Advertising

  3. 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


    "benoit" <> wrote in message
    news:D...
    > 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?
    >
    Zeeshan Muhammad, Jan 23, 2006
    #3
  4. 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" <> wrote in message
    news:D...
    > 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?
    >
    Zeeshan Muhammad, Jan 23, 2006
    #4
  5. 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" <> wrote in message
    > news:D...
    > > 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?
    > >

    >
    >
    >
    =?Utf-8?B?YmVub2l0?=, Jan 23, 2006
    #5
  6. thanks
    it worked !

    "Daniel Fisher(lennybacon)" wrote:

    > Try also
    >
    > graphicOrig.Dispose();
    >
    >
    >
    > --Daniel
    > http://staff.newtelligence.com/danielf/
    >
    >
    >
    >
    > -----Original Message-----
    > From: benoit [mailto:]
    > 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?
    >
    >
    =?Utf-8?B?YmVub2l0?=, Jan 23, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anastasia
    Replies:
    4
    Views:
    17,542
    atalas
    Apr 18, 2008
  2. =?Utf-8?B?U2lsdmlh?=

    Apx returnig system.drawing.image

    =?Utf-8?B?U2lsdmlh?=, Jun 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    372
    =?Utf-8?B?U2lsdmlh?=
    Jun 28, 2004
  3. Replies:
    1
    Views:
    623
    Kevin Spencer
    Jan 9, 2006
  4. byrd48
    Replies:
    0
    Views:
    3,553
    byrd48
    Jul 6, 2006
  5. defn noob
    Replies:
    1
    Views:
    373
    Mark Space
    Jun 28, 2008
Loading...

Share This Page