添加功能
This commit is contained in:
@@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace GeekDesk.Constant
|
|
||||||
{
|
|
||||||
class AppConstant
|
|
||||||
{
|
|
||||||
private static string APP_DIR = AppDomain.CurrentDomain.BaseDirectory.Trim();
|
|
||||||
/// <summary>
|
|
||||||
/// app数据文件路径
|
|
||||||
/// </summary>
|
|
||||||
public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,6 +8,12 @@ namespace GeekDesk.Constant
|
|||||||
{
|
{
|
||||||
public class Constants
|
public class Constants
|
||||||
{
|
{
|
||||||
|
public static string APP_DIR = AppDomain.CurrentDomain.BaseDirectory.Trim();
|
||||||
|
/// <summary>
|
||||||
|
/// app数据文件路径
|
||||||
|
/// </summary>
|
||||||
|
public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径
|
||||||
|
|
||||||
//默认文件夹图标
|
//默认文件夹图标
|
||||||
public static string DEFAULT_DIR_IMAGE_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAASISURBVHhe7dvPi9R1HMfx/Qu6RYfqEp1CZ8Yko0MQRNEPgnQ36FJEFyPoF/0DHbx06dSlnVkF6SgEgocOYUEG0cFWpQ476yhbQfTDslJxk+k79S1IP/NSF3f2O+7jBY/TKgvz/j5nXMUZMzMzMzMzMzMzMzMzMzMzu959023dsbSw9YGlbuchyk7v3XbP0t5tt9Yvmd3MW3r//luWu623TvbahytDrtvBQa/9xvJ85776JbWbZf359s7quCcKR2cNqjeaQ/35zgv1y2vTvOqgOy4/MDdG9abzwWC+06lfapu2jf4cXTosN9SZ5W7n9folt2nZ6Ifw6niDy47JelloH6hfepuGLffa7xQPyfpZaL9Xv/zW5K307r27eEDWXfXG9GJ9BmvqqneyV0rHYzL63a3b61NYEzfodT4rHY4J8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+8tjw/OdPXbPVr18eXlp6E6bG6le7i8/yOL8efnR4at+24czvR54Y/nl8DrjM6INjpvQFYG548ehOgcA4AoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCAQCgUAgEAgEAoFAIBAIBAKBQCAQCC4e3XVJIDBG9QmyKhAY4+Li7HmBwBirx2bPCgTGOTH3g0BgHIFAIBAI6kDOXPEFoDLbn7l0bG53+YuwyS3OPTsz2oVjs3etLs49OM65T5/c9fNHj7z044cPvwrTbvQsj57p0rP+r3NfPnP733GYmZmZmZmZmZmZmZmZmZnZf5uZ+QsdP8v10G4AYgAAAABJRU5ErkJggg==";
|
||||||
|
|
||||||
|
|||||||
@@ -46,5 +46,6 @@ namespace GeekDesk.Control
|
|||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using GeekDesk.Util;
|
using GeekDesk.Util;
|
||||||
using GeekDesk.ViewModel;
|
using GeekDesk.ViewModel;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
@@ -58,17 +59,24 @@ namespace GeekDesk.Control
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void EditImage(object sender, RoutedEventArgs e)
|
private void EditImage(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
OpenFileDialog ofd = new OpenFileDialog
|
try
|
||||||
{
|
{
|
||||||
Multiselect = false, //只允许选中单个文件
|
OpenFileDialog ofd = new OpenFileDialog
|
||||||
Filter = "所有文件(*.*)|*.*"
|
{
|
||||||
};
|
Multiselect = false, //只允许选中单个文件
|
||||||
if (ofd.ShowDialog() == true)
|
Filter = "所有文件(*.*)|*.*"
|
||||||
|
};
|
||||||
|
if (ofd.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
IconInfo info = this.DataContext as IconInfo;
|
||||||
|
info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
|
||||||
|
CommonCode.SaveAppData(MainWindow.appData);
|
||||||
|
}
|
||||||
|
} catch (Exception)
|
||||||
{
|
{
|
||||||
IconInfo info = this.DataContext as IconInfo;
|
HandyControl.Controls.Growl.WarningGlobal("修改图标失败,已重置为默认图标!");
|
||||||
info.BitmapImage = ImageUtil.GetBitmapIconByPath(ofd.FileName);
|
|
||||||
CommonCode.SaveAppData(MainWindow.appData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
<hc:UniformSpacingPanel Spacing="10" Margin="40,199.5,-40,-189.5" Grid.ColumnSpan="4">
|
<hc:UniformSpacingPanel Spacing="10" Margin="40,199.5,-40,-189.5" Grid.ColumnSpan="4">
|
||||||
<TextBlock Text="图片路径:" VerticalAlignment="Center"/>
|
<TextBlock Text="图片路径:" VerticalAlignment="Center"/>
|
||||||
<TextBlock Text="{Binding BacImgName}" Width="200" VerticalAlignment="Center"/>
|
<TextBlock Text="{Binding BacImgName}" Width="200" VerticalAlignment="Center"/>
|
||||||
<Button Content="修改" Click="Button_Click"/>
|
<Button Content="修改" Click="BGButton_Click"/>
|
||||||
</hc:UniformSpacingPanel>
|
</hc:UniformSpacingPanel>
|
||||||
<hc:Divider LineStrokeDashArray="3,3" Margin="30,22,450,119" LineStroke="Black" Grid.ColumnSpan="4"/>
|
<hc:Divider LineStrokeDashArray="3,3" Margin="30,22,450,119" LineStroke="Black" Grid.ColumnSpan="4"/>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using GeekDesk.Util;
|
using GeekDesk.Util;
|
||||||
|
using GeekDesk.ViewModel;
|
||||||
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -36,8 +38,30 @@ namespace GeekDesk.Control.UserControls
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
/// <summary>
|
||||||
|
/// 修改背景图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void BGButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
AppConfig appConfig = MainWindow.appData.AppConfig;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OpenFileDialog ofd = new OpenFileDialog
|
||||||
|
{
|
||||||
|
Multiselect = false, //只允许选中单个文件
|
||||||
|
Filter = "图像文件(*.png, *.jpg)|*.png;*.jpg;*.gif"
|
||||||
|
};
|
||||||
|
if (ofd.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
appConfig.BitmapImage = ImageUtil.GetBitmapImageByFile(ofd.FileName);
|
||||||
|
}
|
||||||
|
} catch (Exception)
|
||||||
|
{
|
||||||
|
HandyControl.Controls.Growl.WarningGlobal("修改背景失败,已重置为默认背景!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,9 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Apex.WinForms, Version=1.6.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\SharpShellTools.2.2.0.0\lib\Apex.WinForms.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="CommonServiceLocator, Version=2.0.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
|
<Reference Include="CommonServiceLocator, Version=2.0.6.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\CommonServiceLocator.2.0.6\lib\net45\CommonServiceLocator.dll</HintPath>
|
<HintPath>packages\CommonServiceLocator.2.0.6\lib\net45\CommonServiceLocator.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -53,12 +56,23 @@
|
|||||||
<Reference Include="HandyControl, Version=3.1.0.0, Culture=neutral, PublicKeyToken=45be8712787a1e5b, processorArchitecture=MSIL">
|
<Reference Include="HandyControl, Version=3.1.0.0, Culture=neutral, PublicKeyToken=45be8712787a1e5b, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\HandyControl.3.1.0\lib\net452\HandyControl.dll</HintPath>
|
<HintPath>packages\HandyControl.3.1.0\lib\net452\HandyControl.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="ServerManager, Version=2.2.0.0, Culture=neutral, processorArchitecture=x86">
|
||||||
|
<HintPath>packages\SharpShellTools.2.2.0.0\lib\ServerManager.exe</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="SharpShell, Version=2.2.0.0, Culture=neutral, PublicKeyToken=f14dc899472fe6fb, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\SharpShellTools.2.2.0.0\lib\SharpShell.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="srm, Version=2.2.0.0, Culture=neutral, PublicKeyToken=68bd4561cc3495fc, processorArchitecture=MSIL">
|
||||||
|
<HintPath>packages\SharpShellTools.2.2.0.0\lib\srm.exe</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Drawing.Common, Version=4.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Drawing.Common, Version=4.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\System.Drawing.Common.6.0.0-preview.3.21201.4\lib\net461\System.Drawing.Common.dll</HintPath>
|
<HintPath>packages\System.Drawing.Common.6.0.0-preview.3.21201.4\lib\net461\System.Drawing.Common.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<HintPath>packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
|
<HintPath>packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -82,7 +96,6 @@
|
|||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="Command\DelegateCommand.cs" />
|
<Compile Include="Command\DelegateCommand.cs" />
|
||||||
<Compile Include="Command\DelegateCommandBase.cs" />
|
<Compile Include="Command\DelegateCommandBase.cs" />
|
||||||
<Compile Include="Constant\AppConstant.cs" />
|
|
||||||
<Compile Include="Constant\AppHideType.cs" />
|
<Compile Include="Constant\AppHideType.cs" />
|
||||||
<Compile Include="Constant\Constants.cs" />
|
<Compile Include="Constant\Constants.cs" />
|
||||||
<Compile Include="Constant\DefaultConstant.cs" />
|
<Compile Include="Constant\DefaultConstant.cs" />
|
||||||
@@ -113,6 +126,7 @@
|
|||||||
<Compile Include="Util\MouseUtil.cs" />
|
<Compile Include="Util\MouseUtil.cs" />
|
||||||
<Compile Include="Util\MouseUtilities.cs" />
|
<Compile Include="Util\MouseUtilities.cs" />
|
||||||
<Compile Include="Util\ScreenUtil.cs" />
|
<Compile Include="Util\ScreenUtil.cs" />
|
||||||
|
<Compile Include="Util\ShellContextMenu.cs" />
|
||||||
<Compile Include="Util\SystemIcon.cs" />
|
<Compile Include="Util\SystemIcon.cs" />
|
||||||
<Compile Include="ViewModel\AppConfig.cs" />
|
<Compile Include="ViewModel\AppConfig.cs" />
|
||||||
<Compile Include="ViewModel\AppData.cs" />
|
<Compile Include="ViewModel\AppData.cs" />
|
||||||
|
|||||||
@@ -3,15 +3,16 @@ using GeekDesk.Constant;
|
|||||||
using GeekDesk.Control;
|
using GeekDesk.Control;
|
||||||
using GeekDesk.Util;
|
using GeekDesk.Util;
|
||||||
using GeekDesk.ViewModel;
|
using GeekDesk.ViewModel;
|
||||||
|
using SharpShell.SharpContextMenu;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace GeekDesk
|
namespace GeekDesk
|
||||||
{
|
{
|
||||||
@@ -216,7 +217,7 @@ namespace GeekDesk
|
|||||||
p.Start();
|
p.Start();
|
||||||
icon.Count++;
|
icon.Count++;
|
||||||
} catch (Exception)
|
} catch (Exception)
|
||||||
{
|
{
|
||||||
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
|
HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,7 +447,7 @@ namespace GeekDesk
|
|||||||
private void ShowAppAndFollowMouse()
|
private void ShowAppAndFollowMouse()
|
||||||
{
|
{
|
||||||
//获取鼠标位置
|
//获取鼠标位置
|
||||||
Point p = MouseUtil.GetMousePosition();
|
System.Windows.Point p = MouseUtil.GetMousePosition();
|
||||||
double left = SystemParameters.VirtualScreenLeft;
|
double left = SystemParameters.VirtualScreenLeft;
|
||||||
double top = SystemParameters.VirtualScreenTop;
|
double top = SystemParameters.VirtualScreenTop;
|
||||||
double width = SystemParameters.VirtualScreenWidth;
|
double width = SystemParameters.VirtualScreenWidth;
|
||||||
@@ -550,7 +551,10 @@ namespace GeekDesk
|
|||||||
|
|
||||||
private void MenuItem_Click(object sender, RoutedEventArgs e)
|
private void MenuItem_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
|
||||||
|
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
|
||||||
|
psi.Arguments = "/e,/select," + icon.Path;
|
||||||
|
System.Diagnostics.Process.Start(psi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -18,16 +18,16 @@ namespace GeekDesk.Util
|
|||||||
public static AppData GetAppDataByFile()
|
public static AppData GetAppDataByFile()
|
||||||
{
|
{
|
||||||
AppData appData;
|
AppData appData;
|
||||||
if (!File.Exists(AppConstant.DATA_FILE_PATH))
|
if (!File.Exists(Constants.DATA_FILE_PATH))
|
||||||
{
|
{
|
||||||
using (FileStream fs = File.Create(AppConstant.DATA_FILE_PATH)) { }
|
using (FileStream fs = File.Create(Constants.DATA_FILE_PATH)) { }
|
||||||
appData = new AppData();
|
appData = new AppData();
|
||||||
SaveAppData(appData);
|
SaveAppData(appData);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Open))
|
using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Open))
|
||||||
{
|
{
|
||||||
BinaryFormatter bf = new BinaryFormatter();
|
BinaryFormatter bf = new BinaryFormatter();
|
||||||
appData = bf.Deserialize(fs) as AppData;
|
appData = bf.Deserialize(fs) as AppData;
|
||||||
@@ -43,7 +43,7 @@ namespace GeekDesk.Util
|
|||||||
public static void SaveAppData(AppData appData)
|
public static void SaveAppData(AppData appData)
|
||||||
{
|
{
|
||||||
|
|
||||||
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Create))
|
using (FileStream fs = new FileStream(Constants.DATA_FILE_PATH, FileMode.Create))
|
||||||
{
|
{
|
||||||
BinaryFormatter bf = new BinaryFormatter();
|
BinaryFormatter bf = new BinaryFormatter();
|
||||||
bf.Serialize(fs, appData);
|
bf.Serialize(fs, appData);
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
using GeekDesk.Constant;
|
using GeekDesk.Constant;
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Interop;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace GeekDesk.Util
|
namespace GeekDesk.Util
|
||||||
@@ -66,7 +69,7 @@ namespace GeekDesk.Util
|
|||||||
{
|
{
|
||||||
if (IsImage(filePath)) {
|
if (IsImage(filePath)) {
|
||||||
//图片
|
//图片
|
||||||
return GetThumbnail(filePath, 256, 256);
|
return GetThumbnailByFile(filePath, 256, 256);
|
||||||
} else
|
} else
|
||||||
{ //其它文件
|
{ //其它文件
|
||||||
return FileIcon.GetBitmapImage(filePath);
|
return FileIcon.GetBitmapImage(filePath);
|
||||||
@@ -86,47 +89,128 @@ namespace GeekDesk.Util
|
|||||||
/// <param name="lnWidth">缩略图的宽度</param>
|
/// <param name="lnWidth">缩略图的宽度</param>
|
||||||
/// <param name="lnHeight">缩略图的高度</param>
|
/// <param name="lnHeight">缩略图的高度</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static BitmapImage GetThumbnail(string lcFilename, int lnWidth, int lnHeight)
|
//public static BitmapImage GetThumbnail(string lcFilename, int lnWidth, int lnHeight)
|
||||||
|
//{
|
||||||
|
// Bitmap bmpOut = null;
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// Bitmap loBMP = new Bitmap(lcFilename);
|
||||||
|
// ImageFormat loFormat = loBMP.RawFormat;
|
||||||
|
|
||||||
|
// decimal lnRatio;
|
||||||
|
// int lnNewWidth = 0;
|
||||||
|
// int lnNewHeight = 0;
|
||||||
|
|
||||||
|
// //如果图像小于缩略图直接返回原图,因为upfront
|
||||||
|
// if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
|
||||||
|
// return BitmapToBitmapImage(loBMP);
|
||||||
|
// if (loBMP.Width > loBMP.Height)
|
||||||
|
// {
|
||||||
|
// lnRatio = (decimal)lnWidth / loBMP.Width;
|
||||||
|
// lnNewWidth = lnWidth;
|
||||||
|
// decimal lnTemp = loBMP.Height * lnRatio;
|
||||||
|
// lnNewHeight = (int)lnTemp;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// lnRatio = (decimal)lnHeight / loBMP.Height;
|
||||||
|
// lnNewHeight = lnHeight;
|
||||||
|
// decimal lnTemp = loBMP.Width * lnRatio;
|
||||||
|
// lnNewWidth = (int)lnTemp;
|
||||||
|
// }
|
||||||
|
// bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
|
||||||
|
// Graphics g = Graphics.FromImage(bmpOut);
|
||||||
|
// g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||||
|
// g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
|
||||||
|
// g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
|
||||||
|
// loBMP.Dispose();
|
||||||
|
// }
|
||||||
|
// catch (Exception e)
|
||||||
|
// {
|
||||||
|
// return Base64ToBitmapImage(Constants.DEFAULT_IMG_IMAGE_BASE64);
|
||||||
|
// }
|
||||||
|
// return BitmapToBitmapImage(bmpOut);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public static BitmapImage GetThumbnailByFile(string filePath, int tWidth, int tHeight)
|
||||||
{
|
{
|
||||||
Bitmap bmpOut = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Bitmap loBMP = new Bitmap(lcFilename);
|
Image img = Image.FromFile(filePath);
|
||||||
ImageFormat loFormat = loBMP.RawFormat;
|
if (img.Width <= tWidth && img.Height <= tHeight)
|
||||||
|
|
||||||
decimal lnRatio;
|
|
||||||
int lnNewWidth = 0;
|
|
||||||
int lnNewHeight = 0;
|
|
||||||
|
|
||||||
//如果图像小于缩略图直接返回原图,因为upfront
|
|
||||||
if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)
|
|
||||||
return BitmapToBitmapImage(bmpOut);
|
|
||||||
if (loBMP.Width > loBMP.Height)
|
|
||||||
{
|
{
|
||||||
lnRatio = (decimal)lnWidth / loBMP.Width;
|
return GetBitmapImageByFile(filePath);
|
||||||
lnNewWidth = lnWidth;
|
|
||||||
decimal lnTemp = loBMP.Height * lnRatio;
|
|
||||||
lnNewHeight = (int)lnTemp;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lnRatio = (decimal)lnHeight / loBMP.Height;
|
Bitmap loBMP = new Bitmap(filePath);
|
||||||
lnNewHeight = lnHeight;
|
ImageFormat loFormat = loBMP.RawFormat;
|
||||||
decimal lnTemp = loBMP.Width * lnRatio;
|
|
||||||
lnNewWidth = (int)lnTemp;
|
decimal lnRatio;
|
||||||
|
int lnNewWidth;
|
||||||
|
int lnNewHeight;
|
||||||
|
if (loBMP.Width > loBMP.Height)
|
||||||
|
{
|
||||||
|
lnRatio = (decimal)tWidth / loBMP.Width;
|
||||||
|
lnNewWidth = tWidth;
|
||||||
|
decimal lnTemp = loBMP.Height * lnRatio;
|
||||||
|
lnNewHeight = (int)lnTemp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lnRatio = (decimal)tHeight / loBMP.Height;
|
||||||
|
lnNewHeight = tHeight;
|
||||||
|
decimal lnTemp = loBMP.Width * lnRatio;
|
||||||
|
lnNewWidth = (int)lnTemp;
|
||||||
|
}
|
||||||
|
Bitmap bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
|
||||||
|
Graphics g = Graphics.FromImage(bmpOut);
|
||||||
|
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||||
|
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
|
||||||
|
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
|
||||||
|
loBMP.Dispose();
|
||||||
|
string tempPath = Constants.APP_DIR + "\\temp";
|
||||||
|
if (File.Exists(tempPath))
|
||||||
|
{
|
||||||
|
File.Delete(tempPath);
|
||||||
|
}
|
||||||
|
bmpOut.Save(tempPath, loFormat);
|
||||||
|
BitmapImage bm = GetBitmapImageByFile(tempPath);
|
||||||
|
File.Delete(tempPath);
|
||||||
|
return bm;
|
||||||
}
|
}
|
||||||
bmpOut = new Bitmap(lnNewWidth, lnNewHeight);
|
|
||||||
Graphics g = Graphics.FromImage(bmpOut);
|
|
||||||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
|
||||||
g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
|
|
||||||
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
|
|
||||||
loBMP.Dispose();
|
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return Base64ToBitmapImage(Constants.DEFAULT_IMG_IMAGE_BASE64);
|
return Base64ToBitmapImage(Constants.DEFAULT_IMG_IMAGE_BASE64);
|
||||||
}
|
}
|
||||||
return BitmapToBitmapImage(bmpOut);
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static BitmapImage GetBitmapImageByFile(string filePath)
|
||||||
|
{
|
||||||
|
BitmapImage bmImg = new BitmapImage();
|
||||||
|
bmImg.BeginInit();
|
||||||
|
bmImg.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||||
|
{
|
||||||
|
bmImg.StreamSource = fs;
|
||||||
|
bmImg.EndInit();
|
||||||
|
}
|
||||||
|
return bmImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BitmapImage MemoryStremToBitMapImage(MemoryStream ms)
|
||||||
|
{
|
||||||
|
BitmapImage bi = new BitmapImage();
|
||||||
|
bi.BeginInit();
|
||||||
|
bi.StreamSource = ms;
|
||||||
|
bi.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
|
bi.EndInit();
|
||||||
|
bi.Freeze();
|
||||||
|
return bi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,12 +219,24 @@ namespace GeekDesk.Util
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bitmap"></param>
|
/// <param name="bitmap"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
|
public static BitmapImage BitmapToBitmapImage(Bitmap bitmap)
|
||||||
|
{
|
||||||
|
return BitmapToBitmapImage(bitmap, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BitmapImage BitmapToBitmapImage(Image bitmap, ImageFormat format)
|
||||||
{
|
{
|
||||||
BitmapImage bitmapImage = new BitmapImage();
|
BitmapImage bitmapImage = new BitmapImage();
|
||||||
using (MemoryStream ms = new MemoryStream())
|
using (MemoryStream ms = new MemoryStream())
|
||||||
{
|
{
|
||||||
bitmap.Save(ms, bitmap.RawFormat);
|
if (format == null)
|
||||||
|
{
|
||||||
|
bitmap.Save(ms, bitmap.RawFormat);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bitmap.Save(ms, format);
|
||||||
|
}
|
||||||
bitmapImage.BeginInit();
|
bitmapImage.BeginInit();
|
||||||
bitmapImage.StreamSource = ms;
|
bitmapImage.StreamSource = ms;
|
||||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
@@ -150,6 +246,29 @@ namespace GeekDesk.Util
|
|||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
|
||||||
|
public static extern bool DeleteObject(IntPtr hObject);
|
||||||
|
|
||||||
|
public static BitmapImage Bitmap2BitmapImage(Bitmap bitmap)
|
||||||
|
{
|
||||||
|
IntPtr hBitmap = bitmap.GetHbitmap();
|
||||||
|
BitmapImage retval;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
retval = (BitmapImage)Imaging.CreateBitmapSourceFromHBitmap(
|
||||||
|
hBitmap,
|
||||||
|
IntPtr.Zero,
|
||||||
|
Int32Rect.Empty,
|
||||||
|
BitmapSizeOptions.FromEmptyOptions());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DeleteObject(hBitmap);
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 图片文件转base64
|
/// 图片文件转base64
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
23
Util/ShellContextMenu.cs
Normal file
23
Util/ShellContextMenu.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using SharpShell.SharpContextMenu;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace GeekDesk.Util
|
||||||
|
{
|
||||||
|
class ShellContextMenu : SharpContextMenu
|
||||||
|
{
|
||||||
|
protected override bool CanShowMenu()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ContextMenuStrip CreateMenu()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,5 +3,7 @@
|
|||||||
<package id="CommonServiceLocator" version="2.0.6" targetFramework="net452" requireReinstallation="true" />
|
<package id="CommonServiceLocator" version="2.0.6" targetFramework="net452" requireReinstallation="true" />
|
||||||
<package id="HandyControl" version="3.1.0" targetFramework="net452" requireReinstallation="true" />
|
<package id="HandyControl" version="3.1.0" targetFramework="net452" requireReinstallation="true" />
|
||||||
<package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net472" />
|
<package id="MvvmLightLibs" version="5.4.1.1" targetFramework="net472" />
|
||||||
|
<package id="SharpShell" version="2.7.2" targetFramework="net472" />
|
||||||
|
<package id="SharpShellTools" version="2.2.0.0" targetFramework="net472" />
|
||||||
<package id="System.Drawing.Common" version="6.0.0-preview.3.21201.4" targetFramework="net472" />
|
<package id="System.Drawing.Common" version="6.0.0-preview.3.21201.4" targetFramework="net472" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user