GDI+ and SAVE JPG or BMP on the server

G

Guest

First of all, I thought this might be a directory security issue but it's not.
I was able to upload the file to the directory via HTTP.

Here's the situation.
I have a JPG file on my server.
..../images/myPIC.jpg

I wanted to draw a box or line using GDI+ on top of myPIC.jpg and then save
the new image to the server.

I was able to draw and display the image on screen but somehow cannot figure
out how to save it to the server.

The code below allows the result to be displayed on screen and it works fine.

newBMP.Save(Response.OutputStream, ImageFormat.Jpeg);

Something else is strange with the above image. When I RIGHT-CLICK and
attempted to save the image, the image cannot be saved. Although it displays
on screen but somehow I cannot copy the image using the RIGHT-CLICK.

Below is the code I used to save the image to the server....

newBMP.Save(Server.MapPath("images/" + "myNewPIC.jpg");


Got the following error:

[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder,
EncoderParameters encoderParams) +578
System.Drawing.Image.Save(String filename, ImageFormat format) +59
System.Drawing.Image.Save(String filename) +24
 
D

Darrel

[ExternalException (0x80004005): A generic error occurred in GDI+.]

99.9% of the time, when using GDI, 'a generic error occured' means that the
directory you are trying to save to doesn't ahve the proper permissions.
Typically, you need to make sure that directory is allowing asp.net to
modify files.

-Darrel
 
G

Guest

That's what I thought so.
However, I was able to upload file to the directory.
If dir permission doesn't allow READ and WRITE, I would think I wouldn't be
able to upload anything there.

If I added IMAGE control to the web form and allow the result to display in
the IMAGE control, the same SAVE code works.

My goal is that I don't want to display the result on screen.
The practical application would be something like a WATERMARK.
May be I have a TEXTBOX control and allow the ASP.NET and GDI+ to draw a
string on an image(s).
And if necessary, display the result on screen plus save the same result on
the server.








Darrel said:
[ExternalException (0x80004005): A generic error occurred in GDI+.]

99.9% of the time, when using GDI, 'a generic error occured' means that the
directory you are trying to save to doesn't ahve the proper permissions.
Typically, you need to make sure that directory is allowing asp.net to
modify files.

-Darrel
 

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

Similar Threads


Top