471,618 Members | 1,316 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,618 software developers and data experts.

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

Dec 22 '05 #1
2 2166
Hi,

al*******@gmail.com wrote:
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.
--
Chris Priede
Dec 22 '05 #2

Chris Priede ha scritto:
Hi,

al*******@gmail.com wrote:
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.
--
Chris Priede

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

Dec 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Defcon31 | last post: by
8 posts views Thread by Mad Scientist Jr | last post: by
reply views Thread by Balu Ramachandran | last post: by
2 posts views Thread by Andreas Viklund via DotNetMonster.com | last post: by
reply views Thread by Gregory Piñero | last post: by
anfetienne
14 posts views Thread by anfetienne | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.