2012-06-09 2 views
1

그래서 웹상에서 그레이 스케일로 이미지를 변환하는 변형을 사용하고 있습니다. 나는 "회색으로 퇴색"할 수 있기를 바란다. 색상을 점차적으로 희미 해 지므로 전체 색상에서 부분적으로 채색되어 순수한 회색으로 바뀔 수 있습니다.부분 회색조 용 ColorMatrix

public static ColorMatrix ColorMatrixForGrayScale = new ColorMatrix(new[] { 
          new[] {.3f, .3f, .3f, 0, 0}, 
          new[] {.59f, .59f, .59f, 0, 0}, 
          new[] {.11f, .11f, .11f, 0, 0}, 
          new float[] {0, 0, 0, 1, 0}, 
          new float[] {0, 0, 0, 0, 1} }); 

    public static Bitmap MakeGrayscale(Image original, int percent = 100) 
    { 
     ColorMatrix matrix = GetMatrix(percent); // returns a variation of the above. 

     //create a blank bitmap the same size as original 
     var newBitmap = new Bitmap(original.Width, original.Height); 

     //get a graphics object from the new image 
     var g = System.Drawing.Graphics.FromImage(newBitmap); 

     //create some image attributes 
     var attributes = new ImageAttributes(); 

     //set the color matrix attribute 
     attributes.SetColorMatrix(matrix); 

     //draw the original image on the new image 
     //using the grayscale color matrix 
     g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height), 
      0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes); 

     //dispose the Graphics object 
     g.Dispose(); 
     return newBitmap; 
    } 

그래서 두 부분으로 나뉩니다. 첫째, 매트릭스를 사용할 수 있습니까? 그렇다면 변화가 무엇인가, 그렇지 않다면 실행 가능한 접근법은 무엇입니까? 전체 회색조를 만든 다음 컬러 이미지와 병합하는 방법을 생각하고 있습니다.

감사

편집 : 원본 소스 Switch on the code

+0

에서 흥미로운 기사가 ​​채도를 변경하려면? 컬러링 된 영역과 나머지 그레이 스케일 (colorkey)? 확실하지 않은 무슨 뜻인지 – Sascha

+0

죄송합니다, 분명히하지 않았습니다. 사진이 모두 빨간색임을 상상해보십시오. 그레이 스케일로 변환하면 모든 회색이됩니다. 부분적으로 변환하면 색상은 빨간색과 회색 사이 어딘가에 있습니다. – Ian

+0

나는 빛과 색조를 똑같이 유지하면서 채도를 줄이는 것 같이 생각하니? – Ian

답변

관련 문제