Problems converting color image to grayscale [modified]
-
Hi everyone, it's my first post so be gentle :). I'm having difficulties converting a colored image to grayscale in a silverlight application. Clicking the link you can see the results of my code (left is the original pic right the resulting grayscale pic): Link I have no idea what I'm doing wrong. It should work but it doesn't. Help would be appreciated! One other thing, the WriteableBitmap.setPixel and WriteableBitmap.getPixel functions are part of the WritableBitmapEx library downloaded from Codeplex. Here's the code:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
convertToGrayscale(new WriteableBitmap((BitmapSource)this.Original.Source));
}public void convertToGrayscale(WriteableBitmap image) { var p = image.Pixels; for(int y=0; y
modified on Sunday, September 26, 2010 8:09 AM
-
Hi everyone, it's my first post so be gentle :). I'm having difficulties converting a colored image to grayscale in a silverlight application. Clicking the link you can see the results of my code (left is the original pic right the resulting grayscale pic): Link I have no idea what I'm doing wrong. It should work but it doesn't. Help would be appreciated! One other thing, the WriteableBitmap.setPixel and WriteableBitmap.getPixel functions are part of the WritableBitmapEx library downloaded from Codeplex. Here's the code:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
convertToGrayscale(new WriteableBitmap((BitmapSource)this.Original.Source));
}public void convertToGrayscale(WriteableBitmap image) { var p = image.Pixels; for(int y=0; y
modified on Sunday, September 26, 2010 8:09 AM
Well - could be something wrong with the algorithm. Try
byte gray = (byte)((c.R + c.G + c.B)/3);
instead. See here.The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
-
Well - could be something wrong with the algorithm. Try
byte gray = (byte)((c.R + c.G + c.B)/3);
instead. See here.The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.
-
Hi everyone, it's my first post so be gentle :). I'm having difficulties converting a colored image to grayscale in a silverlight application. Clicking the link you can see the results of my code (left is the original pic right the resulting grayscale pic): Link I have no idea what I'm doing wrong. It should work but it doesn't. Help would be appreciated! One other thing, the WriteableBitmap.setPixel and WriteableBitmap.getPixel functions are part of the WritableBitmapEx library downloaded from Codeplex. Here's the code:
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
convertToGrayscale(new WriteableBitmap((BitmapSource)this.Original.Source));
}public void convertToGrayscale(WriteableBitmap image) { var p = image.Pixels; for(int y=0; y
modified on Sunday, September 26, 2010 8:09 AM
Hi Lenquist Ran some tests (i.e. setting the pixel to the returned GetPixel with no modification) and the image changed. Turns out there is a problem with the GetPixel in the extensions library, which has been fixed. You need to go to http://writeablebitmapex.codeplex.com/SourceControl/list/changesets and download the latest source and compile it yourself.
-
Hi Lenquist Ran some tests (i.e. setting the pixel to the returned GetPixel with no modification) and the image changed. Turns out there is a problem with the GetPixel in the extensions library, which has been fixed. You need to go to http://writeablebitmapex.codeplex.com/SourceControl/list/changesets and download the latest source and compile it yourself.