图标到图像 - 透明度问题 [英] Icon to Image - transparency issue
问题描述
我想在一个富文本框来构建,如文件列表中的树状视图。
I'm trying to build a treeview like file list in a richtext box.
它应该看起来像一个探险家树视图。我的code是能够得到一个调整大小的图标,但透明度缺失(浅灰色的背景,而不是透明度)。我需要做什么改变这里的?是图像格式错误? 有没有更好的方式来将图像添加到一个RichTextBox?
It should look like an explorer treeview. My code is able to get an resize the icon, but the transparency is missing (light gray background instead of transparency). What do I need to change here? Is the Image format wrong? Is there a better way to add an image to a richtextbox?
// Get file info
FileInfo f = new FileInfo("myfile.name");
// Get icon for fileinfo
Icon ico = Icon.ExtractAssociatedIcon(f);
// Convert icon to bitmap
Bitmap bm = ico.ToBitmap();
// create new image with desired size
Bitmap img = new Bitmap(16,16,PixelFormat.Frmat32bpRgb);
// Create graphics with desired sized image
Graphics g = Graphics.FormImage(img);
// set interpolation mode
g.InterpolationMode = InterpolationMode.HighQualityBiCubic;
// draw/resize image
g.DrawImage(bm, new Rectangle(0,0,16,16), new Rectangle(0, 0, bm.Width, bm,Height), GraphicalUnit.Pixel);
// Paste to clipboard
Clipboard.SetImage(bm);
// Paste in RichtextBox
rtb.Paste();
例如:
编辑:
我已经想通了,该图像是透明的,但使用Clipboard.SetImage()不会发布为透明图像。
I've figured out that the image is transparent, but using Clipboard.SetImage() doesn't publish it as transparent image.
任何想法,为什么我能做些什么来解决这个问题?我是否需要切换到differn文本框控件?
Any ideas why and what can I do to fix it? Do I need to switch to a differn textbox control?
推荐答案
我有一些运气经历显卡。
I've had some luck going through Graphics.
Bitmap b = new Bitmap(pbAssetLoaded.Width, pbAssetLoaded.Height);
using (Graphics g = Graphics.FromImage(b))
{
g.DrawIcon(SystemIcons.Information, 0, 0);
}
这与透明位图绘制图标。
This draws the icon with transparency to the Bitmap.
这篇关于图标到图像 - 透明度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!