我如何可以将图像设置为在C#中的透明背景,而无需使用Bitmap.MakeTransparent()? [英] How can I set an image to have a transparent background in C# without using Bitmap.MakeTransparent()?

查看:1964
本文介绍了我如何可以将图像设置为在C#中的透明背景,而无需使用Bitmap.MakeTransparent()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置的图像有一个透明的背景,但我不希望更换一个特定的颜色与透明度的所有像素。

I want to set an image to have a transparent background, but I do not want to replace all pixels of a specific colour with transparency.

要更具体,该图像是一个文件夹,通过IShellItemImageFactory.GetImage获得缩略图。这给了我一个位图,所显示在Windows资源管理器缩略图视图,但背景是纯白色。

To be more specific, the image is a thumbnail image for a folder, obtained via IShellItemImageFactory.GetImage. This gives me a Bitmap, as displayed in Windows Explorer thumbnail view, but the background is solid white.

我可以用它Bitmap.MakeTransparent,这将在工作大多数情况下,但在缩略图图像中包含的白色本身(例如,包含图像,其中包括白颜色的文件夹)的任何情况下。

I can use Bitmap.MakeTransparent on it, and that will work in most cases, but in any cases where the thumbnail image contains white itself (for example, a folder that contains images, which include white colours).

顺便提及,这是第一次在超过10年作为开发者的是,谷歌上搜索我的问题后,我还没有找到答案的任何地方,我实际上已经不得不问我自己。 (我想这意味着我只是铲平了!yippee的,我现在是一个2级的开发...)

Incidently, this is the first time in over 10 years as a developer that, after googling my question, I have not found an answer anywhere, and I've actually had to ask it myself. (I think that means I just levelled up! Yippee, I am now a level 2 developer...)

推荐答案

使用洪水-fill算法从外部,你需要它填充相同颜色的像素。它类似于魔棒在Photoshop的东西。

Use flood-fill algorithm to fill pixels of the same color from the OUTSIDE as you need it. It is something similar to magic wand in photoshop.

http://en.wikipedia.org/wiki/Flood_fill

我会做的是一些模糊的颜色洪水填充(品红总是做它我),然后替换透明色彩(我不知道,如果洪水具有透明像素的填充是可行的)。

What I would do is flood-fill with some obscure color (Magenta always does it for me), then replace that color with transparent (I don't know if flood filling with transparent pixels is feasible).

这篇关于我如何可以将图像设置为在C#中的透明背景,而无需使用Bitmap.MakeTransparent()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