Before looking at the code, I would advise you through out this code, because you are doing it all wrong, from the very beginning.
You are not really using writeable capabilities of
WriteableBitmap
as you don't write anything, only reading. The only writing part is
SetPixel
which defeats the purpose of this class completely. Performance of
SetPixel
is always prohibitively bad (unless you want to write very few pixels).
Look at the code sample of the class documentation:
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.aspx[
^].
How could you possibly miss the main idea of this class? You call
Lock
, directly manipulate memory, and then call
Unlock
. This is the main idea. That's why it give good performance. (It it similar to
System.Windows.Forms.Bitmap.LockBits
.)
Now, I cannot see how you algorithm can sharpen anything. I don't think it can. I know at least two methods of sharpening: one is unsharp mask, another one simply perform the image convolution with a fixed core (matrix) and is very simple and fast. Are you familiar with convolution operations? In discrete objects, they are pretty easy.
[EDIT #1]
You can find good example of convolutions of the image with a 5x5
convolution matrix demonstrating sharpening, blur, edge enhance, edge detect and emboss here:
http://docs.gimp.org/en/plug-in-convmatrix.html[
^].
Isn't that amazing? Just one operation for such different and striking effects! You can easily implement it using
WriteableBitmap
, can you?
[EDIT #2]
I found an open-source library which should do it for Silverlight, WPF and more:
http://writeablebitmapex.codeplex.com/[
^].
You can try to find more:
http://bit.ly/WKz4pj[
^].
—SA