locked
PictureBox - displaying image parts RRS feed

  • Question

  • Hello all,
    do you know somebody how to display parts of images in PictureBox? Imagine when you have one image and you want to display parts of it in many PictureBoxes.
    E.g. you have Google logo in JPG (everybody can imagine) and you want to display only second part of this image (letters "gle") but you don't want to make new cropped image JPG file.
    Is there anyone who knows how to make it?
    Wednesday, October 24, 2007 3:29 PM

Answers

  • Hi
    This code answer to your request

    Code Block

    static public Bitmap Copy(Bitmap srcBitmap, Rectangle section)
    {
        // Create the new bitmap and associated graphics object
        Bitmap bmp = new Bitmap(section.Width, section.Height);
        Graphics g = Graphics.FromImage(bmp);

        // Draw the specified section of the source bitmap to the new one
        g.DrawImage(srcBitmap, 0, 0, section, GraphicsUnit.Pixel);

        // Clean up
        g.Dispose();

        // Return the bitmap
        return bmp;
    }



    Regrds
    Hammadi
    Thursday, October 25, 2007 9:43 AM