Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VIZ.Package
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘龙飞
VIZ.Package
Commits
21ab2fd1
Commit
21ab2fd1
authored
Feb 17, 2023
by
liulongfei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://49.233.21.66/liulongfei/VIZ.Package
parents
3e43799f
b5d858a0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
661 additions
and
3 deletions
+661
-3
VIZ.Package.Module/Resource/MediaResource/Controller/MediaResourceFileController.cs
+21
-0
VIZ.Package.Module/Resource/MediaResource/Controller/MediaResourceFileService.cs
+36
-1
VIZ.Package.Module/Resource/MediaResource/Controller/ThumbnailHelper.cs
+33
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealer.xaml
+10
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealer.xaml.cs
+146
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealerUnsafe.xaml
+29
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealerUnsafe.xaml.cs
+0
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEdit.xaml
+66
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEdit.xaml.cs
+52
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEditWindow.xaml
+14
-0
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEditWindow.xaml.cs
+28
-0
VIZ.Package.Module/Resource/MediaResource/View/MediaResourceView.xaml
+1
-1
VIZ.Package.Module/Resource/MediaResource/ViewModel/ImageEditViewModel.cs
+134
-0
VIZ.Package.Module/Resource/MediaResource/ViewModel/MediaResourcePanelViewModel.cs
+62
-1
VIZ.Package.Module/VIZ.Package.Module.csproj
+29
-0
No files found.
VIZ.Package.Module/Resource/MediaResource/Controller/MediaResourceFileController.cs
View file @
21ab2fd1
...
...
@@ -198,6 +198,27 @@ namespace VIZ.Package.Module
}
/// <summary>
/// 创建截图文件
/// </summary>
/// <param name="filePath"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public
async
Task
<
fileUploadResult
>
CreateCutImageFile
(
Bitmap
bitmap
,
string
fileName
)
{
string
requestUri
=
string
.
Format
(
"{0}UplodFile?filePath={1}"
,
ApplicationDomainEx
.
MediaConfig
.
Url
,
this
.
Support
.
SelectedFolderModel
.
Path
+
"\\"
);
fileUploadResult
upLoadResult
=
await
MediaResourceFileService
.
PostCutImage
<
fileUploadResult
>(
requestUri
,
bitmap
,
fileName
);
if
(
upLoadResult
==
null
)
return
null
;
return
upLoadResult
;
}
/// <summary>
/// 删除文件
/// </summary>
...
...
VIZ.Package.Module/Resource/MediaResource/Controller/MediaResourceFileService.cs
View file @
21ab2fd1
...
...
@@ -3,11 +3,13 @@ using log4net;
using
Newtonsoft.Json
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Net.Http
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Shapes
;
namespace
VIZ.Package.Module
{
...
...
@@ -178,7 +180,7 @@ namespace VIZ.Package.Module
var
content
=
new
MultipartFormDataContent
();
content
.
Headers
.
Add
(
"ContentType"
,
$"multipart/form-data"
);
var
b
=
new
ByteArrayContent
(
System
.
IO
.
File
.
ReadAllBytes
(
path
));
content
.
Add
(
new
ByteArrayContent
(
System
.
IO
.
File
.
ReadAllBytes
(
path
))
,
"image"
,
fileName
);
content
.
Add
(
b
,
"image"
,
fileName
);
var
response
=
await
client
.
PostAsync
(
requestUri
,
content
);
var
result
=
response
.
Content
.
ReadAsStringAsync
().
Result
;
...
...
@@ -191,5 +193,38 @@ namespace VIZ.Package.Module
}
}
/// <summary>
/// 上传截图图片
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="requestUri"></param>
/// <param name="bitmap"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public
static
async
Task
<
T
>
PostCutImage
<
T
>(
string
requestUri
,
Bitmap
bitmap
,
string
fileName
)
{
try
{
HttpClient
client
=
new
HttpClient
();
var
content
=
new
MultipartFormDataContent
();
content
.
Headers
.
Add
(
"ContentType"
,
$"multipart/form-data"
);
var
b
=
ThumbnailHelper
.
BitmapToGrayByte
(
bitmap
);
content
.
Add
(
new
ByteArrayContent
(
b
),
"image"
,
fileName
);
var
response
=
await
client
.
PostAsync
(
requestUri
,
content
);
var
result
=
response
.
Content
.
ReadAsStringAsync
().
Result
;
return
JsonConvert
.
DeserializeObject
<
T
>(
result
);
}
catch
(
Exception
ex
)
{
log
.
Error
(
ex
.
Message
);
return
default
(
T
);
}
}
}
}
VIZ.Package.Module/Resource/MediaResource/Controller/ThumbnailHelper.cs
View file @
21ab2fd1
...
...
@@ -2,8 +2,10 @@
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
System.Text
;
using
System.Threading.Tasks
;
...
...
@@ -199,6 +201,37 @@ namespace VIZ.Package.Module
// 最后一个反斜杠后返回名称
return
path
.
Substring
(
lastIndex
+
1
);
}
/// <summary>
/// byte数组转换
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public
static
byte
[]
BitmapToGrayByte
(
Bitmap
bitmap
)
{
//// 申请目标位图的变量,并将其内存区域锁定
//BitmapData bitmapDat = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
//// 获取bmpData的内存起始位置
//IntPtr intPtr = bitmapDat.Scan0;
//byte[] image = new byte[bitmap.Width * bitmap.Height];//原始数据
// // 将数据复制到byte数组中,
//Marshal.Copy(intPtr, image, 0, bitmap.Width * bitmap.Height);
////解锁内存区域
//bitmap.UnlockBits(bitmapDat);
//return image;
// 1.先将BitMap转成内存流
System
.
IO
.
MemoryStream
ms
=
new
System
.
IO
.
MemoryStream
();
bitmap
.
Save
(
ms
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
ms
.
Seek
(
0
,
System
.
IO
.
SeekOrigin
.
Begin
);
// 2.再将内存流转成byte[]并返回
byte
[]
bytes
=
new
byte
[
ms
.
Length
];
ms
.
Read
(
bytes
,
0
,
bytes
.
Length
);
ms
.
Dispose
();
return
bytes
;
}
#
endregion
}
}
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealer.xaml
0 → 100644
View file @
21ab2fd1
<UserControl x:Class="VIZ.Package.Module.ImageDealer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Name="MainGrid" MinHeight="200" MinWidth="200" >
</Grid>
</UserControl>
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealer.xaml.cs
0 → 100644
View file @
21ab2fd1
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
System.Windows.Documents
;
using
System.Windows.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
namespace
VIZ.Package.Module
{
/// <summary>
/// Interaction logic for ImageDealer.xaml
/// </summary>
public
partial
class
ImageDealer
:
UserControl
{
public
static
readonly
RoutedEvent
OnCutImagingEventHandler
=
EventManager
.
RegisterRoutedEvent
(
"OnCutImaging"
,
RoutingStrategy
.
Bubble
,
typeof
(
RoutedEventHandler
),
typeof
(
ImageDealer
));
#
region
私有字段
/// <summary>
/// 截图控件
/// </summary>
public
ImageDealerUnsafe
_ImageDealerControl
=
new
ImageDealerUnsafe
();
/// <summary>
/// 图片源
/// </summary>
private
BitmapImage
_BitSource
;
private
int
_ChangeMargin
=
1
;
#
endregion
#
region
公共字段
/// <summary>
/// 图片源
/// </summary>
public
BitmapImage
BitSource
{
get
{
return
this
.
_BitSource
;
}
set
{
this
.
_BitSource
=
value
;
this
.
_ImageDealerControl
.
BitSource
=
value
;
LocateInit
();
}
}
/// <summary>
/// 截图事件
/// </summary>
public
event
RoutedEventHandler
OnCutImaging
{
add
{
base
.
AddHandler
(
OnCutImagingEventHandler
,
value
);
}
remove
{
base
.
RemoveHandler
(
OnCutImagingEventHandler
,
value
);
}
}
#
endregion
#
region
==
方法
==
public
ImageDealer
()
{
InitializeComponent
();
this
.
_ImageDealerControl
.
OnCutImage
+=
this
.
OnCutImage
;
this
.
Loaded
+=
UserControl_Loaded
;
}
//外部截图
public
void
CutImage
()
{
if
(
this
.
IsLoaded
==
true
||
this
.
_ImageDealerControl
==
null
)
{
this
.
_ImageDealerControl
.
CutImage
();
}
else
{
throw
new
Exception
(
"尚未创建视图时无法截图!"
);
}
}
//截图控件位置初始化
private
void
LocateInit
()
{
double
Margin
=
1
;
if
(
this
.
_BitSource
!=
null
)
{
double
percent
=
1
;
//根据最小倍率放大截图控件
percent
=
(
this
.
_BitSource
.
PixelHeight
*
1.0
/
this
.
ActualHeight
);
percent
=
percent
<
(
this
.
_BitSource
.
PixelWidth
*
1.0
/
this
.
ActualWidth
)
?
(
this
.
_BitSource
.
PixelWidth
*
1.0
/
this
.
ActualWidth
)
:
percent
;
this
.
_ImageDealerControl
.
Width
=
this
.
_BitSource
.
PixelWidth
*
1.0
/
percent
;
this
.
_ImageDealerControl
.
Height
=
this
.
_BitSource
.
PixelHeight
*
1.0
/
percent
;
//初始化截图方块
this
.
_ImageDealerControl
.
ImageArea
.
Width
=
this
.
_ImageDealerControl
.
ImageArea
.
Height
=
100
+
_ChangeMargin
;
_ChangeMargin
=
-
_ChangeMargin
;
this
.
_ImageDealerControl
.
ImageArea
.
SetValue
(
VerticalAlignmentProperty
,
VerticalAlignment
.
Center
);
this
.
_ImageDealerControl
.
ImageArea
.
SetValue
(
HorizontalAlignmentProperty
,
HorizontalAlignment
.
Center
);
this
.
_ImageDealerControl
.
ImageArea
.
SetValue
(
MarginProperty
,
new
Thickness
(
0
));
//截图控件相对父控件Margin
this
.
_ImageDealerControl
.
Width
-=
2
*
Margin
;
this
.
_ImageDealerControl
.
Height
-=
2
*
Margin
;
this
.
_ImageDealerControl
.
SetValue
(
VerticalAlignmentProperty
,
VerticalAlignment
.
Center
);
this
.
_ImageDealerControl
.
SetValue
(
HorizontalAlignmentProperty
,
HorizontalAlignment
.
Center
);
this
.
_ImageDealerControl
.
SetValue
(
MarginProperty
,
new
Thickness
(
0
));
}
}
#
endregion
#
region
==
事件
==
//截图回调
private
void
OnCutImage
(
BitmapSource
bit
)
{
RaiseEvent
(
new
RoutedEventArgs
(
OnCutImagingEventHandler
,
bit
));
}
//加载完成
private
void
UserControl_Loaded
(
object
sender
,
RoutedEventArgs
e
)
{
if
(
this
.
MainGrid
.
Children
.
Contains
(
this
.
_ImageDealerControl
)
==
false
)
{
this
.
MainGrid
.
Children
.
Add
(
this
.
_ImageDealerControl
);
this
.
_ImageDealerControl
.
Width
=
this
.
ActualWidth
;
this
.
_ImageDealerControl
.
Height
=
this
.
ActualHeight
;
this
.
_ImageDealerControl
.
SetValue
(
VerticalAlignmentProperty
,
VerticalAlignment
.
Center
);
this
.
_ImageDealerControl
.
SetValue
(
HorizontalAlignmentProperty
,
HorizontalAlignment
.
Center
);
this
.
_ImageDealerControl
.
SetValue
(
MarginProperty
,
new
Thickness
(
0
));
}
}
/// <summary> 手动设置范围 </summary>
public
void
setImageAreaParemater
(
double
x
,
double
y
,
double
width
,
double
height
)
{
_ImageDealerControl
.
setImageAreaParemater
(
x
,
y
,
width
,
height
);
}
#
endregion
}
}
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealerUnsafe.xaml
0 → 100644
View file @
21ab2fd1
<UserControl x:Class="VIZ.Package.Module.ImageDealerUnsafe"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Background="Transparent"
SnapsToDevicePixels="True"
PreviewMouseDown="UserControl_MouseDown" PreviewMouseUp="UserControl_MouseUp" MouseLeave="UserControl_MouseLeave" PreviewMouseMove="UserControl_MouseMove"
Loaded="onViewLoad"
>
<Grid Name="MainGrid" >
<Image Name="SoureceImage" Stretch="Uniform"></Image>
<Border Name="ImageArea" BorderBrush="Red" BorderThickness="1,1,1,1" Panel.ZIndex="5" Margin="50" SizeChanged="ImageArea_SizeChanged">
<Grid >
<Rectangle Name="R_LeftUp" Width="5" Height="5" Margin="-3" VerticalAlignment="Top" HorizontalAlignment="Left" Fill="White" Panel.ZIndex="0" Cursor="SizeNWSE"/>
<Rectangle Name="R_Up" Width="5" Height="5" Margin="-3" VerticalAlignment="Top" HorizontalAlignment="Center" Fill="White" Panel.ZIndex="0" Cursor="SizeNS"/>
<Rectangle Name="R_RightUp" Width="5" Height="5" Margin="-3" VerticalAlignment="Top" HorizontalAlignment="Right" Fill="White" Panel.ZIndex="0" Cursor="SizeNESW"/>
<Rectangle Name="R_Right" Width="5" Height="5" Margin="-3" VerticalAlignment="Center" HorizontalAlignment="Right" Fill="White" Panel.ZIndex="0" Cursor="SizeWE"/>
<Rectangle Name="R_RightDown" Width="5" Height="5" Margin="-3" VerticalAlignment="Bottom" HorizontalAlignment="Right" Fill="White" Panel.ZIndex="0" Cursor="SizeNWSE"/>
<Rectangle Name="R_Down" Width="5" Height="5" Margin="-3" VerticalAlignment="Bottom" HorizontalAlignment="Center" Fill="White" Panel.ZIndex="0" Cursor="SizeNS"/>
<Rectangle Name="R_LeftDown" Width="5" Height="5" Margin="-3" VerticalAlignment="Bottom" HorizontalAlignment="Left" Fill="White" Panel.ZIndex="0" Cursor="SizeNESW"/>
<Rectangle Name="R_Left" Width="5" Height="5" Margin="-3" VerticalAlignment="Center" HorizontalAlignment="Left" Fill="White" Panel.ZIndex="0" Cursor="SizeWE"/>
<!--<GridSplitter Height="5" Width="5" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"></GridSplitter>-->
</Grid>
</Border>
</Grid>
</UserControl>
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageDealerUnsafe.xaml.cs
0 → 100644
View file @
21ab2fd1
This diff is collapsed.
Click to expand it.
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEdit.xaml
0 → 100644
View file @
21ab2fd1
<UserControl x:Class="VIZ.Package.Module.ImageEdit"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:module="clr-namespace:VIZ.Package.Module"
mc:Ignorable="d"
d:DesignHeight="350" d:DesignWidth="525">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<module:ImageDealer Panel.ZIndex="0" x:Name="ImageDealer" Margin="20" OnCutImaging="ImageDealer_OnOnCutImaging">
</module:ImageDealer>
<StackPanel Grid.Column="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="150"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Image Name="CutImage" Grid.Column="1" Margin="5" VerticalAlignment="Top" ></Image>
<WrapPanel Grid.Row="1" VerticalAlignment="Center">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<TextBlock Text="高度:" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock x:Name="txt_Height" Grid.Column="1"/>
</Grid>
</WrapPanel>
<WrapPanel Grid.Row="2" VerticalAlignment="Center">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<TextBlock Text="宽度:" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock x:Name="txt_With" Grid.Column="1"/>
</Grid>
</WrapPanel>
<Button Content="截图" Grid.Row="3" Width="120" Command="{Binding Path=ImageCutCommand}" ></Button>
</Grid>
</StackPanel>
</Grid>
</UserControl>
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEdit.xaml.cs
0 → 100644
View file @
21ab2fd1
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Linq
;
using
System.Text
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
System.Windows.Documents
;
using
System.Windows.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Navigation
;
using
System.Windows.Shapes
;
using
VIZ.Framework.Core
;
namespace
VIZ.Package.Module
{
/// <summary>
/// Interaction logic for ImageEdit.xaml
/// </summary>
public
partial
class
ImageEdit
:
UserControl
{
ImageEditViewModel
vm
=
new
ImageEditViewModel
();
public
ImageEdit
()
{
InitializeComponent
();
WPFHelper
.
BindingViewModel
(
this
,
vm
);
this
.
Loaded
+=
ImageEdit_Loaded
;
}
private
void
ImageEdit_Loaded
(
object
sender
,
RoutedEventArgs
e
)
{
ImageDealer
.
BitSource
=
vm
.
OriginImage
;
}
//private void Button_Click_1(object sender, RoutedEventArgs e)
//{
// ImageDealer.CutImage();
//}
private
void
ImageDealer_OnOnCutImaging
(
object
sender
,
RoutedEventArgs
e
)
{
CutImage
.
Source
=
(
BitmapSource
)
e
.
OriginalSource
;
txt_Height
.
Text
=
CutImage
.
Source
.
Height
.
ToString
();
txt_With
.
Text
=
CutImage
.
Source
.
Width
.
ToString
();
vm
.
CutImage
=
vm
.
ImageSourceToBitmap
(
CutImage
.
Source
);
}
}
}
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEditWindow.xaml
0 → 100644
View file @
21ab2fd1
<dx:ThemedWindow
x:Class="VIZ.Package.Module.ImageEditWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:module="clr-namespace:VIZ.Package.Module"
Title="编辑图片" Height="600" Width="600" >
<Grid>
<module:ImageEdit x:Name="ImageCut">
</module:ImageEdit>
</Grid>
</dx:ThemedWindow>
VIZ.Package.Module/Resource/MediaResource/ImageCut/ImageEditWindow.xaml.cs
0 → 100644
View file @
21ab2fd1
using
DevExpress.Xpf.Core
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Windows
;
using
System.Windows.Controls
;
using
System.Windows.Data
;
using
System.Windows.Documents
;
using
System.Windows.Input
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
System.Windows.Shapes
;
namespace
VIZ.Package.Module
{
/// <summary>
/// Interaction logic for ImageEditWindow.xaml
/// </summary>
public
partial
class
ImageEditWindow
:
ThemedWindow
{
public
ImageEditWindow
()
{
InitializeComponent
();
}
}
}
VIZ.Package.Module/Resource/MediaResource/View/MediaResourceView.xaml
View file @
21ab2fd1
...
...
@@ -27,7 +27,7 @@
<MenuItem Header="移动文件" Command="{Binding Path=PlacementTarget.DataContext.MoveFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<MenuItem Header="导出素材" Command="{Binding Path=PlacementTarget.DataContext.ExportFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
<
!--<MenuItem Header="编辑图片" Command="{Binding Path=PlacementTarget.DataContext.EditImageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>--
>
<
MenuItem Header="编辑图片" Command="{Binding Path=PlacementTarget.DataContext.EditImageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/
>
<Separator/>
<MenuItem Header="文件列表" Command="{Binding Path=PlacementTarget.DataContext.FilesListCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
</ContextMenu>
...
...
VIZ.Package.Module/Resource/MediaResource/ViewModel/ImageEditViewModel.cs
0 → 100644
View file @
21ab2fd1
using
log4net
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Media
;
using
System.Windows.Media.Imaging
;
using
VIZ.Framework.Core
;
namespace
VIZ.Package.Module
{
/// <summary>
/// 绑定
/// </summary>
public
class
ImageEditViewModel
:
ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private
static
readonly
ILog
log
=
LogManager
.
GetLogger
(
typeof
(
ImageEditViewModel
));
public
ImageEditViewModel
()
{
ImageCutCommand
=
new
VCommand
(
this
.
ImageCut
);
}
/// <summary>
/// 截图命令
/// </summary>
public
VCommand
ImageCutCommand
{
get
;
set
;
}
/// <summary>
/// 源图
/// </summary>
public
BitmapImage
OriginImage
{
get
;
set
;
}
/// <summary>
/// 截图
/// </summary>
public
Bitmap
CutImage
{
get
;
set
;
}
private
bool
isEnter
=
false
;
/// <summary>
/// 是否确定
/// </summary>
public
bool
IsEnter
{
get
{
return
isEnter
;
}
set
{
isEnter
=
value
;
this
.
RaisePropertyChanged
(
nameof
(
IsEnter
));
}
}
/// <summary>
/// BitMapImage转Bitmap
/// </summary>
/// <param name="bitmapImage"></param>
/// <returns></returns>
public
Bitmap
BitmapImage2Bitmap
(
BitmapImage
bitmapImage
)
{
using
(
MemoryStream
outStream
=
new
MemoryStream
())
{
BitmapEncoder
enc
=
new
BmpBitmapEncoder
();
enc
.
Frames
.
Add
(
BitmapFrame
.
Create
(
bitmapImage
));
enc
.
Save
(
outStream
);
System
.
Drawing
.
Bitmap
bitmap
=
new
System
.
Drawing
.
Bitmap
(
outStream
);
return
new
Bitmap
(
bitmap
);
}
}
/// <summary>
/// bitmap 转BitmapImage
/// </summary>
/// <param name="bitmap"></param>
/// <returns></returns>
public
BitmapImage
BitmapToBitmapImage
(
System
.
Drawing
.
Bitmap
bitmap
)
{
System
.
Drawing
.
Bitmap
ImageOriginalBase
=
new
System
.
Drawing
.
Bitmap
(
bitmap
);
BitmapImage
bitmapImage
=
new
BitmapImage
();
using
(
System
.
IO
.
MemoryStream
ms
=
new
System
.
IO
.
MemoryStream
())
{
ImageOriginalBase
.
Save
(
ms
,
System
.
Drawing
.
Imaging
.
ImageFormat
.
Png
);
bitmapImage
.
BeginInit
();
bitmapImage
.
StreamSource
=
ms
;
bitmapImage
.
CacheOption
=
BitmapCacheOption
.
OnLoad
;
bitmapImage
.
EndInit
();
bitmapImage
.
Freeze
();
}
return
bitmapImage
;
}
/// <summary>
/// ImageSource转换为Bitmap
/// </summary>
/// <param name="_imagesource"></param>
/// <returns></returns>
public
Bitmap
ImageSourceToBitmap
(
ImageSource
_imagesource
)
{
System
.
IO
.
MemoryStream
ms
=
new
System
.
IO
.
MemoryStream
();
BmpBitmapEncoder
encoder
=
new
BmpBitmapEncoder
();
encoder
.
Frames
.
Add
(
BitmapFrame
.
Create
((
BitmapSource
)
_imagesource
));
encoder
.
Save
(
ms
);
Bitmap
bp
=
new
Bitmap
(
ms
);
ms
.
Close
();
return
bp
;
}
/// <summary>
///截图方法
/// </summary>
private
void
ImageCut
()
{
isEnter
=
true
;
this
.
GetWindow
()?.
Close
();
}
}
}
VIZ.Package.Module/Resource/MediaResource/ViewModel/MediaResourcePanelViewModel.cs
View file @
21ab2fd1
...
...
@@ -9,10 +9,12 @@ using System.Drawing;
using
System.IO
;
using
System.Linq
;
using
System.Net
;
using
System.Security.Cryptography
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Forms
;
using
System.Windows.Shapes
;
using
VIZ.Framework.Core
;
using
VIZ.Package.Domain
;
...
...
@@ -798,9 +800,68 @@ namespace VIZ.Package.Module
/// </summary>
public
VCommand
EditImageCommand
{
get
;
set
;
}
private
void
EditImage
()
private
async
void
EditImage
()
{
if
(
selectedFileModel
==
null
||
selectedFileModel
.
ThumbnailBitmap
==
null
)
return
;
ImageEditWindow
imageEditWindow
=
new
ImageEditWindow
();
ImageEditViewModel
vm
=
imageEditWindow
.
ImageCut
.
DataContext
as
ImageEditViewModel
;
vm
.
OriginImage
=
vm
.
BitmapToBitmapImage
(
selectedFileModel
.
ThumbnailBitmap
);
imageEditWindow
.
ShowDialog
();
if
(
vm
.
IsEnter
)
{
string
fileName
=
string
.
Format
(
"{0}.png"
,
GenerateStringID
());
Bitmap
bp
=
new
Bitmap
(
vm
.
CutImage
);
bool
flag
=
false
;
try
{
var
fileResult
=
await
this
.
mediaResourceFileController
.
CreateCutImageFile
(
bp
,
fileName
);
if
(
fileResult
!=
null
&&
fileResult
.
errCode
==
"0"
)
{
flag
=
true
;
}
else
{
flag
=
false
;
}
}
catch
(
Exception
ex
)
{
log
.
Error
(
ex
.
Message
);
}
if
(
flag
)
{
if
(
this
.
SelectedFolderModel
!=
null
)
{
this
.
mediaResourceFileController
.
UpdateFileModels
(
this
.
SelectedFolderModel
);
}
}
}
}
/// <summary>
/// 随机生成GuID字符串
/// </summary>
/// <returns></returns>
private
string
GenerateStringID
()
{
long
i
=
1
;
foreach
(
byte
b
in
Guid
.
NewGuid
().
ToByteArray
())
{
i
*=
((
int
)
b
+
1
);
}
return
string
.
Format
(
"{0:x}"
,
i
-
DateTime
.
Now
.
Ticks
);
}
#
endregion
...
...
VIZ.Package.Module/VIZ.Package.Module.csproj
View file @
21ab2fd1
...
...
@@ -150,6 +150,19 @@
<Compile Include="Resource\MediaResource\Controller\Model\ms.cs" />
<Compile Include="Resource\MediaResource\Core\MHResourceFileDoubleClickEventArgs.cs" />
<Compile Include="Resource\MediaResource\Core\MHResourceSelectedFileChangedEventArgs.cs" />
<Compile Include="Resource\MediaResource\ImageCut\ImageDealer.xaml.cs">
<DependentUpon>ImageDealer.xaml</DependentUpon>
</Compile>
<Compile Include="Resource\MediaResource\ImageCut\ImageDealerUnsafe.xaml.cs">
<DependentUpon>ImageDealerUnsafe.xaml</DependentUpon>
</Compile>
<Compile Include="Resource\MediaResource\ImageCut\ImageEdit.xaml.cs">
<DependentUpon>ImageEdit.xaml</DependentUpon>
</Compile>
<Compile Include="Resource\MediaResource\ImageCut\ImageEditWindow.xaml.cs">
<DependentUpon>ImageEditWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Resource\MediaResource\ViewModel\ImageEditViewModel.cs" />
<Compile Include="Setting\Conn\View\ConnSettingView.xaml.cs">
<DependentUpon>ConnSettingView.xaml</DependentUpon>
</Compile>
...
...
@@ -431,6 +444,22 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resource\MediaResource\ImageCut\ImageDealer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resource\MediaResource\ImageCut\ImageDealerUnsafe.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resource\MediaResource\ImageCut\ImageEdit.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resource\MediaResource\ImageCut\ImageEditWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Setting\Conn\View\ConnSettingView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment