Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, let's see what we can do - a quick Google found <a href="http://www.copypastecode.com/68220/" rel="nofollow noreferrer">this</a>, which can be simply adapted to your function something like this</p> <pre><code>private Bitmap SobelEdgeDetect(Bitmap original) { int width = original.Width; int height = original.Height; int BitsPerPixel = Image.GetPixelFormatSize(original.PixelFormat); int OneColorBits = BitsPerPixel / 8; BitmapData bmpData = original.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, original.PixelFormat); int position; int[,] gx = new int[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; int[,] gy = new int[,] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } }; byte Threshold = 128; Bitmap dstBmp = new Bitmap(width, height, original.PixelFormat); BitmapData dstData = dstBmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, dstBmp.PixelFormat); unsafe { byte* ptr = (byte*)bmpData.Scan0.ToPointer(); byte* dst = (byte*)dstData.Scan0.ToPointer(); for (int i = 1; i &lt; height - 1; i++) { for (int j = 1; j &lt; width - 1; j++) { int NewX = 0, NewY = 0; for (int ii = 0; ii &lt; 3; ii++) { for (int jj = 0; jj &lt; 3; jj++) { int I = i + ii - 1; int J = j + jj - 1; byte Current = *(ptr + (I * width + J) * OneColorBits); NewX += gx[ii, jj] * Current; NewY += gy[ii, jj] * Current; } } position = ((i * width + j) * OneColorBits); if (NewX * NewX + NewY * NewY &gt; Threshold * Threshold) dst[position] = dst[position + 1] = dst[position + 2] = 255; else dst[position] = dst[position + 1] = dst[position + 2] = 0; } } } original.UnlockBits(bmpData); dstBmp.UnlockBits(dstData); return dstBmp; } </code></pre> <p>It's not complete copy/paste solution but you should be able to see how the original author is accessing the pixel data by using <code>LockBits</code> in exactly the way you need. The rest is up to you ;-)</p> <p>You will need to set the <code>unsafe</code> option in your project properties as I explained in <a href="https://stackoverflow.com/a/16632698/2065121">my answer</a> to your previous question.</p>
    singulars
    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.
    1. VO
      singulars
      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