2014-10-02 4 views
0

두 개의 System.Drawing.Brush 클래스를 결합/추가하는 방법이 있습니까?두 개의 브러시 클래스를 추가하는 방법

Brush b1 = GetFromSomewhere();

Brush b2 = GetFromSomewhereElse(); 

(그런 일이 ...)

Brush b3 = b1 + b2; 

결국 내 목적은 그런 짓을하는 것입니다

업데이트
Graphics graphics = new Graphics; 
graphics.FillRectangle(b3, rectangle); 

: 나는 제 3 자 라이브러리가 (제어 할 수는 없다.) 미리 정의 된 Brush 인스턴스를 제공한다 (예 : ++++ 또는 #####와 같은 채우기 패턴을 나타냄). 내 "자신의"브러시 패턴으로 그 인스턴스를 "오버레이"하고 싶습니다.

+2

어떻게 생겼습니까? –

+1

두 개의 브러시를 "결합"또는 "추가"하는 데는 현재 아무 것도 없습니다. 누군가가 해결 방법을 제공하기 전에 어떤 의미인지 정의해야합니다. –

+0

색상을 혼합하려면 쉽게 할 수 있습니다. SolidBrush에 대해 이야기하고 있습니까? 혼합물이별로 의미가없는, 훨씬 더 복잡한 브러시 유형이 있습니다. 아니면 [CompoundPen] (http://msdn.microsoft.com/en-us/library/system.drawing.pen.compoundarray%28v=vs.110%29.aspx)을 의미할까요? – TaW

답변

3

업데이트 : 마침내 당신이 여기에 원하는 것은 두 TextureBrushes을 혼합 할 수있는 솔루션입니다 명확히했기 때문에

:

난 당신이 Image IMG2에 TextureBrush에 대한 패턴을 가정합니다. ..

Bitmap mixBitmaps(Bitmap bmp1, Bitmap bmp2) 
{ 
    using (Graphics G = Graphics.FromImage(bmp1)) 
    { 
     G.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; 
     G.DrawImage(bmp2, Point.Empty); 
    } 
    return bmp1; 
} 

여기에 지금

TextureBrush brush3 = new TextureBrush(
         mixBitmaps((Bitmap)(brush1.Image), (Bitmap) img2) ); 

당신은 페인트 또는 그것으로 물건을 채울 수 : 같은 크기의 두 개의 이미지를 혼합하고 결합 된 패턴을 사용하여 새 브러시를 만들려면 아래 간단한 방법을 사용하여 나는 이전의 대답을 남겨

texture mix


: 예입니다 일부 사람들도 그것에 관심이 있기 때문에 : 당신은 색상을 혼합 할 경우

당신은 아마 다음과 같이 쉽게 수행 할 수 있습니다

SolidBrush MixColor(SolidBrush b1, SolidBrush b2) 
{ 
    return new SolidBrush(Color.FromArgb(Math.Max(b1.Color.A, b2.Color.A), 
         (b1.Color.R + b2.Color.R)/2, (b1.Color.G + b2.Color.G)/2, 
         (b1.Color.B + b2.Color.B)/2)); 
} 

당신은 고정 된 값으로 알파 채널을 설정할 수 있습니다 대신 255 자

그러나 이것은 단순한 평균 caculation입니다. 색상이 비슷하지 않으면 잘 작동하지 않습니다. 더 나은 여기

입니다 ... 당신이 당신이, HSL 또는 HSV로 변환이 혼합 다시 RGB로 변환하는 것입니다, 채도 및 밝기 값에서 separatly 색상 모두를 혼합 것 섞어 들어

버전 :

SolidBrush MixBrushes(SolidBrush br1, SolidBrush br2) 
{ 
    return new SolidBrush (MixColorHSV(br1.Color, br2.Color)); 
} 

Color MixColorHSV(Color c1 , Color c2) 
{ 
    double h1 = c1.GetHue(); 
    double h2 = c2.GetHue(); 
    double d = (h2 - h1)/2d; 
    double h = h1 + d; 
    if (d > 90) h -= 180; else if (d < -90) h += 180; // correction 1! 
    if (h < 0) h += 360; else if (h > 360) h -= 360; // correction 2! 

    int max1 = Math.Max(c1.R, Math.Max(c1.G, c1.B)); 
    int min1 = Math.Min(c1.R, Math.Min(c1.G, c1.B)); 
    double s1 = (max1 == 0) ? 0 : 1d - (1d * min1/max1); 
    double v1 = max1/255d; 

    int max2 = Math.Max(c2.R, Math.Max(c2.G, c2.B)); 
    int min2 = Math.Min(c2.R, Math.Min(c2.G, c2.B)); 
    double s2 = (max2 == 0) ? 0 : 1d - (1d * min2/max2); 
    double v2 = max2/255d; 

    double s = (s1 + s2)/2d; 
    double v = (v1 + v2)/2d; 

    return ColorFromHSV(h,s,v); 
} 

public static Color ColorFromHSV(double hue, double saturation, double value) 
{ 
    int hi = Convert.ToInt32(Math.Floor(hue/60)) % 6; 
    double f = hue/60 - Math.Floor(hue/60); 

    value = value * 255; 
    int v = Convert.ToInt32(value); 
    int p = Convert.ToInt32(value * (1 - saturation)); 
    int q = Convert.ToInt32(value * (1 - f * saturation)); 
    int t = Convert.ToInt32(value * (1 - (1 - f) * saturation)); 

    if (hi == 0)  return Color.FromArgb(255, v, t, p); 
    else if (hi == 1) return Color.FromArgb(255, q, v, p); 
    else if (hi == 2) return Color.FromArgb(255, p, v, t); 
    else if (hi == 3) return Color.FromArgb(255, p, q, v); 
    else if (hi == 4) return Color.FromArgb(255, t, p, v); 
    else    return Color.FromArgb(255, v, p, q); 
} 

변환 부분은 this post을 참조하십시오.

다음은 각각 30 ° 더 멀리 떨어진 색상으로 빨간색을 추가하는 두 가지 혼합을 비교하는 색상 차트입니다. 몇 가지 간단한 믹스가 더 채도가 낮고 murkier인지 확인하십시오. two color mixes

+0

그게 전부 야! 완벽 해, 고마워. – Nostradamus

관련 문제