Modify picture with PowerShell got quality losses

Hello folks :wave:,

I’m “developing” or more tinkering a script together to modify the wallpaper with different information from the system and set that modified wallpaper again as background.

So far so good, but I recognized that it has losses in quality if you compare to the original one. It’s some artifacts on the wallpaper itself, but mostly on the text.

It’s also scientifically proven because the file itself is much smaller. The original file is a png file with around 18~ MB, yes without compression, testwise. And then the modified picture from PowerShell is 9~ MB.

I also tried different formats, though I always started with original wallpaper in png format. But the output file is changed to bmp, bitmap, file. Didn’t help that much.

Is there any possibility to save without any compression or quality loss?

I hope I said everything important, else don’t hesitate to ask, I will try to deliver the answer to it.

Attachments:


I marked the artifacts with the arrows. As said, in general it appears around the text. When I zoom in I see also the lack of quality in the wallpaper itself and even more in the text section.

Code Snippet of image generation:

(...)

$originalImage = [System.Drawing.Bitmap]::FromFile("C:\mypath\to\original.png")

$copyImage = $originalImage.Clone()

$graphics = [System.Drawing.Graphics]::FromImage($copyImage)
$graphics.CompositingQuality = [System.Drawing.Drawing2D.CompositingQuality]::HighQuality
$graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
$graphics.DrawString($text, $font, $brush, ($copyImage.Width - 500), ($copyImage.Height - 300))
$graphics.Dispose()


$copyImage.Save("C:\path\to\modified\background.bmp", [System.Drawing.Imaging.ImageFormat]::Bmp)

(...)

Those code snippets are tinkered together from the internet documentations and forums I found.


Notice 01
Im not a powershell expert and would say im a bloody beginner, but with motivation to learn it. I’m home at the python corner and also there I would say I’m im somewhere in the beginner section. I would say I have a general understanding of programming/scripting but not that much of knowledge of the language itself whats possible or not or how to program more efficient, yet. :wink:

I may set my own skills to low but better low than to high right? :blush:

Notice 02:
I you think that sounds like something else you already heard, your right! I try to create alternative to BgInfo which does not work that well on my machine.

Hi,

Instead of editing the wallpaper why dont you just overlay the info you need ?

Ive been using the below, might have to edit what you need.

#OneAndOnlyCharlie!

<#
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⢄⡲⠖⠛⠉⠉⠉⠉⠉⠙⠛⠿⣿⣶⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⣡⠖⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⣡⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡔⢡⣶⠏⠀⠀⠀⠀⠀⠀⣠⣴⣶⣶⣶⣶⣶⣶⣦⣄⣸⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠌⢀⣿⠏⠀⠀⠀⠀⠀⠀⠸⠿⠋⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡞⠀⡼⢿⣦⣄⠠⠤⠐⠒⠒⠒⠢⠤⣄⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⠀⠀⠀⣸⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⠞⠁⠀⠀⠠⠇⣀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠈⠙⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⣴⣁⠀⣀⣤⣴⣾⣿⣿⣿⣿⡿⢿⣿⣶⣄⠀⠀⠀⠀⠀⣿⣷⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣿⡇⠘⠟⣻⣿⣧⠀⠀⠀⠀⢿⣿⣤⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⡿⠀⠀⠸⣿⠿⠋⠉⠁⠛⠻⠿⢿⣧⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⣿⡿⠋⠁⠀⢀⣄⡀⠀⠀⠀⢀⣀⣤⣴⣿⣿⣧⠀⢀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⠏⢀⠀⢀⡴⠿⣿⣿⣷⣶⣾⣿⣿⣿⣿⣿⣿⣿⣇⠀⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣿⣿⣤⣿⣷⡈⠀⠀⠀⠙⠻⣿⣿⣿⣿⠿⠛⠛⣻⣿⣿⡄⠈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣄⠀⠀⠀⠀⠈⠋⢉⣠⣴⣾⣿⣿⣿⣿⣷⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢸⣿⣿⢻⡏⢹⠙⡆⠀⠀⠀⠒⠚⢛⣉⣉⣿⣿⣿⣿⣿⣿⡇⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢀⡞⠁⠉⠀⠁⠀⣄⣀⣠⣴⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣤⣈⡛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠛⠋⠉⠉⠉⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⣻⠿⠿⢿⣿⠿⠿⠋⠁⠀⠙⣿⡁⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠛⠋⠉⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⠴⠞⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣈⣹⣦⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣤⡀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣼⣿⣄⣀⣀⡄⠀⣀⣀⣠⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀
⠀⠀⠀⠀⠀⢰⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠉⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡀
⠀⠀⠀⢀⣤⣤⣤⣶⣿⣿⣿⣿⠿⠿⠟⠋⢹⠇⠀⠀⢀⣼⣿⣿⣿⣿⣿⡿⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇
⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⡟⠁⠀⠀⠀⢀⡏⠀⠀⢀⣾⠋⣹⣿⣿⣿⡟⠀⠀⣸⡟⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇
⢠⣿⣿⣿⣿⣿⣿⣿⣿⡟473388⡼⠀⠀⢀⣾⠏⢀⣿⣿⣿⠋⠀⠀⣰⣿⣧⡀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇
#>

