EDN Admin
Well-known member
I have this function in Form1
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; long[] GetHistogram(Bitmap b)
{
<span style="color:Blue; long[] myHistogram = <span style="color:Blue; new <span style="color:Blue; long[256];
BitmapData bmData = <span style="color:Blue; null;
<span style="color:Blue; try
{
<span style="color:Green; //Lock it fixed with 32bpp
bmData = b.LockBits(<span style="color:Blue; new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
<span style="color:Blue; int scanline = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
<span style="color:Blue; unsafe
{
<span style="color:Blue; byte* p = (<span style="color:Blue; byte*)(<span style="color:Blue; void*)Scan0;
<span style="color:Blue; int nWidth = b.Width;
<span style="color:Blue; int nHeight = b.Height;
<span style="color:Blue; for (<span style="color:Blue; int y = 0; y < nHeight; y++)
{
<span style="color:Blue; for (<span style="color:Blue; int x = 0; x < nWidth; x++)
{
<span style="color:Blue; long Temp = 0;
Temp += p[0];
Temp += p[1];
Temp += p[2];
Temp = (<span style="color:Blue; int)Temp / 3;
myHistogram[Temp]++;
<span style="color:Green; //we do not need to use any offset, we always can increment by pixelsize when
<span style="color:Green; //locking in 32bppArgb - mode
p += 4;
}
}
}
b.UnlockBits(bmData);
}
<span style="color:Blue; catch
{
<span style="color:Blue; try
{
b.UnlockBits(bmData);
}
<span style="color:Blue; catch
{
}
}
<span style="color:Blue; return myHistogram;
}
[/code]
Now in another class in the top class level i did:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public List<<span style="color:Blue; long> histogramList { <span style="color:Blue; get; <span style="color:Blue; set; }
[/code]
Then in the bottom i did:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; if (!<span style="color:Blue; this.Secondpass)
{
<span style="color:Green; //get avg
<span style="color:Blue; double average = GetAveragePixelValue(bitmap);
<span style="color:Blue; if (AveragesList == <span style="color:Blue; null)
AveragesList = <span style="color:Blue; new List<<span style="color:Blue; double>();
<span style="color:Green; //save avg
AveragesList.Add(average);
<span style="color:Green; // get histogram values
<span style="color:Blue; long[] HistogramValues = Form1.GetHistogram(bitmap);
<span style="color:Blue; if (histogramList == <span style="color:Blue; null)
histogramList = <span style="color:Blue; new List<<span style="color:Blue; long>();
histogramList.Add(HistogramValues);
}
[/code]
Im getting error on this: histogramList.Add(HistogramValues); Error 1 The best overloaded method match for
System.Collections.Generic.List<long>.Add(long) has some invalid arguments
And same line: Error 2 Argument 1: cannot convert from long[] to long
<br/>
The problem is that the List<> isnt array[] so maybe instead of List<long> in the class top level i need to use array ? But how ?
Thanks.
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; long[] GetHistogram(Bitmap b)
{
<span style="color:Blue; long[] myHistogram = <span style="color:Blue; new <span style="color:Blue; long[256];
BitmapData bmData = <span style="color:Blue; null;
<span style="color:Blue; try
{
<span style="color:Green; //Lock it fixed with 32bpp
bmData = b.LockBits(<span style="color:Blue; new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
<span style="color:Blue; int scanline = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
<span style="color:Blue; unsafe
{
<span style="color:Blue; byte* p = (<span style="color:Blue; byte*)(<span style="color:Blue; void*)Scan0;
<span style="color:Blue; int nWidth = b.Width;
<span style="color:Blue; int nHeight = b.Height;
<span style="color:Blue; for (<span style="color:Blue; int y = 0; y < nHeight; y++)
{
<span style="color:Blue; for (<span style="color:Blue; int x = 0; x < nWidth; x++)
{
<span style="color:Blue; long Temp = 0;
Temp += p[0];
Temp += p[1];
Temp += p[2];
Temp = (<span style="color:Blue; int)Temp / 3;
myHistogram[Temp]++;
<span style="color:Green; //we do not need to use any offset, we always can increment by pixelsize when
<span style="color:Green; //locking in 32bppArgb - mode
p += 4;
}
}
}
b.UnlockBits(bmData);
}
<span style="color:Blue; catch
{
<span style="color:Blue; try
{
b.UnlockBits(bmData);
}
<span style="color:Blue; catch
{
}
}
<span style="color:Blue; return myHistogram;
}
[/code]
Now in another class in the top class level i did:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public List<<span style="color:Blue; long> histogramList { <span style="color:Blue; get; <span style="color:Blue; set; }
[/code]
Then in the bottom i did:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; if (!<span style="color:Blue; this.Secondpass)
{
<span style="color:Green; //get avg
<span style="color:Blue; double average = GetAveragePixelValue(bitmap);
<span style="color:Blue; if (AveragesList == <span style="color:Blue; null)
AveragesList = <span style="color:Blue; new List<<span style="color:Blue; double>();
<span style="color:Green; //save avg
AveragesList.Add(average);
<span style="color:Green; // get histogram values
<span style="color:Blue; long[] HistogramValues = Form1.GetHistogram(bitmap);
<span style="color:Blue; if (histogramList == <span style="color:Blue; null)
histogramList = <span style="color:Blue; new List<<span style="color:Blue; long>();
histogramList.Add(HistogramValues);
}
[/code]
Im getting error on this: histogramList.Add(HistogramValues); Error 1 The best overloaded method match for
System.Collections.Generic.List<long>.Add(long) has some invalid arguments
And same line: Error 2 Argument 1: cannot convert from long[] to long
<br/>
The problem is that the List<> isnt array[] so maybe instead of List<long> in the class top level i need to use array ? But how ?
Thanks.
View the full article