-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
383 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* COPYRIGHT: See COPYING in the top level directory | ||
* PROJECT: Imaging | ||
* FILE: Imaging/ImageMask.cs | ||
* PURPOSE: Helper class to handle some shape operations on an Image | ||
* PROGRAMER: Peter Geinitz (Wayfarer) | ||
*/ | ||
|
||
using System.Drawing; | ||
|
||
namespace Imaging | ||
{ | ||
/// <summary> | ||
/// Handle all the possible selections on an Image | ||
/// </summary> | ||
internal static class ImageMask | ||
{ | ||
/// <summary> | ||
/// Applies the rectangle mask. | ||
/// </summary> | ||
/// <param name="bitmap">The bitmap.</param> | ||
/// <param name="width">The width of the rectangle.</param> | ||
/// <param name="height">The height of the rectangle.</param> | ||
/// <param name="startPoint">The starting point (top-left corner) of the rectangle.</param> | ||
/// <returns>Rectangle Bitmap</returns> | ||
internal static Bitmap ApplyRectangleMask(Image bitmap, int width, int height, Point startPoint) | ||
{ | ||
// Create a new bitmap to work on | ||
var rectBitmap = new Bitmap(bitmap.Width, bitmap.Height); | ||
|
||
// Use graphics to apply the mask | ||
using var g = Graphics.FromImage(rectBitmap); | ||
// Clear the background to transparent | ||
g.Clear(Color.Transparent); | ||
|
||
// Create a texture brush with the original bitmap | ||
using var brush = new TextureBrush(bitmap); | ||
// Fill a rectangle starting from the given start point | ||
g.FillRectangle(brush, new Rectangle(startPoint.X, startPoint.Y, width, height)); | ||
|
||
return rectBitmap; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Applies the circle mask. | ||
/// </summary> | ||
/// <param name="bitmap">The bitmap.</param> | ||
/// <param name="width">The width.</param> | ||
/// <param name="height">The height.</param> | ||
/// <param name="startPoint">The start point.</param> | ||
/// <returns> | ||
/// Circle Bitmap | ||
/// </returns> | ||
internal static Bitmap ApplyCircleMask(Image bitmap, int width, int height, Point startPoint) | ||
{ | ||
var circleBitmap = new Bitmap(bitmap.Width, bitmap.Height); | ||
using var g = Graphics.FromImage(circleBitmap); | ||
g.Clear(Color.Transparent); | ||
using var brush = new TextureBrush(bitmap); | ||
|
||
// Fill the ellipse starting at the specified start point | ||
g.FillEllipse(brush, startPoint.X, startPoint.Y, width, height); | ||
|
||
return circleBitmap; | ||
} | ||
|
||
/// <summary> | ||
/// Applies the polygon mask. | ||
/// </summary> | ||
/// <param name="bitmap">The bitmap.</param> | ||
/// <param name="points">The points.</param> | ||
/// <returns>Polygon Bitmap</returns> | ||
internal static Bitmap ApplyPolygonMask(Image bitmap, Point[] points) | ||
{ | ||
var polyBitmap = new Bitmap(bitmap.Width, bitmap.Height); | ||
using var g = Graphics.FromImage(polyBitmap); | ||
g.Clear(Color.Transparent); | ||
using var brush = new TextureBrush(bitmap); | ||
g.FillPolygon(brush, points); | ||
|
||
return polyBitmap; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace SlimViews | ||
{ | ||
public class FillTypeVisibilityConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is int selectedIndex && parameter is string targetFillType) | ||
{ | ||
switch (targetFillType) | ||
{ | ||
case "SolidColor": | ||
return selectedIndex == 0 ? Visibility.Visible : Visibility.Collapsed; | ||
case "Texture": | ||
return selectedIndex == 1 ? Visibility.Visible : Visibility.Collapsed; | ||
case "Filter": | ||
return selectedIndex == 2 ? Visibility.Visible : Visibility.Collapsed; | ||
} | ||
} | ||
|
||
return Visibility.Collapsed; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.