-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Refactor and centralize PosterIcon code
Unified PosterIcon classes into a base class to avoid code duplication and simplify maintenance. Updated class for different PosterIcon variants to extend from the new PosterIconBase class.
- Loading branch information
1 parent
c62d005
commit af8f445
Showing
12 changed files
with
68 additions
and
173 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using NLog; | ||
using Logger = NLog.Logger; | ||
|
||
namespace FoliCon.Models.Data; | ||
|
||
public abstract class PosterIconBase : UserControl | ||
{ | ||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); | ||
protected PosterIconBase() | ||
{ | ||
} | ||
|
||
protected PosterIconBase(object dataContext) | ||
{ | ||
DataContext = dataContext; | ||
} | ||
|
||
public Bitmap RenderToBitmap() | ||
{ | ||
return RenderTargetBitmapTo32BppArgb(AsRenderTargetBitmap()); | ||
} | ||
|
||
private RenderTargetBitmap AsRenderTargetBitmap() | ||
{ | ||
var size = new System.Windows.Size(256, 256); | ||
Measure(size); | ||
Arrange(new Rect(size)); | ||
|
||
var rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Default); | ||
RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality); | ||
RenderOptions.SetEdgeMode(this, EdgeMode.Aliased); | ||
rtb.Render(this); | ||
|
||
return rtb; | ||
} | ||
|
||
public static Bitmap RenderTargetBitmapTo32BppArgb(BitmapSource rtb) | ||
{ | ||
Logger.Trace("Converting RenderTargetBitmap to 32BppArgb"); | ||
var stream = new MemoryStream(); | ||
BitmapEncoder encoder = new PngBitmapEncoder(); | ||
encoder.Frames.Add(BitmapFrame.Create(rtb)); | ||
encoder.Save(stream); | ||
Logger.Trace("RenderTargetBitmap converted to 32BppArgb"); | ||
return new Bitmap(stream); | ||
} | ||
} |
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
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