473,395 Members | 2,798 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,395 software developers and data experts.

C# Image Processing

Folks,

I'm a really rubbish programmer and have just started C#!!

I have been tasked with creating a program that will open an image file to a picturebox and then read the values for each pixel in that file into an array. Each image I will be using is in greyscale, so its values will be 0-255. I Understand that I must use the LockBits method, as PictureBox stores a file location as a string.

In essence, I am totally lost what to do next. The code I have below is the rough foundations of the solution to my problem (I hope).

private void OpenFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Bitmap Files (*.bmp)|*.bmp";
ofd.Title = "Type File";

if (ofd.ShowDialog() == DialogResult.Cancel)
return;
try
{
pictureBox1.ImageLocation = ofd.FileName;
ofd.Dispose();
generateArray(pictureBox1.ImageLocation);
}
...
...

private void generateArray(String fileToDisplay)
{
int[] pixelArray=null;
//insert code
BitmapData sourceData = bmpImage.LockBits(new Rectangle(0, 0, bmpImage.Width, bmpImage.Height), ImageLockMode.ReadOnly, bmpImage.PixelFormat);
//insert code
}



Can anyone help me finish this off so when I open a new openfiledialog, and select an image, the program will read each pixel in the image, and store its value of between 0-255 in the array?! Any help is greatly appreciated!!!

Many thanks,
Stuart.
Apr 25 '07 #1
1 4135
TRScheel
638 Expert 512MB
Folks,

I'm a really rubbish programmer and have just started C#!!

I have been tasked with creating a program that will open an image file to a picturebox and then read the values for each pixel in that file into an array. Each image I will be using is in greyscale, so its values will be 0-255. I Understand that I must use the LockBits method, as PictureBox stores a file location as a string.

In essence, I am totally lost what to do next. The code I have below is the rough foundations of the solution to my problem (I hope).

private void OpenFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Bitmap Files (*.bmp)|*.bmp";
ofd.Title = "Type File";

if (ofd.ShowDialog() == DialogResult.Cancel)
return;
try
{
pictureBox1.ImageLocation = ofd.FileName;
ofd.Dispose();
generateArray(pictureBox1.ImageLocation);
}
...
...

private void generateArray(String fileToDisplay)
{
int[] pixelArray=null;
//insert code
BitmapData sourceData = bmpImage.LockBits(new Rectangle(0, 0, bmpImage.Width, bmpImage.Height), ImageLockMode.ReadOnly, bmpImage.PixelFormat);
//insert code
}



Can anyone help me finish this off so when I open a new openfiledialog, and select an image, the program will read each pixel in the image, and store its value of between 0-255 in the array?! Any help is greatly appreciated!!!

Many thanks,
Stuart.
The bitmap object has a function called GetPixel (I believe...) and it passes the x, y of the pixel and returns the corresponding color. You can then use that color to create a greyscale of it.

EDIT: Also, the BitMap object's constructor can be passed a file location like you did above
Apr 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Deepa | last post by:
Hi All, I'm facing problem displaying image of size 5000X5000 .My window size is smaller than image size so i'm not able to see the complete image.i can use scroll bars to view the image but i...
1
by: jasonshohet | last post by:
I read recently that: "if a before-image was made before an interruption in database processing, you use the before-image dump & simply begin processing again from just before the last...
5
by: Jigar Mehta | last post by:
Hye Friends!!, Happy New Year!! I am Jigar Mehta from India. Currently I am working on a project in which I need to compress some images on the harddisk... I want to make an engine that reads...
2
by: | last post by:
Hi, we are planning to rewrite an extisting C++ image processing application/library in C#. Now several question arouse where I hope you can help me: So far we allocated a block of memory as...
10
by: stonny | last post by:
Hi, I am converting my matlab program into C/C++. I need to change some image processing toolbox functions into C/C++, such as edge detection, mathematical morphology. Is there any place that I...
10
by: Enrique Cruiz | last post by:
Hello all, I am currently implementing a fairly simple algorithm. It scans a grayscale image, and computes a pixel's new value as a function of its original value. Two passes are made, first...
3
by: birensubudhi | last post by:
hey guys,can anyone tell me what is image processing, how to do it using C. IN KSHITIJ 2007 held at IIT kgp a que by INFOSYS is asked, they hav given an image then cut in different orientation...
2
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file formats are supported in this way? Is this fixed based...
5
by: whisk3rs | last post by:
Hello, I have a conceptual question. I need to write a program that will take as input a list of images and then process each image individually (extract useful features from the image) ...
0
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.