How to create an Image with a gray scale with more then 256

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • allanon76@gmail.com

    How to create an Image with a gray scale with more then 256

    I need to create an Image with more then 256 gray scale.

    this is my code, i've some problem setting correctly the pixel value.
    any idea?

    There is another way to create an image with more then 256 gray

    Bitmap myBitmap = new
    Bitmap(256,256, PixelFormat.For mat64bppArgb);
    BitmapData bmd = myBitmap.LockBi ts(new
    Rectangle(0,0,2 56,256),ImageLo ckMode.ReadWrit e,PixelFormat.F ormat64bppArgb) ;

    unsafe
    {
    int PixelSize=8;

    for(int y=0; y<bmd.Height; y++)
    {
    byte* row=(byte *)bmd.Scan0+(y* bmd.Stride);
    for(int x=0; x<bmd.Width; x++)
    {
    row[x*PixelSize]=(byte)grayvalu e;
    }
    }
    }
    myBitmap.Unlock Bits(bmd);

    thank you all.


    michele

  • Chris Priede

    #2
    Re: How to create an Image with a gray scale with more then 256

    Hi,

    allanon76@gmail .com wrote:[color=blue]
    > I need to create an Image with more then 256 gray scale.
    > this is my code, i've some problem setting correctly the pixel value.
    > any idea?[/color]
    [color=blue]
    > byte* row=(byte *)bmd.Scan0+(y* bmd.Stride);
    > for(int x=0; x<bmd.Width; x++)
    > row[x*PixelSize]=(byte)grayvalu e;[/color]


    Without any judgement about the sanity of the rest of it -- if you are
    working with 16-bits-per-channel pixels, you almost certainly don't want to
    be casting things to bytes. Try a 16-bit type, such as ushort.


    --
    Chris Priede


    Comment

    • allanon76@gmail.com

      #3
      Re: How to create an Image with a gray scale with more then 256


      Chris Priede ha scritto:
      [color=blue]
      > Hi,
      >
      > allanon76@gmail .com wrote:[color=green]
      > > I need to create an Image with more then 256 gray scale.
      > > this is my code, i've some problem setting correctly the pixel value.
      > > any idea?[/color]
      >[color=green]
      > > byte* row=(byte *)bmd.Scan0+(y* bmd.Stride);
      > > for(int x=0; x<bmd.Width; x++)
      > > row[x*PixelSize]=(byte)grayvalu e;[/color]
      >
      >
      > Without any judgement about the sanity of the rest of it -- if you are
      > working with 16-bits-per-channel pixels, you almost certainly don't want to
      > be casting things to bytes. Try a 16-bit type, such as ushort.
      >
      >
      > --
      > Chris Priede[/color]


      I've an error if I make as you suggest. (i've already tried)
      with the format Format64bppArgb i've 2 byte per channel but i don't
      know how to set
      these 2 byte.
      If I use SetPixel i can use Color but i can set only 256 value per
      channel and it is very slow
      using LockBits and BitmapData i've no idea how to set correctly
      pixel's image

      I've asked for an alternative to my code if it is a bad code...

      Comment

      Working...