Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
allanon76@gmail.com - 22 Dec 2005 15:02 GMT
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
Chris Priede - 22 Dec 2005 16:15 GMT
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.

Signature

Chris Priede

allanon76@gmail.com - 22 Dec 2005 16:29 GMT
Chris Priede ha scritto:

> Hi,
>
[quoted text clipped - 12 lines]
> --
> 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...

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.