Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq instead two loops get pixel color and point from image
    primarykey
    data
    text
    <p>How can i use linq to list all pixels from image and process on them? For example we have:</p> <pre><code> for (int i = 0; i &lt; this.bitmap.Width; i++) { for (int j = 0; j &lt; this.bitmap.Height; j++) { bitmap.SetPixel(x, y, Color.FromArgb(1, 1, 1)); } } </code></pre> <p>Here i do not need list pixels because i work immediately using meanwhile for loops. However i am not sure if i can process image with linq like that. I understand that linq gain data so, i would like to take pixel from point and somehow store coorinates and color data of that pixel. I need that because how would i be able then make threshold?</p> <p>I tried to use struct but on page <a href="http://social.msdn.microsoft.com/Forums/is/linqtosql/thread/02154de8-ef32-4420-a3f6-e4e473df66ce" rel="nofollow">http://social.msdn.microsoft.com/Forums/is/linqtosql/thread/02154de8-ef32-4420-a3f6-e4e473df66ce</a> they said that linq doesn't work with struct.</p> <p>Maybe i should use list but when i wrote <code>List&lt;Point, Color&gt; list</code> i got error. So i really don't know how to do that..</p> <p>The all thing is about to optimalize my function under that text. I read in book called "effectice programming in c#" that using query syntax would be more readable than for loops..</p> <p>This is my code and i really ask you for a help how make it more readable code.</p> <p>ps. please correct topic if it is not good specified by me, sorry.</p> <blockquote> <p>private void ThreshGrayTails() {</p> <pre><code> this.tempBitmap = new Bitmap(this.bitmap); for (int i = 0; i &lt; this.bitmap.Width; i++) { for (int j = 0; j &lt; this.bitmap.Height; j++) { SetTempPixelInt(i, 0, j, 0, this.tempBitmap); if (this.tempPixelInt == 252 &amp;&amp; (j + 2) &lt; this.bitmap.Height &amp;&amp; (j - 2) &gt; 0) { SetTempPixelInt(i, 0, j, -1, this.bitmap); //if pixel above has value 252 if (this.tempPixelInt == 252) { SetTempPixelInt(i, 0, j, -2, this.bitmap); //if pixel above has value 159 if (this.tempPixelInt == 159) { SetTempPixelInt(i, 0, j, +1, this.bitmap); //if pixel under has value 0 or 172 if (this.tempPixelInt == 0 || this.tempPixelInt == 172) { this.tempBitmap.SetPixel(i, j, Color.FromArgb(255, 255, 255)); this.tempBitmap.SetPixel(i - 1, j, Color.FromArgb(255, 255, 255)); this.tempBitmap.SetPixel(i - 2, j, Color.FromArgb(255, 255, 255)); } } } } //if current pixel doesnt contain value in that list, turn it on black if (!colorsToThreshold.Contains(this.tempBitmap.GetPixel(i, j).R)) { Color newcolor = Color.FromArgb(0, 0, 0); this.tempBitmap.SetPixel(i, j, newcolor); } //if current pixel contain value in that list, turn it on white else { Color newcolor = Color.FromArgb(255, 255, 255); this.tempBitmap.SetPixel(i, j, newcolor); } } } this.bitmap = new Bitmap(this.tempBitmap); SaveImage("thresholded.bmp", this.bitmap); } private void SetTempPixelInt(int i, int pi, int j, int pj, Bitmap bitmap) { Color currentColor = bitmap.GetPixel(i + pi, j + pj); this.tempPixelInt = (int)(currentColor.R); } </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload