我有一个WinForms程序需要一个体面的可滚动图标控件与大图标(真的是128x128或更大的缩略图),可以点击到hilight或双击以执行某些操作.最好是浪费的空间最小(每个图标下方可能需要短文件名标题;如果文件名太长,我可以添加省略号).
具有适当颜色,间距等的listview的完成版本http://www.updike.org/images/listview-great.png
我尝试使用带有LargeIcon的ListView(默认.View),结果令人失望:
截图显示LargeIcon视图中的小图标http://www.updike.org/images/listview-poor.png
也许我错误填充控件?码:
ImageList ilist = new ImageList();
this.listView.LargeImageList = ilist;
int i = 0;
foreach (GradorCacheFile gcf in gc.files)
{
Bitmap b = gcf.image128;
ilist.Images.Add(b);
ListViewItem lvi = new ListViewItem("text");
lvi.ImageIndex = i;
this.listView.Items.Add(lvi);
i++;
}
Run Code Online (Sandbox Code Playgroud)
我需要带有小空间的大图标,而不是带有令人尴尬的小图标的大空间.
我找到了关于OwnerDraw的这个教程,但是从那里开始的工作基本上达到了上面的数字3或4,因为该演示只是展示了如何在细节视图中对行进行调整.
添加线
ilist.ImageSize = new Size(128, 128);
Run Code Online (Sandbox Code Playgroud)
在for循环之前修复了大小问题,但现在图像被调色为8位(看起来像系统颜色?),即使调试器显示图像作为24bpp System.Drawing.Bitmap插入到ImageList中:
大图标,最后是http://www.updike.org/images/listview-poor2.png
随着添加线
ilist.ColorDepth = ColorDepth.Depth24Bit;
Run Code Online (Sandbox Code Playgroud)
设置ilist.ImageSize之后,我按照仲裁者的建议改变了间距:
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试捕获屏幕,然后将其转换为Base64字符串.这是我的代码:
Rectangle bounds = Screen.GetBounds(Point.Empty);
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
// Convert the image to byte[]
System.IO.MemoryStream stream = new System.IO.MemoryStream();
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] imageBytes = stream.ToArray();
// Write the bytes (as a string) to the textbox
richTextBox1.Text = System.Text.Encoding.UTF8.GetString(imageBytes);
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
Run Code Online (Sandbox Code Playgroud)
使用richTextBox进行调试,它显示:
BM6〜
因此,由于某种原因,字节不正确会导致base64String变为null.知道我做错了什么吗?谢谢.