Question writing multiple Image


New member
Nov 11, 2015
Programming Experience

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.

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.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.
Top Bottom