mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-04-04 05:47:21 +08:00
Picture组件增加LoadingImage属性
This commit is contained in:
parent
09727c75e1
commit
e35f7f1e41
@ -257,5 +257,10 @@ namespace CPF.Android
|
||||
const string lib = "/system/lib/egl/libEGL_mali.so";
|
||||
[DllImport(lib)]
|
||||
public extern static IntPtr eglGetProcAddress(string procname);
|
||||
|
||||
public void MakeCurrent()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -406,8 +406,22 @@ namespace CPF.Windows
|
||||
case DataFormat.Text:
|
||||
if (formatId == (int)UnmanagedMethods.ClipboardFormat.CF_TEXT)
|
||||
{
|
||||
var rv = Marshal.PtrToStringAnsi(hText);
|
||||
return rv;
|
||||
try
|
||||
{
|
||||
var rv = Marshal.PtrToStringAnsi(hText);//在Unity 里会报错
|
||||
return rv;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(e);
|
||||
Console.WriteLine(e);
|
||||
var dwBufSize = (int)UnmanagedMethods.GlobalSize(hText);
|
||||
//var ss = new String((sbyte*)hText, 0, dwBufSize);
|
||||
byte[] cc = new byte[dwBufSize];
|
||||
Marshal.Copy(hText, cc, 0, (int)dwBufSize);
|
||||
string ss = Encoding.GetEncoding("GBK").GetString(cc).TrimEnd('\0');
|
||||
return ss;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -464,7 +478,7 @@ namespace CPF.Windows
|
||||
#if Net4
|
||||
var bmp = (UnmanagedMethods.BITMAPINFOHEADER)Marshal.PtrToStructure(ptr, typeof(UnmanagedMethods.BITMAPINFOHEADER));
|
||||
#else
|
||||
var bmp = Marshal.PtrToStructure<UnmanagedMethods.BITMAPINFOHEADER>(ptr);
|
||||
var bmp = Marshal.PtrToStructure<UnmanagedMethods.BITMAPINFOHEADER>(ptr);
|
||||
|
||||
#endif
|
||||
IntPtr screenDC = UnmanagedMethods.GetDC(IntPtr.Zero);
|
||||
@ -478,7 +492,7 @@ namespace CPF.Windows
|
||||
var hBitmap = UnmanagedMethods.CreateDIBSection(memDc, ref info, 0, out IntPtr ppvBits, IntPtr.Zero, 0);
|
||||
var oldBits = UnmanagedMethods.SelectObject(memDc, hBitmap);//将位图载入上下文
|
||||
//_ = UnmanagedMethods.GlobalLock(hText);
|
||||
_ = UnmanagedMethods.StretchDIBits(memDc, 0, 0, bmp.biWidth, bmp.biHeight, 0, 0, bmp.biWidth, bmp.biHeight, (ptr + sizeof(UnmanagedMethods.BITMAPINFOHEADER)), ref info, 0, (uint)TernaryRasterOperations.SRCCOPY);
|
||||
_ = UnmanagedMethods.StretchDIBits(memDc, 0, 0, bmp.biWidth, Math.Abs(bmp.biHeight), 0, 0, bmp.biWidth, Math.Abs(bmp.biHeight), (ptr + sizeof(UnmanagedMethods.BITMAPINFOHEADER)), ref info, 0, (uint)TernaryRasterOperations.SRCCOPY);
|
||||
//sizeof(UnmanagedMethods.BITMAPFILEHEADER) +
|
||||
//var c = sizeof(UnmanagedMethods.BITMAPINFOHEADER);
|
||||
|
||||
|
@ -26,6 +26,17 @@ namespace CPF.Controls
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载中显示的图片
|
||||
/// </summary>
|
||||
[TypeConverter(typeof(StringConverter)), CPF.Design.FileBrowser(".png;.jpg;.bmp;.gif")]
|
||||
[PropertyMetadata(null)]
|
||||
[Description("加载中显示的图片")]
|
||||
public Image LoadingImage
|
||||
{
|
||||
get { return GetValue<Image>(); }
|
||||
set { SetValue(value); }
|
||||
}
|
||||
/// <summary>
|
||||
/// 图片源,可以是路径、Url、Drawing.Image对象、Stream、byte[]
|
||||
/// </summary>
|
||||
@ -124,6 +135,10 @@ namespace CPF.Controls
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
if (img != null && img != ResourceManager.ErrorImage && img != LoadingImage)
|
||||
{
|
||||
RaiseEvent(EventArgs.Empty, nameof(ImageLoaded));
|
||||
}
|
||||
}
|
||||
//int frameTimer = 0;
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
@ -165,8 +180,18 @@ namespace CPF.Controls
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
[PropertyChanged(nameof(LoadingImage))]
|
||||
void OnLoadingImage(object newValue, object oldValue, PropertyMetadataAttribute attribute)
|
||||
{
|
||||
var load = newValue as Image;
|
||||
if (load != null && img == null)
|
||||
{
|
||||
SetImage(load);
|
||||
}
|
||||
}
|
||||
[PropertyChanged(nameof(Source))]
|
||||
void RegisterSource(object newValue, object oldValue, PropertyMetadataAttribute attribute)
|
||||
void OnSource(object newValue, object oldValue, PropertyMetadataAttribute attribute)
|
||||
{
|
||||
if (newValue != null)
|
||||
{
|
||||
@ -183,6 +208,11 @@ namespace CPF.Controls
|
||||
else if (newValue is string)
|
||||
{
|
||||
var s = newValue as string;
|
||||
var load = LoadingImage;
|
||||
if (load != null)
|
||||
{
|
||||
SetImage(load);
|
||||
}
|
||||
ResourceManager.GetImage(s, a =>
|
||||
{
|
||||
Invoke(() =>
|
||||
@ -403,6 +433,15 @@ namespace CPF.Controls
|
||||
remove { RemoveHandler(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片加载
|
||||
/// </summary>
|
||||
public event EventHandler ImageLoaded
|
||||
{
|
||||
add { AddHandler(value); }
|
||||
remove { RemoveHandler(value); }
|
||||
}
|
||||
|
||||
protected override void OnOverrideMetadata(OverrideMetadata overridePropertys)
|
||||
{
|
||||
base.OnOverrideMetadata(overridePropertys);
|
||||
|
@ -78,6 +78,22 @@ namespace CPF.Styling
|
||||
}
|
||||
set { errorImage = value; }
|
||||
}
|
||||
static Image loadingImage;
|
||||
/// <summary>
|
||||
/// 获取或设置加载图片
|
||||
/// </summary>
|
||||
public static Image LoadingImage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (loadingImage == null || loadingImage.ImageImpl == null)
|
||||
{
|
||||
GetImage("res://CPF/loading.gif", a => loadingImage = a);
|
||||
}
|
||||
return loadingImage;
|
||||
}
|
||||
set { loadingImage = value; }
|
||||
}
|
||||
|
||||
static ConcurrentDictionary<string, WeakReference<Image>> res = new ConcurrentDictionary<string, WeakReference<Image>>();
|
||||
static ConcurrentDictionary<string, ConcurrentBag<Action<Image>>> downloading = new ConcurrentDictionary<string, ConcurrentBag<Action<Image>>>();
|
||||
|
Loading…
Reference in New Issue
Block a user