1

this is how my code look now:

System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("aaa.jpg"));

int height = objImage.Height;
int width = objImage.Width;

System.Drawing.Bitmap bitmapimage = new System.Drawing.Bitmap(objImage, width, height);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapimage);
System.Drawing.Image bitmap2 = (System.Drawing.Image)Bitmap.FromFile(Server.MapPath("sem.png"));

g.DrawImage(bitmap2, (objImage.Width - bitmap2.Width) / 2, (objImage.Height - bitmap2.Height) / 2);

MemoryStream stream = new MemoryStream();     
bitmapimage.Save(stream, ImageFormat.Jpeg);

String saveImagePath = Server.MapPath("ImagesMerge/") + "aaa.jpg";
bitmapimage.Save(saveImagePath);
imgBig.ImageUrl = saveImagePath;

The problem I have now is that the image is not displayed in browser, I don't understand why .

5
  • 5
    You question is unclear. Can you describe you task in more details? Commented Oct 22, 2009 at 8:21
  • I want to merge a .jpg with a .png. The result I want to be dsplayed in an image control from my page. Commented Oct 22, 2009 at 9:09
  • The merged image I want to be displayed in an <image tag Commented Oct 22, 2009 at 9:21
  • In the image-control, you'll point to the image file OR image handler. So what you need to know is "how to dynamically create an image with an asp.net handler or .ashx file". See google.com/… for some helpful articles... Commented Oct 22, 2009 at 11:18
  • Are you able to see the image on your file system? How are you trying to display the image on the browser? Commented Oct 22, 2009 at 12:20

6 Answers 6

3

like jmaglasang said, I would suggest to you to use an ashx file and if you don't need to keep the image, just send the image stream directly to the http without saving it on the disk

so you only need to do something like

       <img src="Handler.ashx?action=merge&image1=blah.jpg&image2=bloh.jpg">

look at this code for an example of how to send an image made in memory that does not exist on the drive

Sign up to request clarification or add additional context in comments.

Comments

2

Bitmap is a subclass of Image, so there no need to convert Bitmap to Image. It already is...

Comments

2

Probably because saveImagePath will be a local path (such as c:\somepath\aaa.jpg) that is not reachable from the browser. You probably want to set the ImageUrl = "ImagesMerge/aaa.jpg" instead.

Comments

1

You can also try:

imgBig.ImageUrl = ResolveUrl(saveImagePath);

EDIT:

If saveImagePath is under the WebApplication Directory, doing some modifications on the directory structure i.e. modifying files, deleting and creating can cause the application pool to recycle, and once it reaches the maximum recycle count the application pool will be stopped causing "Server unavailable" error.

I would suggests to add/save/modify images on a separate directory (not under the Apps Directory) then create a Handler(ASHX) that will read the images, just an advice though.

Comments

0

MapPath will give you a physycal address, not a virtual address which is what the browser needs to get to the image.

Comments

0

You might be forgetting to set the Response.Headers. Check out the following example that shows how to create bar chart images and then display it on the screen:

http://www.highoncoding.com/Articles/399_Creating_Bar_Chart_Using__NET_Graphics_API.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.