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

A

allanon76

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.Format64bppArgb);
BitmapData bmd = myBitmap.LockBits(new
Rectangle(0,0,256,256),ImageLockMode.ReadWrite,PixelFormat.Format64bppArgb);

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)grayvalue;
}
}
}
myBitmap.UnlockBits(bmd);

thank you all.


michele
 
C

Chris Priede

Hi,

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?
byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
for(int x=0; x<bmd.Width; x++)
row[x*PixelSize]=(byte)grayvalue;


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.
 
A

allanon76

Chris Priede ha scritto:
Hi,

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?
byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
for(int x=0; x<bmd.Width; x++)
row[x*PixelSize]=(byte)grayvalue;


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.


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top