2010-11-20 6 views
1

Ich soll dieses RBG-Parade-Projekt in WPF erstellen, aber ich habe keine Ahnung, wo ich anfangen soll. Es sollte Bilder in 720p-Einstellungen (1280x720) verarbeiten. Irgendeine Idee, wo ich anfangen soll, ich bin völlig ahnungslos. Ich will nicht das ganze Projekt nur ein paar Hinweise.RGB-Parade in WPF

Vielen Dank.

+0

es Figured auf meinem eigenen aus. Ich werde das Projekt später veröffentlichen. Vielen Dank. – Carlo

Antwort

0

Ok, das ist, was ich kam mit, ich bin sicher, dass es eine bessere Lösung, aber es funktioniert:

public ObservableCollection<double> RPercentPerColumn { get; set; } 
public ObservableCollection<double> GPercentPerColumn { get; set; } 
public ObservableCollection<double> BPercentPerColumn { get; set; } 

private int[] GetImagePixels(ref int imageHeight, ref int imageWidth) 
{ 
    BitmapImage image = new BitmapImage(new Uri(this.CurrentImageFile, UriKind.Absolute)); 

    WriteableBitmap bmp = new WriteableBitmap(image); 

    int rows = bmp.PixelHeight; 
    int columns = bmp.PixelWidth; 

    int[] pixels = new int[bmp.PixelWidth * bmp.PixelHeight]; 

    bmp.CopyPixels(pixels, columns * 4, 0); 

    imageHeight = bmp.PixelHeight; 
    imageWidth = bmp.PixelWidth; 

    return pixels; 
} 

private void ClearAllData() 
{ 
    this.RPercentPerColumn.Clear(); 
    this.GPercentPerColumn.Clear(); 
    this.BPercentPerColumn.Clear(); 
} 

public void ProcessRGBParade() 
{ 
    if (string.IsNullOrEmpty(this.CurrentImageFile)) 
     return; 

    ClearAllData(); 

    int columns = 0; 
    int rows = 0; 

    int[] pixels = GetImagePixels(ref rows, ref columns); 

    int column = 0; 
    int row = 0; 

    int redColumnTotal = 0; 
    int greenColumnTotal = 0; 
    int blueColumnTotal = 0; 
    int currentPixel = 0; 

    double totalColorInColumn = 0; 

    double redIntensity = 0; 
    double greenIntensity = 0; 
    double blueIntensity = 0; 

    int r = 0; 
    int g = 0; 
    int b = 0; 

    // logic to calculate intensity 
    for (int i = 0; i < pixels.Length; i ++) 
    { 
     row++; 

     r = (pixels[currentPixel] & 0x00FF0000) >> 16; 
     g = (pixels[currentPixel] & 0x0000FF00) >> 8; 
     b = (pixels[currentPixel] & 0x000000FF); 

     redColumnTotal += r; 
     greenColumnTotal += g; 
     blueColumnTotal += b; 

     totalColorInColumn += r + g + b; 

     if (row == rows) 
     { 
      row = 0; 
      column++; 

      currentPixel = column; 

      redIntensity = (redColumnTotal/totalColorInColumn) * 100; 
      greenIntensity = (greenColumnTotal/totalColorInColumn) * 100; 
      blueIntensity = (blueColumnTotal/totalColorInColumn) * 100; 

      RPercentPerColumn.Add(double.IsNaN(redIntensity) ? 0 : redIntensity); 
      GPercentPerColumn.Add(double.IsNaN(greenIntensity) ? 0 : greenIntensity); 
      BPercentPerColumn.Add(double.IsNaN(blueIntensity) ? 0 : blueIntensity); 

      redColumnTotal = 0; 
      greenColumnTotal = 0; 
      blueColumnTotal = 0; 

      totalColorInColumn = 0; 
     } 
     else 
     { 
      currentPixel += columns; 
     } 
    } 
}