IT俱乐部 ASP.NET .Net Winform 实现CSS3.0 泼墨画效果(示例代码)

.Net Winform 实现CSS3.0 泼墨画效果(示例代码)

效果图

代码

private unsafe void BlendImages1(Bitmap img1, Bitmap img2)
{
    // 确定两个图像的重叠区域
    Rectangle rect = new Rectangle(0, 0,
        Math.Min(img1.Width, img2.Width),
        Math.Min(img1.Height, img2.Height));
    // 创建输出图像,尺寸为重叠区域大小
    Bitmap blendedImage = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
    // Lock the bits of each image and get the BitmapData.
    BitmapData data1 = img1.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    BitmapData data2 = img2.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    BitmapData dataBlended = blendedImage.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
    int bytesPerPixel = 4; // For Format32bppArgb
    int stride1 = data1.Stride;
    int stride2 = data2.Stride;
    int strideBlended = dataBlended.Stride;
    byte* ptr1 = (byte*)data1.Scan0.ToPointer();
    byte* ptr2 = (byte*)data2.Scan0.ToPointer();
    byte* ptrBlended = (byte*)dataBlended.Scan0.ToPointer();
    for (int y = 0; y > 8)); // B
                rowPtrBlended[pixelOffset + 1] = (byte)(255 - ((255 - rowPtr1[pixelOffset + 1]) * (255 - rowPtr2[pixelOffset + 1]) >> 8)); // G
                rowPtrBlended[pixelOffset + 2] = (byte)(255 - ((255 - rowPtr1[pixelOffset + 2]) * (255 - rowPtr2[pixelOffset + 2]) >> 8)); // R
                rowPtrBlended[pixelOffset + 3] = (byte)255; // A
            }
        }
    }
    // Unlock the bits of each image after processing.
    img1.UnlockBits(data1);
    img2.UnlockBits(data2);
    blendedImage.UnlockBits(dataBlended);
    // Display the blended image.
    pictureBoxResult.Image = blendedImage;
}

素材

到此这篇关于.net winform 实现CSS3.0 泼墨画效果的文章就介绍到这了,更多相关.net winform CSS3.0 泼墨画内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/code/asp-net/14794.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部