mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-02 15:50:51 +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)
|
||||
{
|
||||
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);
|
||||
|
||||
return viewmodel;
|
||||
|
||||
@@ -188,6 +188,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
if (_diagramViewModel != null)
|
||||
{
|
||||
_diagramViewModel.PropertyChanged += DiagramViewModel_PropertyChanged;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,12 +468,12 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
@@ -483,7 +484,7 @@ namespace AIStudio.Wpf.DiagramApp.ViewModels
|
||||
DiagramItem diagramItem = new DiagramItem(viewModel);
|
||||
diagramItem.Name = NewNameHelper.GetNewName(DiagramViewModels.Select(p => p.Name), "页-");
|
||||
|
||||
viewModel = GetDiagramViewModel(diagramItem, ".json");
|
||||
viewModel = GetDiagramViewModel(diagramItem, ".json");
|
||||
|
||||
DiagramViewModels.Add(viewModel);
|
||||
DiagramViewModel = viewModel;
|
||||
|
||||
@@ -524,7 +524,7 @@
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<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>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="增加页" Command="{binding:ControlBinding PageViewModel.AddPageCommand}" CommandParameter="{Binding .}"/>
|
||||
|
||||
@@ -302,12 +302,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
PageBackground = diagramView.DiagramOption.LayoutOption.PageBackground;
|
||||
AllowDrop = diagramView.DiagramOption.LayoutOption.AllowDrop;
|
||||
|
||||
Thumbnail = diagramView.Thumbnail.ToBase64String();
|
||||
Thumbnail = diagramView.Thumbnail?.ToBase64String();
|
||||
|
||||
var selectedDesignerItems = diagramView.Items.OfType<DesignerItemViewModelBase>();
|
||||
var selectedConnections = diagramView.Items.OfType<ConnectionViewModel>();
|
||||
|
||||
@@ -346,6 +346,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public bool GenerateThumbnail
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public bool ShowMenuOptions
|
||||
{
|
||||
get
|
||||
@@ -873,7 +878,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
DiagramOption.LayoutOption.PageBackground = diagramItem.PageBackground;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1025,11 +1030,16 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void SaveThumbnail()
|
||||
{
|
||||
if (Thumbnail is VisualBrush visualBrush)
|
||||
if (GenerateThumbnail)
|
||||
{
|
||||
var size = ((UIElement)visualBrush.Visual).DesiredSize;
|
||||
var image = visualBrush.ToBitmap(new Rect(size)).ToBitmapSource((int)size.Width / 4, (int)size.Height / 4);
|
||||
Thumbnail = new ImageBrush(image) { Stretch = Stretch.Uniform };
|
||||
if (Thumbnail is VisualBrush visualBrush)
|
||||
{
|
||||
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;
|
||||
}
|
||||
bool GenerateThumbnail
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
#region 如果这个赋值了,优先用这个的
|
||||
IDrawModeViewModel DrawModeViewModel
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user