Question writing multiple Image

Steinster

New member
Joined
Nov 11, 2015
Messages
2
Programming Experience
10+
Hi,

Im creating a CAPTCHA control and are stuck on the GDI part.
I get the correct image loaded, but I dont know how to write the image to the final image.

If anybody out there could help me with this I will be very thankfull.

C#:
Bitmap bmp = new Bitmap(imageLength, 78);
                Random rnd = new Random();

                for (int i = 0; i <= length; i++)
                {        
                    int r = rnd.Next(0, 25);
                    string letter = letters.Substring(r, 1);
                    sCode += letter;

                    System.Reflection.Assembly thisExe;
                    thisExe = System.Reflection.Assembly.GetExecutingAssembly();
                    System.IO.Stream file = thisExe.GetManifestResourceStream("LCTools.Service.Captcha.Gfx." + letter + ".jpg");

                    int angl = rnd.Next(-15, 15);

                    System.Drawing.Image img = System.Drawing.Image.FromStream(file);
                    Graphics gfx = Graphics.FromImage(img);
                    
                    gfx.RotateTransform(angl);
                    gfx.DrawImage(img, 0, 0);
    
                    //DRAW IMAGE TO bmp
}
 
Exactly as you have already done, create Graphics object from the bitmap with FromImage method, and draw with DrawImage. Bitmap inherits Image, so a Bitmap is an Image.

Don't forget to dispose everything that can be disposed when you a finished using such objects.
 
thank you for taking time to answer!

I'm not sure I understand what you mean. How do I write the Graphics object to the Bitmap object?
 
You don't. You write one image to the other image as you asked for.
 
Back
Top Bottom