문제

다른 이미지에서 알파를 사용하여 이미지의 알파를 조작하는 방법이 있습니까?

이미지가 있고 왼쪽에서 불투명하게 시작하고 오른쪽에서 완전히 투명한 알파를 변경하고 싶다고 가정 해 봅시다. 현재 나는 선형 그라디언트 브러쉬로 다른 이미지를 그립니다. 픽셀로 픽셀을 루핑하여 두 번째 이미지에서 Orginal Image의 알파를 설정합니다. Gdiplus에는 다른 방법이 있습니다. , 일부 이미지 마스크 또는 두 개의 이미지의 알파를 혼합합니까?

결론 : GDI+에는 두 개의 이미지를 혼합 할 수있는 방법이없는 것 같습니다. 픽셀을 통해 반복하여 단지 방법만이 수동 방식 인 것 같습니다.

도움이 되었습니까?

해결책

나는 당신 이이 픽셀 바이 픽셀을해야한다는 점에서 당신이 맞다고 생각합니다. 나는 또한 더 "순수한"방법을 검색했지만 이것이 내가 끝난 것입니다.

    public enum ChannelARGB
    {
        Blue = 0,
        Green = 1,
        Red = 2,
        Alpha = 3
    }

    public static void transferOneARGBChannelFromOneBitmapToAnother(
        Bitmap source,
        Bitmap dest,
        ChannelARGB sourceChannel,
        ChannelARGB destChannel )
    {
        if ( source.Size!=dest.Size )
            throw new ArgumentException();
        Rectangle r = new Rectangle( Point.Empty, source.Size );
        BitmapData bdSrc = source.LockBits( r, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb );
        BitmapData bdDst = dest.LockBits( r, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb );
        unsafe
        {
            byte* bpSrc = (byte*)bdSrc.Scan0.ToPointer();
            byte* bpDst = (byte*)bdDst.Scan0.ToPointer();
            bpSrc += (int)sourceChannel;
            bpDst += (int)destChannel;
            for ( int i = r.Height * r.Width; i > 0; i-- )
            {
                *bpDst = *bpSrc;
                bpSrc += 4;
                bpDst += 4;
            }
        }
        source.UnlockBits( bdSrc );
        dest.UnlockBits( bdDst );
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top