Click here to Skip to main content
15,887,676 members
Home / Discussions / WPF
   

WPF

 
QuestionRichTexBox/FlowDocument Macro Recording Pin
dani kenan27-Sep-10 3:27
dani kenan27-Sep-10 3:27 
QuestionCanvas, dragging, scrollbars and measureoverride Pin
RugbyLeague26-Sep-10 23:09
RugbyLeague26-Sep-10 23:09 
AnswerRe: Canvas, dragging, scrollbars and measureoverride Pin
PumbaPumba27-Sep-10 19:41
PumbaPumba27-Sep-10 19:41 
GeneralRe: Canvas, dragging, scrollbars and measureoverride Pin
RugbyLeague27-Sep-10 21:39
RugbyLeague27-Sep-10 21:39 
QuestionDatagrid with Selected cell Pin
Saksida Bojan26-Sep-10 4:57
Saksida Bojan26-Sep-10 4:57 
AnswerRe: Datagrid with Selected cell Pin
Abhinav S26-Sep-10 5:36
Abhinav S26-Sep-10 5:36 
GeneralRe: Datagrid with Selected cell [modified] Pin
Saksida Bojan26-Sep-10 9:46
Saksida Bojan26-Sep-10 9:46 
QuestionProblems converting color image to grayscale [modified] Pin
Lenquist26-Sep-10 1:46
Lenquist26-Sep-10 1:46 
Hi everyone,
it's my first post so be gentle Smile | :) . 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<image.PixelHeight; y++)
                        { 
                              for(int x=0; x < image.PixelWidth; x++)
				
				{					
                                        Color c = image.GetPixel(x, y);					
					byte gray = (byte)((c.R*11 + c.G*16 + c.B*5)/32);
					image.SetPixel(x, y, Color.FromArgb(c.A, gray, gray, gray));
				}
			}
 			this.resultImgBox.Source = image;
		}


modified on Sunday, September 26, 2010 8:09 AM

AnswerRe: Problems converting color image to grayscale Pin
Abhinav S26-Sep-10 7:23
Abhinav S26-Sep-10 7:23 
GeneralRe: Problems converting color image to grayscale Pin
Lenquist26-Sep-10 8:55
Lenquist26-Sep-10 8:55 
AnswerRe: Problems converting color image to grayscale Pin
Paul Daniel Ruston27-Sep-10 13:59
Paul Daniel Ruston27-Sep-10 13:59 
GeneralRe: Problems converting color image to grayscale Pin
Lenquist27-Sep-10 23:31
Lenquist27-Sep-10 23:31 
QuestionAnimating Object along PathGeometry + transformation Pin
DTh197823-Sep-10 16:04
DTh197823-Sep-10 16:04 
QuestionEfficient WPF drawing code Pin
astibich223-Sep-10 12:17
astibich223-Sep-10 12:17 
QuestionUnable to set focus to datepicker using attached property in wpf Pin
dashingsidds23-Sep-10 1:07
dashingsidds23-Sep-10 1:07 
AnswerRe: Unable to set focus to datepicker using attached property in wpf Pin
PumbaPumba27-Sep-10 20:02
PumbaPumba27-Sep-10 20:02 
QuestionCustom control resets font properties set through Xaml Pin
WebMaster22-Sep-10 21:36
WebMaster22-Sep-10 21:36 
AnswerRe: Custom control resets font properties set through Xaml Pin
PumbaPumba27-Sep-10 17:44
PumbaPumba27-Sep-10 17:44 
QuestionDatagrid Pin
Saksida Bojan22-Sep-10 0:16
Saksida Bojan22-Sep-10 0:16 
AnswerRe: Datagrid Pin
Abhinav S22-Sep-10 4:06
Abhinav S22-Sep-10 4:06 
GeneralRe: Datagrid Pin
Saksida Bojan22-Sep-10 9:50
Saksida Bojan22-Sep-10 9:50 
AnswerRe: Datagrid Pin
Abhishek Sur22-Sep-10 9:54
professionalAbhishek Sur22-Sep-10 9:54 
GeneralRe: Datagrid [modified] Pin
Saksida Bojan22-Sep-10 10:12
Saksida Bojan22-Sep-10 10:12 
QuestionAnimation of Expander expand / collapse programmatically Pin
tronix0121-Sep-10 20:58
tronix0121-Sep-10 20:58 
AnswerRe: Animation of Expander expand / collapse programmatically Pin
Abhishek Sur22-Sep-10 9:46
professionalAbhishek Sur22-Sep-10 9:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.