mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-06-28 13:34:09 +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";
|
const string lib = "/system/lib/egl/libEGL_mali.so";
|
||||||
[DllImport(lib)]
|
[DllImport(lib)]
|
||||||
public extern static IntPtr eglGetProcAddress(string procname);
|
public extern static IntPtr eglGetProcAddress(string procname);
|
||||||
|
|
||||||
|
public void MakeCurrent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -406,9 +406,23 @@ namespace CPF.Windows
|
|||||||
case DataFormat.Text:
|
case DataFormat.Text:
|
||||||
if (formatId == (int)UnmanagedMethods.ClipboardFormat.CF_TEXT)
|
if (formatId == (int)UnmanagedMethods.ClipboardFormat.CF_TEXT)
|
||||||
{
|
{
|
||||||
var rv = Marshal.PtrToStringAnsi(hText);
|
try
|
||||||
|
{
|
||||||
|
var rv = Marshal.PtrToStringAnsi(hText);//在Unity 里会报错
|
||||||
return rv;
|
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
|
else
|
||||||
{
|
{
|
||||||
var rv = Marshal.PtrToStringUni(hText);
|
var rv = Marshal.PtrToStringUni(hText);
|
||||||
@ -478,7 +492,7 @@ namespace CPF.Windows
|
|||||||
var hBitmap = UnmanagedMethods.CreateDIBSection(memDc, ref info, 0, out IntPtr ppvBits, IntPtr.Zero, 0);
|
var hBitmap = UnmanagedMethods.CreateDIBSection(memDc, ref info, 0, out IntPtr ppvBits, IntPtr.Zero, 0);
|
||||||
var oldBits = UnmanagedMethods.SelectObject(memDc, hBitmap);//将位图载入上下文
|
var oldBits = UnmanagedMethods.SelectObject(memDc, hBitmap);//将位图载入上下文
|
||||||
//_ = UnmanagedMethods.GlobalLock(hText);
|
//_ = 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) +
|
//sizeof(UnmanagedMethods.BITMAPFILEHEADER) +
|
||||||
//var c = sizeof(UnmanagedMethods.BITMAPINFOHEADER);
|
//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>
|
/// <summary>
|
||||||
/// 图片源,可以是路径、Url、Drawing.Image对象、Stream、byte[]
|
/// 图片源,可以是路径、Url、Drawing.Image对象、Stream、byte[]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -124,6 +135,10 @@ namespace CPF.Controls
|
|||||||
timer = null;
|
timer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (img != null && img != ResourceManager.ErrorImage && img != LoadingImage)
|
||||||
|
{
|
||||||
|
RaiseEvent(EventArgs.Empty, nameof(ImageLoaded));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//int frameTimer = 0;
|
//int frameTimer = 0;
|
||||||
private void Timer_Tick(object sender, EventArgs e)
|
private void Timer_Tick(object sender, EventArgs e)
|
||||||
@ -165,8 +180,18 @@ namespace CPF.Controls
|
|||||||
Invalidate();
|
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))]
|
[PropertyChanged(nameof(Source))]
|
||||||
void RegisterSource(object newValue, object oldValue, PropertyMetadataAttribute attribute)
|
void OnSource(object newValue, object oldValue, PropertyMetadataAttribute attribute)
|
||||||
{
|
{
|
||||||
if (newValue != null)
|
if (newValue != null)
|
||||||
{
|
{
|
||||||
@ -183,6 +208,11 @@ namespace CPF.Controls
|
|||||||
else if (newValue is string)
|
else if (newValue is string)
|
||||||
{
|
{
|
||||||
var s = newValue as string;
|
var s = newValue as string;
|
||||||
|
var load = LoadingImage;
|
||||||
|
if (load != null)
|
||||||
|
{
|
||||||
|
SetImage(load);
|
||||||
|
}
|
||||||
ResourceManager.GetImage(s, a =>
|
ResourceManager.GetImage(s, a =>
|
||||||
{
|
{
|
||||||
Invoke(() =>
|
Invoke(() =>
|
||||||
@ -403,6 +433,15 @@ namespace CPF.Controls
|
|||||||
remove { RemoveHandler(value); }
|
remove { RemoveHandler(value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 图片加载
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler ImageLoaded
|
||||||
|
{
|
||||||
|
add { AddHandler(value); }
|
||||||
|
remove { RemoveHandler(value); }
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnOverrideMetadata(OverrideMetadata overridePropertys)
|
protected override void OnOverrideMetadata(OverrideMetadata overridePropertys)
|
||||||
{
|
{
|
||||||
base.OnOverrideMetadata(overridePropertys);
|
base.OnOverrideMetadata(overridePropertys);
|
||||||
|
@ -78,6 +78,22 @@ namespace CPF.Styling
|
|||||||
}
|
}
|
||||||
set { errorImage = value; }
|
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, WeakReference<Image>> res = new ConcurrentDictionary<string, WeakReference<Image>>();
|
||||||
static ConcurrentDictionary<string, ConcurrentBag<Action<Image>>> downloading = new ConcurrentDictionary<string, ConcurrentBag<Action<Image>>>();
|
static ConcurrentDictionary<string, ConcurrentBag<Action<Image>>> downloading = new ConcurrentDictionary<string, ConcurrentBag<Action<Image>>>();
|
||||||
|
Loading…
Reference in New Issue
Block a user