here is my code :
- Code: Select all
private void OpenBTN_Click(object sender, EventArgs e)
{
Bitmap img;
int height = 0;
int weight = 0;
int size = 0;
byte[] image;
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
try
{
img = AForge.Imaging.Image.FromFile(openFileDialog1.FileName);
ccdImageAnalyzer1.Image = img;
image = imageToByteArray(img);
height = img.Height;
weight = img.Width;
size = height * weight;
}
catch( Exception err)
{
MessageBox.Show(err.ToString());
}
}
MessageBox.Show(result.ToString());
}
public byte[] imageToByteArray(Bitmap imageIn)
{
MemoryStream ms = new MemoryStream();
string temp = imageIn.PixelFormat.ToString();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
I make a white picture in paint and saved it as a PNG
but when I run my program I am getting NON zero number in my array...
how is that ?
0 is white and 255 is black
but I am get random numbers
like
- Code: Select all
137
80
78
71
13
10
26
10
0
0
0
13
73
72
68
82
0
0
3
185
0
0
3
how is that ?
something is wrong..
how do I get an true array of the pixels in my image ?
Also my array size is way off,
height 799 int
weight 953 int
size 761447 int
+ image {byte[605]} byte[]
so I know Height and weight are right because I make the pic in paint
so Size is right too
but the image array is way too small