473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2285
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Defcon31 | last post by:
hello i receive from a dll a pointer to raw image data (307200bytes grayscale values). can someone explain how i can put this image data in a picturebox in VB? or can someone post code to do it...
2
by: xj92wang | last post by:
I have following code to convert a big image to smaller thumbnail, it work's fine until one day this image come out http://www.here4now.com/mobdata/sunbleached/Untitled-2.gif The original size...
5
by: Benjamin Esham | last post by:
Hello all, I have a very wide image that I want positioned in the extreme top left of the page. If the browser window is too narrow to contain the whole thing, that's fine-- the image should...
8
by: Mad Scientist Jr | last post by:
Has anyone worked with code that can look at two JPG images (I am talking about relatively small ones, 40x40 pixels or less) and quickly analyzing them to see how similar or different they are? Is...
0
by: Balu Ramachandran | last post by:
How can I create the Thumbnail view from the form? In the following approach I tried but Iams facing some limitations to get the thumbnail image of the form alone. Plaese any one can help in...
2
by: Andreas Viklund via DotNetMonster.com | last post by:
Hi! I am developing an application in ASP.NET that takes an image, that have been created with a digital camera or camera phone, and processes it, to get data from it. The image taken by the user...
0
by: Gregory Piñero | last post by:
I want to be able to randomly change pixels in an image and view the results. I can use whatever format of image makes this easiest, e.g., gray scale, bit tonal, etc. Ideally I'd like to keep...
0
by: crazyyellowguy | last post by:
hi, This is my first post in this forum and I just wanted to thank you for even taking a look at my post. The class that I am writing the C code for is my first computer class and my knowledge is...
14
anfetienne
by: anfetienne | last post by:
hi.....i have this script (below #1) that is linked to another php file SimpleImage.php (#2) im trying to get it to work on my uploaded images but it keeps coming up errors.....i haven't altered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.