Add-Type -AssemblyName PresentationFramework
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')

$computerName = $env:COMPUTERNAME
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -eq "Ethernet"} | Select-Object -First 1).IPAddress
$username = $env:USERNAME
$domain = $env:USERDOMAIN
$osVersion = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption


$cpu = (Get-CimInstance -ClassName Win32_Processor).Name
$totalRAM = [math]::Round((Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 2)
$networkInterface = (Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | Select-Object -First 1).Name

$infoText = @"
Computer Name: $computerName
IP Address: $ip
Username: $username
Domain: $domain

OS Version: $osVersion
CPU: $cpu
RAM: $totalRAM GB
Network Adapter: $networkInterface
"@

$window = New-Object Windows.Window
$window.WindowStyle = 'None'
$window.AllowsTransparency = $true
$window.Background = [Windows.Media.Brushes]::Transparent
$window.Topmost = $true
$window.ResizeMode = 'NoResize'
$window.Width = 400
$window.Height = 200
$window.Left = [System.Windows.SystemParameters]::PrimaryScreenWidth - $window.Width - 20
$window.Top = 20
$window.ShowInTaskbar = $false

$textBlock = New-Object Windows.Controls.TextBlock
$textBlock.Text = $infoText
$textBlock.FontSize = 16
$textBlock.Foreground = [Windows.Media.Brushes]::Black
$textBlock.Margin = '0'
$textBlock.HorizontalAlignment = 'Center'
$textBlock.VerticalAlignment = 'Center'
$textBlock.FontFamily = 'Consolas'
$textBlock.FontWeight = 'Bold'

$window.Content = $textBlock

$window.ShowDialog()
1 Like

What’s your issue with BGInfo? It might be easier to fix the issues you have with BGInfo instead of trying to recreate the functionality of it. :man_shrugging:t3:

Just my 2 ¢ :slightly_smiling_face:

2 Likes

Yeah I read the question and thought, “why are you not using bginfo?” :smiley:

This worked very well! :exploding_head::blush:

Can we modify the code that normal applications can overlap the text?
Else it would be a very nice solution to it! :muscle::technologist:

Hey there @Olaf and @neemobeer :wave:,

A good question of you, let me explain:

BgInfo didn’t update my information of the machine. I fiddle around for several days until I gave up.

It may be easier to solve this issue, but then I didn’t learn anything about PowerShell, and this is much more helpful than using such an old software which does not get any new updates or bug fixes.

Anyway, I like to have things from my own toolbox because as said every time I learned a lot on the way to my goal of the project or Idea until now.

And you see it does work in general, just detail I like to fix because I am so near to the finish.

I hope you understand my view to it.

:blush:

1 Like

I’m not sure what you mean by this. It gets updated. I just recently had to change from version 4.28 to 4.32 for an issue with Server 2022. That aside, there is also this alternative.

1 Like

Okay, actually didn’t know that! :thinking:


I tried PowerBGInfo already, but also didn’t get to work properly :man_shrugging:

But sure can give that again a try.

I tried once to get past that using something like FindWindow and SetWindowPos to only attach text at desktop level but then it started becoming a monster lol

I found a solution to it. I created a 4K version of my image. Now the distortions are not there anymore, at least I did not find any. The text is now also very clear. Also, I changed from bmp format to png saving the new modified image.

Example Image:

Code Snippet:

function Save-Image
{
	param ($Image,
		$OutputPath)
	
	try
	{
		$Image.Save($OutputPath, [System.Drawing.Imaging.ImageFormat]::png)
		return $true
	}
	catch
	{
		Write-Output "Failed to save the image as a png."
		return $false
	}
}
$OutputPath = C:\path\to\my\output\picture.png

Many thanks to all of you, @Vikash_Ghantwal, @neemobeer and @krzydoug for giving recommendations, feedback and pushing me in the right direction. :blush:

If there is interest, I will prepare to create a new forum post and share my code there for discussion and feedback, if there is any such thread or category to do this… :thinking:

Monster is a good keyword. My Project is now a monster, but it’s a nice one. It just wants to play. :wink:

At the end it does not matter if It’s big or not, I think it just matters if that code is readable and working, not right?

Anyway I learned again many things, and I guess that’s even more the important thing, no matter if you reached the goal or not. :blush:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.