mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-29 12:43:24 +08:00
缩略图优化
This commit is contained in:
@@ -114,7 +114,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
|||||||
|
|
||||||
protected override DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType, bool initNew)
|
protected override DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType, bool initNew)
|
||||||
{
|
{
|
||||||
var viewmodel = new MindDiagramViewModel() { Name = name ?? NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType, MindType = MindType, MindTheme = MindTheme };
|
var viewmodel = new MindDiagramViewModel() { Name = name ?? NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType, MindType = MindType, MindTheme = MindTheme, GenerateThumbnail = true };
|
||||||
viewmodel.Init(initNew);
|
viewmodel.Init(initNew);
|
||||||
|
|
||||||
return viewmodel;
|
return viewmodel;
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
|||||||
if (_diagramViewModel != null)
|
if (_diagramViewModel != null)
|
||||||
{
|
{
|
||||||
_diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
|
_diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,12 +468,12 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
|||||||
|
|
||||||
protected virtual DiagramViewModel GetDiagramViewModel(DiagramItem diagramItem, string ext)
|
protected virtual DiagramViewModel GetDiagramViewModel(DiagramItem diagramItem, string ext)
|
||||||
{
|
{
|
||||||
return new BlockDiagramViewModel(diagramItem, ext);
|
return new BlockDiagramViewModel(diagramItem, ext) { GenerateThumbnail = true};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType, bool initNew)
|
protected virtual DiagramViewModel GetDiagramViewModel(string name, DiagramType diagramType, bool initNew)
|
||||||
{
|
{
|
||||||
return new BlockDiagramViewModel() { Name = name ?? NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType };
|
return new BlockDiagramViewModel() { Name = name ?? NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-"), DiagramType = diagramType,GenerateThumbnail = true };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCopyPageExecuted(object para)
|
public void AddCopyPageExecuted(object para)
|
||||||
|
|||||||
@@ -524,7 +524,7 @@
|
|||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Grid >
|
<Grid >
|
||||||
<Border Margin="3" Height="100" Background="{Binding Thumbnail}" BorderThickness="1" BorderBrush="LightGray">
|
<Border Margin="3" Height="100" Background="{Binding Thumbnail}" RenderOptions.BitmapScalingMode="HighQuality" BorderThickness="1" BorderBrush="LightGray">
|
||||||
<Border.ContextMenu>
|
<Border.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="增加页" Command="{binding:ControlBinding PageViewModel.AddPageCommand}" CommandParameter="{Binding .}"/>
|
<MenuItem Header="增加页" Command="{binding:ControlBinding PageViewModel.AddPageCommand}" CommandParameter="{Binding .}"/>
|
||||||
|
|||||||
@@ -302,12 +302,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
|
|
||||||
if (e.OldValue is IDiagramViewModel oldvalue)
|
if (e.OldValue is IDiagramViewModel oldvalue)
|
||||||
{
|
{
|
||||||
//var image = this.ToBitmap().ToBitmapSource();
|
|
||||||
//oldvalue.Thumbnail = new ImageBrush(image) { Stretch = Stretch.Uniform };
|
|
||||||
}
|
}
|
||||||
if (e.NewValue is IDiagramViewModel newvalue)
|
if (e.NewValue is IDiagramViewModel newvalue)
|
||||||
{
|
{
|
||||||
newvalue.Thumbnail = new VisualBrush(this) { Stretch = Stretch.Uniform };
|
if (newvalue.GenerateThumbnail)
|
||||||
|
newvalue.Thumbnail = new VisualBrush(this) { Stretch = Stretch.Uniform };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
{
|
{
|
||||||
var bitmapImage = base64String.ToBitmapImage(width, height);
|
var bitmapImage = base64String.ToBitmapImage(width, height);
|
||||||
|
|
||||||
return new System.Windows.Media.ImageBrush(bitmapImage) { Stretch = System.Windows.Media.Stretch.Uniform };
|
var brush = new System.Windows.Media.ImageBrush(bitmapImage) { Stretch = System.Windows.Media.Stretch.Uniform };
|
||||||
|
//brush.SetCurrentValue(System.Windows.Media.RenderOptions.BitmapScalingModeProperty, System.Windows.Media.BitmapScalingMode.HighQuality);
|
||||||
|
|
||||||
|
return brush;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
PageBackground = diagramView.DiagramOption.LayoutOption.PageBackground;
|
PageBackground = diagramView.DiagramOption.LayoutOption.PageBackground;
|
||||||
AllowDrop = diagramView.DiagramOption.LayoutOption.AllowDrop;
|
AllowDrop = diagramView.DiagramOption.LayoutOption.AllowDrop;
|
||||||
|
|
||||||
Thumbnail = diagramView.Thumbnail.ToBase64String();
|
Thumbnail = diagramView.Thumbnail?.ToBase64String();
|
||||||
|
|
||||||
var selectedDesignerItems = diagramView.Items.OfType<DesignerItemViewModelBase>();
|
var selectedDesignerItems = diagramView.Items.OfType<DesignerItemViewModelBase>();
|
||||||
var selectedConnections = diagramView.Items.OfType<ConnectionViewModel>();
|
var selectedConnections = diagramView.Items.OfType<ConnectionViewModel>();
|
||||||
|
|||||||
@@ -346,6 +346,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool GenerateThumbnail
|
||||||
|
{
|
||||||
|
get;set;
|
||||||
|
}
|
||||||
|
|
||||||
public bool ShowMenuOptions
|
public bool ShowMenuOptions
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -873,7 +878,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
DiagramOption.LayoutOption.PageBackground = diagramItem.PageBackground;
|
DiagramOption.LayoutOption.PageBackground = diagramItem.PageBackground;
|
||||||
DiagramOption.LayoutOption.AllowDrop = diagramItem.AllowDrop;
|
DiagramOption.LayoutOption.AllowDrop = diagramItem.AllowDrop;
|
||||||
|
|
||||||
Thumbnail = diagramItem.Thumbnail.ToBrush((int)DiagramOption.LayoutOption.PageSize.Width / 4, (int)DiagramOption.LayoutOption.PageSize.Height / 4);
|
Thumbnail = diagramItem.Thumbnail?.ToBrush((int)DiagramOption.LayoutOption.PageSize.Width, (int)DiagramOption.LayoutOption.PageSize.Height);
|
||||||
Init(true);
|
Init(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1025,11 +1030,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
|
|
||||||
public void SaveThumbnail()
|
public void SaveThumbnail()
|
||||||
{
|
{
|
||||||
if (Thumbnail is VisualBrush visualBrush)
|
if (GenerateThumbnail)
|
||||||
{
|
{
|
||||||
var size = ((UIElement)visualBrush.Visual).DesiredSize;
|
if (Thumbnail is VisualBrush visualBrush)
|
||||||
var image = visualBrush.ToBitmap(new Rect(size)).ToBitmapSource((int)size.Width / 4, (int)size.Height / 4);
|
{
|
||||||
Thumbnail = new ImageBrush(image) { Stretch = Stretch.Uniform };
|
var size = ((UIElement)visualBrush.Visual).DesiredSize;
|
||||||
|
var image = visualBrush.ToBitmap(new Rect(size)).ToBitmapSource((int)size.Width, (int)size.Height);
|
||||||
|
var brush = new ImageBrush(image) { Stretch = Stretch.Uniform };
|
||||||
|
//brush.SetCurrentValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
|
||||||
|
Thumbnail = brush;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -294,6 +294,10 @@ namespace AIStudio.Wpf.DiagramDesigner
|
|||||||
{
|
{
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
|
bool GenerateThumbnail
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
}
|
||||||
#region 如果这个赋值了,优先用这个的
|
#region 如果这个赋值了,优先用这个的
|
||||||
IDrawModeViewModel DrawModeViewModel
|
IDrawModeViewModel DrawModeViewModel
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user