Skip to content

Commit

Permalink
Merge branch 'master' into Skyline/work/20240905_AddMammothSubmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-proteinms authored Sep 18, 2024
2 parents 10ccf27 + 15eaa1c commit ddac058
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
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
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);
}
}
}
}
}
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>
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);
}
}
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>
```

0 comments on commit ddac058

Please sign in to comment.