Skip to content

Commit

Permalink
Merge pull request #29 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Jan 13, 2024
2 parents aee56d2 + df6d81b commit eef116d
Show file tree
Hide file tree
Showing 83 changed files with 4,692 additions and 4,804 deletions.
15 changes: 4 additions & 11 deletions Source/IconImage/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;

namespace IconImage
namespace IconImage;

public partial class App : Application
{
public partial class App : Application
{
}
}
23 changes: 0 additions & 23 deletions Source/IconImage/AppIcon.xaml.cs

This file was deleted.

117 changes: 117 additions & 0 deletions Source/IconImage/DarkAppIcon.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<UserControl x:Class="IconImage.DarkAppIcon"
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:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:IconImage"
mc:Ignorable="d"
d:DesignHeight="256" d:DesignWidth="256"
Width="256" Height="256">
<UserControl.Resources>
<Color x:Key="EdgeColor">#FF343434</Color>
<Color x:Key="BackColor">#FF262626</Color>

<SolidColorBrush x:Key="FanBrush" Color="White"/>
<SolidColorBrush x:Key="EdgeBrush" Color="{StaticResource BackColor}"/>
<SolidColorBrush x:Key="BackBrush" Color="{StaticResource BackColor}"/>

<sys:Double x:Key="OutlineStrokeThickness">20</sys:Double>

<PathGeometry x:Key="ArcPath">
<PathFigure IsClosed="True" StartPoint="0,100">
<ArcSegment Point="100,0"
Size="100,100"
IsLargeArc="False" SweepDirection="Clockwise"/>
<LineSegment Point="100,23"/>
<ArcSegment Point="23, 100"
Size="77,77"
IsLargeArc="False" SweepDirection="Counterclockwise"/>
</PathFigure>
</PathGeometry>

<PathGeometry x:Key="FanPath">
<PathFigure IsClosed="True" StartPoint="0,100">
<ArcSegment Point="100,0"
Size="100,100"
IsLargeArc="False" SweepDirection="Clockwise"/>
<LineSegment Point="100,100"/>
</PathFigure>
</PathGeometry>

<Style x:Key="PathStyleBack" TargetType="{x:Type Path}">
<Setter Property="Fill" Value="{StaticResource FanBrush}"/>
<Setter Property="Stroke" Value="{StaticResource EdgeBrush}"/>
<Setter Property="StrokeThickness" Value="{DynamicResource OutlineStrokeThickness}"/>
<Setter Property="Stretch" Value="Uniform"/>
<!--<Setter Property="Visibility" Value="Hidden"/>-->
</Style>
<Style x:Key="PathStyleFront" TargetType="{x:Type Path}" BasedOn="{StaticResource PathStyleBack}">
<Setter Property="StrokeThickness" Value="0"/>
<Setter Property="Visibility" Value="Visible"/>
</Style>

<Style x:Key="CanvasStyle" TargetType="{x:Type Canvas}">
<Setter Property="Background" Value="{x:Null}"/>
<!--<Setter Property="Background" Value="{StaticResource BackBrush}"/>-->
</Style>
</UserControl.Resources>

<Grid>
<Rectangle x:Name="RoundedMask"
Width="256" Height="256"
RadiusX="28" RadiusY="28"
Fill="{StaticResource BackBrush}"/>

<Canvas Style="{StaticResource CanvasStyle}">
<Canvas.OpacityMask>
<VisualBrush Visual="{Binding ElementName=RoundedMask}"/>
</Canvas.OpacityMask>

<!-- Right -->
<Path Style="{StaticResource PathStyleBack}"
Data="{StaticResource ArcPath}"
Canvas.Left="130" Canvas.Top="98" Height="120" Width="120"/>
<Path Style="{StaticResource PathStyleFront}"
Data="{StaticResource ArcPath}"
Canvas.Left="140" Canvas.Top="108" Height="100" Width="100"/>

<Path Style="{StaticResource PathStyleBack}"
Data="{StaticResource FanPath}"
Canvas.Left="184" Canvas.Top="152" Height="66" Width="66"/>
<Path Style="{StaticResource PathStyleFront}"
Data="{StaticResource FanPath}"
Canvas.Left="194" Canvas.Top="162" Height="46" Width="46"/>

<!-- Left Top -->
<Path Style="{StaticResource PathStyleBack}"
Data="{StaticResource ArcPath}"
Canvas.Left="40" Canvas.Top="6" Width="116" Height="116"/>
<Path Style="{StaticResource PathStyleFront}"
Data="{StaticResource ArcPath}"
Canvas.Left="50" Canvas.Top="16" Width="96" Height="96"/>

<Path Style="{StaticResource PathStyleBack}"
Data="{StaticResource FanPath}"
Canvas.Left="90" Canvas.Top="58" Height="64" Width="64"/>
<Path Style="{StaticResource PathStyleFront}"
Data="{StaticResource FanPath}"
Canvas.Left="100" Canvas.Top="68" Height="44" Width="44"/>

