回复 1楼zhuseeav的帖子
可以通过 RasterImage 组件来做,大体思路是获取紫色背景区域,再创建一个透明通道覆盖该区域,参考代码:
- RasterImage main = _codecs.Load("DarkBG1.jpg");
- RasterImage alpha = main.Clone();
- GrayscaleCommand gray = new GrayscaleCommand(8);
- gray.Run(alpha);
- //create a region of all dark areas
- alpha.AddColorRgbRangeToRegion(new RasterColor(0, 0, 0), new RasterColor(40, 40, 40), RasterRegionCombineMode.Set);
- FillCommand fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Black));
- //fill the dark areas with black
- fill.Run(alpha);
- //invert the region so that it covers the non-dark areas
- alpha.AddRectangleToRegion(null, new LeadRect(0, 0, alpha.Width, alpha.Height), RasterRegionCombineMode.Xor);
- fill.Color = RasterColor.FromKnownColor(RasterKnownColor.White);
- //fill the new regin with white
- fill.Run(alpha);
- //clear the region
- alpha.MakeRegionEmpty();
- //diffuse the edges to make the boundary smooth between black and white
- AverageCommand avg = new AverageCommand(8);
- avg.Run(alpha);
- main.SetAlphaImage(alpha);
- _codecs.Save(main, "DarkBG1withAlpha.png", RasterImageFormat.Png, 32);
复制代码 |