-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Skyline/work/20240905_AddMammothSubmodule
- Loading branch information
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
pwiz_tools/Skyline/Executables/DevTools/ImageConverter/ImageConverter.sln
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.10.35027.167 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageConverter", "ImageConverter\ImageConverter.csproj", "{264C8064-E16C-4502-8514-120C9754DBEA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{264C8064-E16C-4502-8514-120C9754DBEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{264C8064-E16C-4502-8514-120C9754DBEA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{264C8064-E16C-4502-8514-120C9754DBEA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{264C8064-E16C-4502-8514-120C9754DBEA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {64965344-5B0D-485A-8BE0-E4AB33E29781} | ||
EndGlobalSection | ||
EndGlobal |
40 changes: 40 additions & 0 deletions
40
pwiz_tools/Skyline/Executables/DevTools/ImageConverter/ImageConverter/EmfUtilities.cs
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,40 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
using System.Windows; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Media; | ||
|
||
namespace ImageConverter | ||
{ | ||
public static class EmfUtilities | ||
{ | ||
public static void ConvertToPng(string path, string outputPath) | ||
{ | ||
using (Metafile emf = new Metafile(path)) | ||
using (Bitmap bmp = new Bitmap(emf.Width, emf.Height)) | ||
{ | ||
bmp.SetResolution(emf.HorizontalResolution, emf.VerticalResolution); | ||
using (Graphics g = Graphics.FromImage(bmp)) | ||
{ | ||
g.DrawImage(emf, 0, 0); | ||
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); | ||
|
||
//convert image format | ||
var src = new FormatConvertedBitmap(); | ||
src.BeginInit(); | ||
src.Source = bitmapSource; | ||
src.DestinationFormat = PixelFormats.Bgra32; | ||
src.EndInit(); | ||
|
||
//copy to bitmap | ||
Bitmap bitmap = new Bitmap(src.PixelWidth, src.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); | ||
var data = bitmap.LockBits(new Rectangle(System.Drawing.Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); | ||
src.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride); | ||
bitmap.UnlockBits(data); | ||
bitmap.Save(outputPath); | ||
} | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
pwiz_tools/Skyline/Executables/DevTools/ImageConverter/ImageConverter/ImageConverter.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<UseWPF>true</UseWPF> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" /> | ||
<PackageReference Include="System.Drawing.Common" Version="8.0.7" /> | ||
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
41 changes: 41 additions & 0 deletions
41
pwiz_tools/Skyline/Executables/DevTools/ImageConverter/ImageConverter/Program.cs
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,41 @@ | ||
using ImageConverter; | ||
using System.CommandLine; | ||
using System.Threading.Tasks; | ||
|
||
public class Program | ||
{ | ||
public static async Task<int> Main(string[] args) | ||
{ | ||
var inputFileOption = new Option<string>( | ||
name: "--input-file", | ||
description: "The file to read.") | ||
{ IsRequired = true }; | ||
|
||
var outputFileOption = new Option<string>( | ||
name: "--output-file", | ||
description: "The file to write to.") | ||
{ IsRequired = true }; | ||
|
||
var rootCommand = new RootCommand("Image converting command line utility"); | ||
|
||
var convertEmfToPngCommand = new Command("convertEmfToPng", "Convert Emf to Png file") | ||
{ | ||
inputFileOption, | ||
outputFileOption, | ||
}; | ||
convertEmfToPngCommand.SetHandler( (inputFile, outputFile) => | ||
{ | ||
ConvertEmfToPng(inputFile, outputFile); | ||
}, | ||
inputFileOption, outputFileOption); | ||
|
||
rootCommand.AddCommand(convertEmfToPngCommand); | ||
return await rootCommand.InvokeAsync(args); | ||
|
||
} | ||
|
||
public static void ConvertEmfToPng(string inputFile, string outputFile) | ||
{ | ||
EmfUtilities.ConvertToPng(inputFile, outputFile); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
pwiz_tools/Skyline/Executables/DevTools/ImageConverter/ImageConverter/README.md
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,6 @@ | ||
ImageConverter is a command line utility to convert images when .net is most appropriate. Requires .net8. | ||
|
||
Convert EMF to PNG: | ||
``` | ||
ImageConverter.exe convertEmfToPng --input-file <input_file> --output-file <output_file> | ||
``` |