<!-- Left Bottom -->
<Path Style="{StaticResource PathStyleBack}"
Data="{StaticResource ArcPath}"
Canvas.Left="6" Canvas.Top="134" Width="116" Height="116"/>
<Path Style="{StaticResource PathStyleFront}"
Data="{StaticResource ArcPath}"
Canvas.Left="16" Canvas.Top="144" Width="96" Height="96"/>

<Path Style="{StaticResource PathStyleBack}"
Data="{StaticResource FanPath}"
Canvas.Left="58" Canvas.Top="186" Height="64" Width="64"/>
<Path Style="{StaticResource PathStyleFront}"
Data="{StaticResource FanPath}"
Canvas.Left="68" Canvas.Top="196" Height="44" Width="44"/>
</Canvas>
</Grid>
</UserControl>
11 changes: 11 additions & 0 deletions Source/IconImage/DarkAppIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Windows.Controls;

namespace IconImage;

public partial class DarkAppIcon : UserControl
{
public DarkAppIcon()
{
InitializeComponent();
}
}
95 changes: 45 additions & 50 deletions Source/IconImage/FrameworkElementImage.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,66 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace IconImage
namespace IconImage;

public class FrameworkElementImage
{
public class FrameworkElementImage
/// <summary>
/// Saves the image of a specified FrameworkElement to file in PNG format.
/// </summary>
/// <param name="source">FrameworkElement</param>
/// <param name="filePath">File path</param>
/// <param name="width">Width of saved image (optional)</param>
/// <param name="height">Height of saved image (optional)</param>
public static void SaveImage(FrameworkElement source, string filePath, double width = 0D, double height = 0D)
{
/// <summary>
/// Saves the image of a specified FrameworkElement to file in PNG format.
/// </summary>
/// <param name="source">FrameworkElement</param>
/// <param name="filePath">File path</param>
/// <param name="width">Width of saved image (optional)</param>
/// <param name="height">Height of saved image (optional)</param>
public static void SaveImage(FrameworkElement source, string filePath, double width = 0D, double height = 0D)
{
if (source is null)
throw new ArgumentNullException(nameof(source));
if (string.IsNullOrWhiteSpace(filePath))
throw new ArgumentNullException(nameof(filePath));

var rtb = new RenderTargetBitmap(
(int)source.Width,
(int)source.Height,
96D, 96D,
PixelFormats.Pbgra32);
if (source is null)
throw new ArgumentNullException(nameof(source));
if (string.IsNullOrWhiteSpace(filePath))
throw new ArgumentNullException(nameof(filePath));

rtb.Render(source);
var rtb = new RenderTargetBitmap(
(int)source.Width,
(int)source.Height,
96D, 96D,
PixelFormats.Pbgra32);

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
rtb.Render(source);

if ((0 < width) || (0 < height))
{
var bi = new BitmapImage();
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));

using (var ms = new MemoryStream())
{
encoder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
if ((0 < width) || (0 < height))
{
var bi = new BitmapImage();

bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = ms;
using (var ms = new MemoryStream())
{
encoder.Save(ms);
ms.Seek(0, SeekOrigin.Begin);

if (0 < width)
bi.DecodePixelWidth = (int)width;
if (0 < height)
bi.DecodePixelHeight = (int)height;
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = ms;

bi.EndInit();
}
if (0 < width)
bi.DecodePixelWidth = (int)width;
if (0 < height)
bi.DecodePixelHeight = (int)height;

encoder = new PngBitmapEncoder(); // Save method cannot be used twice.
encoder.Frames.Add(BitmapFrame.Create(bi));
bi.EndInit();
}

using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
encoder.Save(fs);
}
encoder = new PngBitmapEncoder(); // Save method cannot be used twice.
encoder.Frames.Add(BitmapFrame.Create(bi));
}

using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
encoder.Save(fs);
}
}
}
13 changes: 10 additions & 3 deletions Source/IconImage/IconImage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,24 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppIcon.xaml.cs">
<DependentUpon>AppIcon.xaml</DependentUpon>
<Compile Include="DarkAppIcon.xaml.cs">
<DependentUpon>DarkAppIcon.xaml</DependentUpon>
</Compile>
<Compile Include="FrameworkElementImage.cs" />
<Compile Include="LightAppIcon.xaml.cs">
<DependentUpon>LightAppIcon.xaml</DependentUpon>
</Compile>
<Compile Include="ScaleConverter.cs" />
<Compile Include="UpdateImage.xaml.cs">
<DependentUpon>UpdateImage.xaml</DependentUpon>
</Compile>
<Page Include="AppIcon.xaml">
<Page Include="DarkAppIcon.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="LightAppIcon.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
Loading

0 comments on commit eef116d

Please sign in to comment.