mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 19:19:23 +08:00
Search result thumbnail for PowerLauncher (#2124)
* Replace WPF Imaging library with UWP * Removed UWP and WPF namespace conflicting files from Wox * Removed Image hashing as it wasn't used anywhere * Updated formatting
This commit is contained in:
parent
37a551ecd3
commit
367cb41121
@ -7,8 +7,6 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Windows.ApplicationModel;
|
using Windows.ApplicationModel;
|
||||||
using Windows.Management.Deployment;
|
using Windows.Management.Deployment;
|
||||||
@ -18,6 +16,8 @@ using Wox.Infrastructure;
|
|||||||
using Wox.Plugin.Program.Logger;
|
using Wox.Plugin.Program.Logger;
|
||||||
using IStream = AppxPackaing.IStream;
|
using IStream = AppxPackaing.IStream;
|
||||||
using Rect = System.Windows.Rect;
|
using Rect = System.Windows.Rect;
|
||||||
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace Wox.Plugin.Program.Programs
|
namespace Wox.Plugin.Program.Programs
|
||||||
{
|
{
|
||||||
@ -517,11 +517,7 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
public ImageSource Logo()
|
public ImageSource Logo()
|
||||||
{
|
{
|
||||||
var logo = ImageFromPath(LogoPath);
|
var logo = ImageFromPath(LogoPath);
|
||||||
var plated = PlatedImage(logo);
|
return logo;
|
||||||
|
|
||||||
// todo magic! temp fix for cross thread object
|
|
||||||
plated.Freeze();
|
|
||||||
return plated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -541,62 +537,6 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageSource PlatedImage(BitmapImage image)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(BackgroundColor) && BackgroundColor != "transparent")
|
|
||||||
{
|
|
||||||
var width = image.Width;
|
|
||||||
var height = image.Height;
|
|
||||||
var x = 0;
|
|
||||||
var y = 0;
|
|
||||||
|
|
||||||
var group = new DrawingGroup();
|
|
||||||
|
|
||||||
var converted = ColorConverter.ConvertFromString(BackgroundColor);
|
|
||||||
if (converted != null)
|
|
||||||
{
|
|
||||||
var color = (Color)converted;
|
|
||||||
var brush = new SolidColorBrush(color);
|
|
||||||
var pen = new Pen(brush, 1);
|
|
||||||
var backgroundArea = new Rect(0, 0, width, width);
|
|
||||||
var rectabgle = new RectangleGeometry(backgroundArea);
|
|
||||||
var rectDrawing = new GeometryDrawing(brush, pen, rectabgle);
|
|
||||||
group.Children.Add(rectDrawing);
|
|
||||||
|
|
||||||
var imageArea = new Rect(x, y, image.Width, image.Height);
|
|
||||||
var imageDrawing = new ImageDrawing(image, imageArea);
|
|
||||||
group.Children.Add(imageDrawing);
|
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/6676072/get-system-drawing-bitmap-of-a-wpf-area-using-visualbrush
|
|
||||||
var visual = new DrawingVisual();
|
|
||||||
var context = visual.RenderOpen();
|
|
||||||
context.DrawDrawing(group);
|
|
||||||
context.Close();
|
|
||||||
const int dpiScale100 = 96;
|
|
||||||
var bitmap = new RenderTargetBitmap(
|
|
||||||
Convert.ToInt32(width), Convert.ToInt32(height),
|
|
||||||
dpiScale100, dpiScale100,
|
|
||||||
PixelFormats.Pbgra32
|
|
||||||
);
|
|
||||||
bitmap.Render(visual);
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ProgramLogger.LogException($"|UWP|PlatedImage|{Package.Location}" +
|
|
||||||
$"|Unable to convert background string {BackgroundColor} " +
|
|
||||||
$"to color for {Package.Location}", new InvalidOperationException());
|
|
||||||
|
|
||||||
return new BitmapImage(new Uri(Constant.ErrorIcon));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// todo use windows theme as background
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{DisplayName}: {Description}";
|
return $"{DisplayName}: {Description}";
|
||||||
|
@ -446,7 +446,7 @@
|
|||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<Image x:Name="AppIcon" Height="36" Margin="8,0,0,0" Grid.RowSpan="2" HorizontalAlignment="Left" Source="{Binding Result.IcoPath}" />
|
<Image x:Name="AppIcon" Height="36" Margin="8,0,0,0" Grid.RowSpan="2" HorizontalAlignment="Left" Source="{Binding Image}" />
|
||||||
<TextBlock x:Name="Title" Grid.Column="1" Text="{Binding Result.Title}" FontWeight="SemiBold" FontSize="20" VerticalAlignment="Bottom"/>
|
<TextBlock x:Name="Title" Grid.Column="1" Text="{Binding Result.Title}" FontWeight="SemiBold" FontSize="20" VerticalAlignment="Bottom"/>
|
||||||
<TextBlock x:Name="Path" Grid.Column="1" Text= "{Binding Result.SubTitle}" Grid.Row="1" Opacity="0.6" VerticalAlignment="Top"/>
|
<TextBlock x:Name="Path" Grid.Column="1" Text= "{Binding Result.SubTitle}" Grid.Row="1" Opacity="0.6" VerticalAlignment="Top"/>
|
||||||
<StackPanel Orientation="Horizontal" Opacity="0" HorizontalAlignment="Right" Grid.RowSpan="2" Grid.Column="1">
|
<StackPanel Orientation="Horizontal" Opacity="0" HorizontalAlignment="Right" Grid.RowSpan="2" Grid.Column="1">
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
<Window x:Class="PowerLauncher.Msg"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
Background="#ebebeb"
|
|
||||||
Topmost="True"
|
|
||||||
SizeToContent="Height"
|
|
||||||
ResizeMode="NoResize"
|
|
||||||
WindowStyle="None"
|
|
||||||
ShowInTaskbar="False"
|
|
||||||
Title="Msg" Height="60" Width="420">
|
|
||||||
<Window.Triggers>
|
|
||||||
<EventTrigger RoutedEvent="Window.Loaded">
|
|
||||||
<BeginStoryboard>
|
|
||||||
<Storyboard>
|
|
||||||
<DoubleAnimation x:Name="showAnimation" Duration="0:0:0.3" Storyboard.TargetProperty="Top"
|
|
||||||
AccelerationRatio="0.2" />
|
|
||||||
</Storyboard>
|
|
||||||
</BeginStoryboard>
|
|
||||||
</EventTrigger>
|
|
||||||
|
|
||||||
</Window.Triggers>
|
|
||||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5">
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="32" />
|
|
||||||
<ColumnDefinition />
|
|
||||||
<ColumnDefinition Width="2.852" />
|
|
||||||
<ColumnDefinition Width="13.148"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" Margin="0,9" />
|
|
||||||
<Grid HorizontalAlignment="Stretch" Margin="5 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition />
|
|
||||||
<RowDefinition />
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
<TextBlock x:Name="tbTitle" FontSize="16" Foreground="#37392c" FontWeight="Medium">Title</TextBlock>
|
|
||||||
<TextBlock Grid.Row="1" Foreground="#8e94a4" x:Name="tbSubTitle">sdfdsf</TextBlock>
|
|
||||||
</Grid>
|
|
||||||
<Image x:Name="imgClose" Grid.Column="2" Cursor="Hand" Width="16" VerticalAlignment="Top"
|
|
||||||
HorizontalAlignment="Right" Grid.ColumnSpan="2" />
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
@ -1,87 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using Wox.Helper;
|
|
||||||
using Wox.Infrastructure;
|
|
||||||
using Wox.Infrastructure.Image;
|
|
||||||
|
|
||||||
namespace PowerLauncher
|
|
||||||
{
|
|
||||||
public partial class Msg : Window
|
|
||||||
{
|
|
||||||
Storyboard fadeOutStoryboard = new Storyboard();
|
|
||||||
private bool closing;
|
|
||||||
|
|
||||||
public Msg()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
|
||||||
var dipWorkingArea = WindowsInteropHelper.TransformPixelsToDIP(this,
|
|
||||||
screen.WorkingArea.Width,
|
|
||||||
screen.WorkingArea.Height);
|
|
||||||
Left = dipWorkingArea.X - Width;
|
|
||||||
Top = dipWorkingArea.Y;
|
|
||||||
showAnimation.From = dipWorkingArea.Y;
|
|
||||||
showAnimation.To = dipWorkingArea.Y - Height;
|
|
||||||
|
|
||||||
// Create the fade out storyboard
|
|
||||||
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
|
|
||||||
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5)))
|
|
||||||
{
|
|
||||||
AccelerationRatio = 0.2
|
|
||||||
};
|
|
||||||
Storyboard.SetTarget(fadeOutAnimation, this);
|
|
||||||
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
|
|
||||||
fadeOutStoryboard.Children.Add(fadeOutAnimation);
|
|
||||||
|
|
||||||
imgClose.Source = ImageLoader.Load(Path.Combine(Wox.Infrastructure.Constant.ProgramDirectory, "Images\\close.png"));
|
|
||||||
imgClose.MouseUp += imgClose_MouseUp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
if (!closing)
|
|
||||||
{
|
|
||||||
closing = true;
|
|
||||||
fadeOutStoryboard.Begin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Show(string title, string subTitle, string iconPath)
|
|
||||||
{
|
|
||||||
tbTitle.Text = title;
|
|
||||||
tbSubTitle.Text = subTitle;
|
|
||||||
if (string.IsNullOrEmpty(subTitle))
|
|
||||||
{
|
|
||||||
tbSubTitle.Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
if (!File.Exists(iconPath))
|
|
||||||
{
|
|
||||||
imgIco.Source = ImageLoader.Load(Path.Combine(Wox.Infrastructure.Constant.ProgramDirectory, "Images\\app.png"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
imgIco.Source = ImageLoader.Load(iconPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
Show();
|
|
||||||
|
|
||||||
Dispatcher.InvokeAsync(async () =>
|
|
||||||
{
|
|
||||||
if (!closing)
|
|
||||||
{
|
|
||||||
closing = true;
|
|
||||||
await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Image
|
namespace Wox.Infrastructure.Image
|
||||||
{
|
{
|
||||||
|
@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Image
|
|
||||||
{
|
|
||||||
public interface IImageHashGenerator
|
|
||||||
{
|
|
||||||
string GetHashFromImage(ImageSource image);
|
|
||||||
}
|
|
||||||
public class ImageHashGenerator : IImageHashGenerator
|
|
||||||
{
|
|
||||||
public string GetHashFromImage(ImageSource imageSource)
|
|
||||||
{
|
|
||||||
if (!(imageSource is BitmapSource image))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var outStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
// PngBitmapEncoder enc2 = new PngBitmapEncoder();
|
|
||||||
// enc2.Frames.Add(BitmapFrame.Create(tt));
|
|
||||||
|
|
||||||
var enc = new JpegBitmapEncoder();
|
|
||||||
var bitmapFrame = BitmapFrame.Create(image);
|
|
||||||
bitmapFrame.Freeze();
|
|
||||||
enc.Frames.Add(bitmapFrame);
|
|
||||||
enc.Save(outStream);
|
|
||||||
var byteArray = outStream.GetBuffer();
|
|
||||||
using (var sha1 = new SHA1CryptoServiceProvider())
|
|
||||||
{
|
|
||||||
var hash = Convert.ToBase64String(sha1.ComputeHash(byteArray));
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,10 +3,10 @@ using System.Collections.Concurrent;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
|
using Windows.UI.Xaml.Media.Imaging;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Image
|
namespace Wox.Infrastructure.Image
|
||||||
{
|
{
|
||||||
@ -14,9 +14,6 @@ namespace Wox.Infrastructure.Image
|
|||||||
{
|
{
|
||||||
private static readonly ImageCache ImageCache = new ImageCache();
|
private static readonly ImageCache ImageCache = new ImageCache();
|
||||||
private static BinaryStorage<ConcurrentDictionary<string, int>> _storage;
|
private static BinaryStorage<ConcurrentDictionary<string, int>> _storage;
|
||||||
private static readonly ConcurrentDictionary<string, string> GuidToKey = new ConcurrentDictionary<string, string>();
|
|
||||||
private static IImageHashGenerator _hashGenerator;
|
|
||||||
|
|
||||||
|
|
||||||
private static readonly string[] ImageExtensions =
|
private static readonly string[] ImageExtensions =
|
||||||
{
|
{
|
||||||
@ -33,13 +30,11 @@ namespace Wox.Infrastructure.Image
|
|||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
_storage = new BinaryStorage<ConcurrentDictionary<string, int>>("Image");
|
_storage = new BinaryStorage<ConcurrentDictionary<string, int>>("Image");
|
||||||
_hashGenerator = new ImageHashGenerator();
|
|
||||||
ImageCache.Usage = _storage.TryLoad(new ConcurrentDictionary<string, int>());
|
ImageCache.Usage = _storage.TryLoad(new ConcurrentDictionary<string, int>());
|
||||||
|
|
||||||
foreach (var icon in new[] { Constant.DefaultIcon, Constant.ErrorIcon })
|
foreach (var icon in new[] { Constant.DefaultIcon, Constant.ErrorIcon })
|
||||||
{
|
{
|
||||||
ImageSource img = new BitmapImage(new Uri(icon));
|
ImageSource img = new BitmapImage(new Uri(icon));
|
||||||
img.Freeze();
|
|
||||||
ImageCache[icon] = img;
|
ImageCache[icon] = img;
|
||||||
}
|
}
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
@ -101,7 +96,6 @@ namespace Wox.Infrastructure.Image
|
|||||||
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
|
if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
var imageSource = new BitmapImage(new Uri(path));
|
var imageSource = new BitmapImage(new Uri(path));
|
||||||
imageSource.Freeze();
|
|
||||||
return new ImageResult(imageSource, ImageType.Data);
|
return new ImageResult(imageSource, ImageType.Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,11 +150,6 @@ namespace Wox.Infrastructure.Image
|
|||||||
image = ImageCache[Constant.ErrorIcon];
|
image = ImageCache[Constant.ErrorIcon];
|
||||||
path = Constant.ErrorIcon;
|
path = Constant.ErrorIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != ImageType.Error)
|
|
||||||
{
|
|
||||||
image.Freeze();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
@ -172,43 +161,22 @@ namespace Wox.Infrastructure.Image
|
|||||||
return new ImageResult(image, type);
|
return new ImageResult(image, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool EnableImageHash = true;
|
|
||||||
|
|
||||||
public static ImageSource Load(string path, bool loadFullImage = false)
|
public static ImageSource Load(string path, bool loadFullImage = false)
|
||||||
{
|
{
|
||||||
var imageResult = LoadInternal(path, loadFullImage);
|
var imageResult = LoadInternal(path, loadFullImage);
|
||||||
|
|
||||||
var img = imageResult.ImageSource;
|
var img = imageResult.ImageSource;
|
||||||
if (imageResult.ImageType != ImageType.Error && imageResult.ImageType != ImageType.Cache)
|
if (imageResult.ImageType != ImageType.Error && imageResult.ImageType != ImageType.Cache)
|
||||||
{ // we need to get image hash
|
{
|
||||||
string hash = EnableImageHash ? _hashGenerator.GetHashFromImage(img) : null;
|
|
||||||
if (hash != null)
|
|
||||||
{
|
|
||||||
if (GuidToKey.TryGetValue(hash, out string key))
|
|
||||||
{ // image already exists
|
|
||||||
img = ImageCache[key];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // new guid
|
|
||||||
GuidToKey[hash] = path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// update cache
|
// update cache
|
||||||
ImageCache[path] = img;
|
ImageCache[path] = img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BitmapImage LoadFullImage(string path)
|
private static BitmapImage LoadFullImage(string path)
|
||||||
{
|
{
|
||||||
BitmapImage image = new BitmapImage();
|
BitmapImage image = new BitmapImage(new Uri(path));
|
||||||
image.BeginInit();
|
|
||||||
image.CacheOption = BitmapCacheOption.OnLoad;
|
|
||||||
image.UriSource = new Uri(path);
|
|
||||||
image.EndInit();
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ using System.IO;
|
|||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using Windows.Storage.Streams;
|
||||||
|
using BitmapSourceWPF = System.Windows.Media.Imaging.BitmapSource;
|
||||||
|
using BitmapImageUWP = Windows.UI.Xaml.Media.Imaging.BitmapImage;
|
||||||
|
|
||||||
namespace Wox.Infrastructure.Image
|
namespace Wox.Infrastructure.Image
|
||||||
{
|
{
|
||||||
@ -103,14 +106,36 @@ namespace Wox.Infrastructure.Image
|
|||||||
public int Height { set { height = value; } }
|
public int Height { set { height = value; } }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static BitmapImageUWP ByteToImage(byte[] imageData)
|
||||||
|
{
|
||||||
|
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
|
||||||
|
{
|
||||||
|
using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))
|
||||||
|
{
|
||||||
|
writer.WriteBytes(imageData);
|
||||||
|
writer.StoreAsync().GetResults();
|
||||||
|
}
|
||||||
|
BitmapImageUWP image = new BitmapImageUWP();
|
||||||
|
image.SetSource(ms);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static BitmapSource GetThumbnail(string fileName, int width, int height, ThumbnailOptions options)
|
public static BitmapImageUWP GetThumbnail(string fileName, int width, int height, ThumbnailOptions options)
|
||||||
{
|
{
|
||||||
IntPtr hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
|
IntPtr hBitmap = GetHBitmap(Path.GetFullPath(fileName), width, height, options);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
byte[] data;
|
||||||
|
BitmapSourceWPF bitmapSourceWPF = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||||
|
PngBitmapEncoder encoder = new PngBitmapEncoder();
|
||||||
|
encoder.Frames.Add(BitmapFrame.Create(bitmapSourceWPF));
|
||||||
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
encoder.Save(ms);
|
||||||
|
data = ms.ToArray();
|
||||||
|
}
|
||||||
|
return ByteToImage(data);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
|
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
|
||||||
|
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.0.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="NLog.Schema" Version="4.7.0" />
|
<PackageReference Include="NLog.Schema" Version="4.7.0" />
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.1" />
|
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.1" />
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace Wox.Plugin
|
namespace Wox.Plugin
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
|
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
|
||||||
|
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.0.0" />
|
||||||
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
|
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.7" />
|
<PackageReference Include="PropertyChanged.Fody" Version="3.2.7" />
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
<Window x:Class="Wox.Msg"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
Background="#ebebeb"
|
|
||||||
Topmost="True"
|
|
||||||
SizeToContent="Height"
|
|
||||||
ResizeMode="NoResize"
|
|
||||||
WindowStyle="None"
|
|
||||||
ShowInTaskbar="False"
|
|
||||||
Title="Msg" Height="60" Width="420">
|
|
||||||
<Window.Triggers>
|
|
||||||
<EventTrigger RoutedEvent="Window.Loaded">
|
|
||||||
<BeginStoryboard>
|
|
||||||
<Storyboard>
|
|
||||||
<DoubleAnimation x:Name="showAnimation" Duration="0:0:0.3" Storyboard.TargetProperty="Top"
|
|
||||||
AccelerationRatio="0.2" />
|
|
||||||
</Storyboard>
|
|
||||||
</BeginStoryboard>
|
|
||||||
</EventTrigger>
|
|
||||||
|
|
||||||
</Window.Triggers>
|
|
||||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5">
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="32" />
|
|
||||||
<ColumnDefinition />
|
|
||||||
<ColumnDefinition Width="2.852" />
|
|
||||||
<ColumnDefinition Width="13.148"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" Margin="0,9" />
|
|
||||||
<Grid HorizontalAlignment="Stretch" Margin="5 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition />
|
|
||||||
<RowDefinition />
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
<TextBlock x:Name="tbTitle" FontSize="16" Foreground="#37392c" FontWeight="Medium">Title</TextBlock>
|
|
||||||
<TextBlock Grid.Row="1" Foreground="#8e94a4" x:Name="tbSubTitle">sdfdsf</TextBlock>
|
|
||||||
</Grid>
|
|
||||||
<Image x:Name="imgClose" Grid.Column="2" Cursor="Hand" Width="16" VerticalAlignment="Top"
|
|
||||||
HorizontalAlignment="Right" Grid.ColumnSpan="2" />
|
|
||||||
</Grid>
|
|
||||||
</Window>
|
|
@ -1,87 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Windows;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Windows.Media.Animation;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using Wox.Helper;
|
|
||||||
using Wox.Infrastructure;
|
|
||||||
using Wox.Infrastructure.Image;
|
|
||||||
|
|
||||||
namespace Wox
|
|
||||||
{
|
|
||||||
public partial class Msg : Window
|
|
||||||
{
|
|
||||||
Storyboard fadeOutStoryboard = new Storyboard();
|
|
||||||
private bool closing;
|
|
||||||
|
|
||||||
public Msg()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
|
||||||
var dipWorkingArea = WindowsInteropHelper.TransformPixelsToDIP(this,
|
|
||||||
screen.WorkingArea.Width,
|
|
||||||
screen.WorkingArea.Height);
|
|
||||||
Left = dipWorkingArea.X - Width;
|
|
||||||
Top = dipWorkingArea.Y;
|
|
||||||
showAnimation.From = dipWorkingArea.Y;
|
|
||||||
showAnimation.To = dipWorkingArea.Y - Height;
|
|
||||||
|
|
||||||
// Create the fade out storyboard
|
|
||||||
fadeOutStoryboard.Completed += fadeOutStoryboard_Completed;
|
|
||||||
DoubleAnimation fadeOutAnimation = new DoubleAnimation(dipWorkingArea.Y - Height, dipWorkingArea.Y, new Duration(TimeSpan.FromSeconds(5)))
|
|
||||||
{
|
|
||||||
AccelerationRatio = 0.2
|
|
||||||
};
|
|
||||||
Storyboard.SetTarget(fadeOutAnimation, this);
|
|
||||||
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
|
|
||||||
fadeOutStoryboard.Children.Add(fadeOutAnimation);
|
|
||||||
|
|
||||||
imgClose.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\close.png"));
|
|
||||||
imgClose.MouseUp += imgClose_MouseUp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
|
|
||||||
{
|
|
||||||
if (!closing)
|
|
||||||
{
|
|
||||||
closing = true;
|
|
||||||
fadeOutStoryboard.Begin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Show(string title, string subTitle, string iconPath)
|
|
||||||
{
|
|
||||||
tbTitle.Text = title;
|
|
||||||
tbSubTitle.Text = subTitle;
|
|
||||||
if (string.IsNullOrEmpty(subTitle))
|
|
||||||
{
|
|
||||||
tbSubTitle.Visibility = Visibility.Collapsed;
|
|
||||||
}
|
|
||||||
if (!File.Exists(iconPath))
|
|
||||||
{
|
|
||||||
imgIco.Source = ImageLoader.Load(Path.Combine(Infrastructure.Constant.ProgramDirectory, "Images\\app.png"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
imgIco.Source = ImageLoader.Load(iconPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
Show();
|
|
||||||
|
|
||||||
Dispatcher.InvokeAsync(async () =>
|
|
||||||
{
|
|
||||||
if (!closing)
|
|
||||||
{
|
|
||||||
closing = true;
|
|
||||||
await Dispatcher.InvokeAsync(fadeOutStoryboard.Begin);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
using Wox.Core.Plugin;
|
using Wox.Core.Plugin;
|
||||||
using Wox.Core.Resource;
|
using Wox.Core.Resource;
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
@ -98,11 +97,6 @@ namespace Wox
|
|||||||
|
|
||||||
public void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true)
|
public void ShowMsg(string title, string subTitle = "", string iconPath = "", bool useMainWindowAsOwner = true)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
|
||||||
{
|
|
||||||
var msg = useMainWindowAsOwner ? new Msg { Owner = Application.Current.MainWindow } : new Msg();
|
|
||||||
msg.Show(title, subTitle, iconPath);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartLoadingBar()
|
public void StartLoadingBar()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media;
|
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.Core.Resource;
|
using Wox.Core.Resource;
|
||||||
using Wox.Infrastructure.Image;
|
using Wox.Infrastructure.Image;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
namespace Wox.ViewModel
|
namespace Wox.ViewModel
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Threading;
|
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Image;
|
using Wox.Infrastructure.Image;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
using Windows.UI.Xaml.Media;
|
||||||
|
|
||||||
|
|
||||||
namespace Wox.ViewModel
|
namespace Wox.ViewModel
|
||||||
|
Loading…
Reference in New Issue
Block a user