1

I need to open an image file with Paint.Net and then perform a Save As. Along with choosing a file type to save as, it would be great to set the image DPI and convert any CMYK images to RGB. Instead of doing this manually for thousands of images, I'm attempting to automate the process with PowerShell, taking advantage of its ability to control .NET programs. I'd like to accomplish this with the new PowerShell Core, but I'm okay with having to use PS 5 if necessary. My Paint.Net version is 4.1.6

My research leads me to believe I first need to load the assemblies in PowerShell. I've tried to accomplish this with variations of [Reflection.Assembly]. The code runs successfully, but I'm not sure if I'm doing it correctly because I can't seem to create a new object using my newly loaded assembly.

Here are two example lines of code that I've used to load the assembly:

[Reflection.Assembly]::LoadFile("C:\Program Files\paint.net\PaintDotNet.Base.dll")
[System.Reflection.Assembly]::LoadFrom("C:\Program Files\paint.net\PaintDotNet.Base.dll")

Afterwards, I believe I need to create a new object using my new assembly:

$tempImage = New-Object PaintDotNet.Base.Bitmap 'C:\Users\jf060898\Pictures\img1.jpg'

When I attempt to create the object, I get the following error: "New-Object : Cannot find type [PaintDotNet.Base.Bitmap]: verify that the assembly containing this type is loaded." However, when I list the assemblies, I see my Paint.Net:

Name               Version           Culture   PublicKeyToken
PaintDotNet.Base   4.106.7016.38074  neutral   null
Jfire
  • 41
  • 7
  • The only exposed member I see on `PaintDotNet.Base` is `AssemblyServices`. – Maximilian Burszley Apr 23 '19 at 14:09
  • When you say exposed member, do you mean what functions are baked within the .dll file? – Jfire Apr 23 '19 at 14:13
  • I mean public members to that specific namespace. – Maximilian Burszley Apr 23 '19 at 14:13
  • Can you tell me how you found that out? – Jfire Apr 23 '19 at 14:32
  • 1
    Do `[PaintDotNet.Base.` and hit CTRL+SPACE to trigger auto-complete. – Maximilian Burszley Apr 23 '19 at 14:53
  • WOW! Did not know about CTRL+SPACE. I have Paint.NET version 4.2.16 -- If I type [PaintDotNet. and press Ctrl-Space it asks if I want to display all 252 possibilities. If I answer Y it throws an exception, however I can press TAB after the . and see many of them. [PaintDotNet.Document]::FromImage( System.Drawing.Image image) might be a place to start to load your image. You will have to look at getting the file into a System.Drawing.Image object. – Joe B Sep 21 '21 at 15:40

0 Answers0