Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi there. how can i extract bitplanes of a gray image?
i wanna read a gray picture from some place and so :
a) show it with biplane1
b)show it with biplane1 and 2
c)show it with biplane1 and 2 and 3
d)show it with biplane1 and 2 and 3 and 4

i should enable the "redo" and "undo" actions

please help
Posted
Comments
[no name] 4-Mar-14 4:32am    
Show us your code.
ilia71 4-Mar-14 6:23am    
i didnt write any code . i have no idea about it at all . how can i reach to value of a pixel as an integer ?

1 solution

I am also struggling to follow exactly what you want but lets start with a simple grayscale display of any supported image format file (JPG,BMP, PNG, GIF & TIFF)
C#
public static Bitmap MakeGrayscale(Image original)
{
    //create a blank bitmap the same size as original image
    Bitmap newBitmap = new Bitmap(original.Width, original.Height);

    //get a graphics object from the new image
    Graphics g = Graphics.FromImage(newBitmap);

    //create the grayscale ColorMatrix
    ColorMatrix colorMatrix = new ColorMatrix(
        new float[][] 
{
    new float[] {.3f, .3f, .3f, 0, 0},
    new float[] {.59f, .59f, .59f, 0, 0},
    new float[] {.11f, .11f, .11f, 0, 0},
    new float[] {0, 0, 0, 1, 0},
    new float[] {0, 0, 0, 0, 1}
});

    //create some image attributes
    ImageAttributes attributes = new ImageAttributes();

    //set the color matrix attribute
    attributes.SetColorMatrix(colorMatrix);

    //draw the original image on the new image
    //using the grayscale color matrix
    g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
        0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);

    //dispose the Graphics object
    g.Dispose();
    return newBitmap;
}

A sample call from say a simple form with a a button would look like
C#
private void button1_Click(object sender, EventArgs e)
{
    //get a graphics object
    Graphics graph = CreateGraphics();

    // load you bitmap image  =>  change the name Image.jpg below to your image
    // Don't forget full path if file isn't in exe directory
    // the function supports  BMP, JPG, PNG, TIFF or GIF formats
    Image img = Image.FromFile("Image.jpg"); 

    // Makes a greyscale version of the bitmap by calling above function
    Bitmap b = MakeGrayscale(img);
    
    // draw bitmap to 0,0 on form
    graph.DrawImage(b, 0, 0);
}


Hope that helps as a start
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900