* UIImageListBox: 从文件载入图片,并且解除占用
This commit is contained in:
parent
8cce9a417e
commit
e1823a882b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7
SunnyUI/Controls/UIImageListBox.Designer.cs
generated
7
SunnyUI/Controls/UIImageListBox.Designer.cs
generated
@ -17,6 +17,13 @@
|
|||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var item in Items)
|
||||||
|
{
|
||||||
|
if (item is ImageListItem imageItem)
|
||||||
|
imageItem.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,14 +727,14 @@ namespace Sunny.UI
|
|||||||
|
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
public Bitmap Image { get; private set; }
|
public Image Image { get; private set; }
|
||||||
|
|
||||||
public ImageListItem(string imagePath, string description = "")
|
public ImageListItem(string imagePath, string description = "")
|
||||||
{
|
{
|
||||||
if (File.Exists(imagePath))
|
if (File.Exists(imagePath))
|
||||||
{
|
{
|
||||||
ImagePath = imagePath;
|
ImagePath = imagePath;
|
||||||
Image = new Bitmap(imagePath);
|
Image = ImageEx.FromFile(imagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
Description = description;
|
Description = description;
|
||||||
|
@ -84,6 +84,26 @@ namespace Sunny.UI
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Image FromFile(string path)
|
||||||
|
{
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] bytes = File.ReadAllBytes(path);
|
||||||
|
return System.Drawing.Image.FromStream(new MemoryStream(bytes));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Color RandomColor()
|
public static Color RandomColor()
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user