Live Chat Icon For mobile
Live Chat Icon

How do I create a new image off a base image with certain portions of the base image modified, in code

Platform: WinForms| Category: Bitmaps and Images

This code depends on the actual bitmap in use. This logic sets a random rectangular portion in the image to a new color.


public class ImageUtil
{
    private Image baseImage;

    private void InitBaseImage(Image baseImage)
    {
        this.baseImage = baseImage.Clone() as Image;
    }

    private Image ApplyNewColorOnImage(Color newColor)
    {
        // Create a new bitmap off the base image. 
        Image newImage = this.baseImage.Clone() as Image;
        Bitmap newBitmap = new Bitmap(newImage);

        // Set the Color cue pixels to the appropriate color. 
        // This logic of course, depends on the actual bitmap. 
        for (int i = 12; i <= 14; i++)
        for (int j = 2; j <= 14; j++)
            newBitmap.SetPixel(j, i, newColor);

        return newImage;
    }
}

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.