views:

179

answers:

2

Hi all, I'm trying to write a webApplication that holds two png images- big one and smaller one, I need to use the bigger one as a base and place the smaller one on it in a specific posiotion, the smaller one has transparent areas so it adds information to the base picture.

I'm using GDI+ with C#, but I managed only to upload one picture (the base one) using the following code: Bitmap objImage = new Bitmap("basePngPicturePath"); objImage.Save(Response.OutputStream, ImageFormat.Jpeg); objImage.Dispose();

I could,'t use two pictures- it doesn't work... and this was the only way I managed to upload a picture. HELP PLEASE!!! I really need this to work...

+4  A: 

You could draw the smaller image onto the larger one before the page is rendered, with code something like this:

Bitmap objImage = new Bitmap("basePngPicturePath");
Bitmap objSmallImage = new Bitmap("smallPngPicturePath");
using (Graphics g = Graphics.FromImage(objImage))
{
    g.DrawImage(...); // there are 30-some overloads of DrawImage, but 
        // basically you use objSmallImage as the source, 
        // plus various ways of telling the method
        // where to draw the smaller image.
}
objImage.Save(Response.OutputStream, ImageFormat.Jpeg);
objImage.Dispose();
objSmallImage.Dispose();
MusiGenesis
Obligatory remark about the need to handle objSmallImage and objImage through _using blocks_ as well. Especially in a Web app. +1 for the rest.
Henk Holterman
Hi, thsnks for the quick reply,I tried your code but it only drew the smaller picture.I even tried to add a line before the line that draw the small picture another that draw the base one- but it still shows only the small picture. (I used g.DrawImage(objSmallImage,new Point(10,10);
@Henk: baby steps, dude. I was trying to fit the code into the original asker's code. Besides, calling Dispose on both bitmaps accomplishes the same thing.
MusiGenesis
@aye: not sure why you'd get that result. Try changing the first two lines to Bitmap bmp = Bitmap.FromFile([filepathontheserver]) to make sure you're actually loading the saved images into the bitmaps.
MusiGenesis
A: 

Thanks, I managed to make it work!

but now arrose a different problem-

I need to make this code as a method (not in the defult.aspx.cs form but in a seperate buisnessLogic.cs class) that I can use for different small-pictures- which picture that the user clicked on, then I pass the path of the right picture to this method, but- the Response.OutputStream throus an exception- it cannot be reached from a different form.

can you help me with this problem as well? thanks

This is easy. Just write a method that takes two paths as parameters (for the big and small images) and returns a Bitmap (with the code above, you would return objImage instead of saving and disposing it). Then just call this method from wherever you had the code before, and then call Save on the bitmap from the method (and then Dispose it).
MusiGenesis