From 1bf8f0bf4915e6ee0b5fd2b6e86fdcb9afdc8666 Mon Sep 17 00:00:00 2001 From: Schneppi Date: Fri, 31 May 2024 07:27:48 +0200 Subject: [PATCH] Fixed Aspekt Ratio for Exported Image The exported Wallpaper was previously not proportionally resized --- Module_Extensions.xojo_code | 35 ++++++++++++++++++++++++++ Supernote Wallpaper Maker.xojo_project | 2 +- Window_Main.xojo_window | 5 +--- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Module_Extensions.xojo_code b/Module_Extensions.xojo_code index b799e5d..ab6f6e3 100644 --- a/Module_Extensions.xojo_code +++ b/Module_Extensions.xojo_code @@ -64,6 +64,41 @@ Protected Module Module_Extensions End Function #tag EndMethod + #tag Method, Flags = &h0 + Function PrepareForExport(p As Picture, X As Integer, Y As Integer) As Picture + If p = Nil Then Return Nil + + Var Preview As New Picture(X, Y) + + // ------------------------------------------------------- + // scale picture keeping the ratio between x and y + // ------------------------------------------------------- + Var PicWidth, PicHeight, ScaleWidth, ScaleHeight As Int16 + Var RatioX, RatioY,PosX, PosY As Double + + PicWidth = p.Width + PicHeight = p.Height + RatioX = X / PicWidth + RatioY = Y / PicHeight + + If RatioX < RatioY Then + ScaleWidth = PicWidth * RatioY + ScaleHeight = PicHeight * RatioY + PosX = ((X - ScaleWidth)/2) + 10 + PosY = 10 + Else + ScaleWidth = PicWidth * RatioX + ScaleHeight = PicHeight * RatioX + PosX = 10 + PosY = ((Y - ScaleHeight)/2) + 10 + End If + + Preview.Graphics.DrawPicture(p,PosX, PosY, ScaleWidth - 20, ScaleHeight - 20, 0, 0, PicWidth, PicHeight) + + Return Preview + End Function + #tag EndMethod + #tag Method, Flags = &h0 Function Set_BrightnessAndContrast(p As Picture, Brightness As Integer, Contrast As Integer) As Picture If p = Nil Then Return Nil diff --git a/Supernote Wallpaper Maker.xojo_project b/Supernote Wallpaper Maker.xojo_project index 6cb8746..e760139 100644 --- a/Supernote Wallpaper Maker.xojo_project +++ b/Supernote Wallpaper Maker.xojo_project @@ -10,7 +10,7 @@ Module=Module_Extensions;Module_Extensions.xojo_code;&h0000000078161FFF;&h000000 DefaultWindow=Window_Main MajorVersion=1 MinorVersion=0 -SubVersion=0 +SubVersion=1 NonRelease=0 Release=3 InfoVersion=Resize and grayscale Pictures to be used as Screensaver on Supernote A6X Machines diff --git a/Window_Main.xojo_window b/Window_Main.xojo_window index b1fb646..27308e6 100644 --- a/Window_Main.xojo_window +++ b/Window_Main.xojo_window @@ -241,15 +241,12 @@ Begin DesktopWindow Window_Main Width = 72 End Begin Thread Thread_RefreshPreview - DebugIdentifier = "" Index = -2147483648 LockedInPosition= False Priority = 2 Scope = 2 StackSize = 0 TabPanelIndex = 0 - ThreadID = 0 - ThreadState = 0 End Begin DesktopLabel Label_GrayscaleType AllowAutoDeactivate= True @@ -462,7 +459,7 @@ End Var ResizedPicture As New Picture(1404,1872) Var ExportPicture As Picture - ResizedPicture.Graphics.DrawPicture(OriginalImage, 0, 0, 1404, 1872, 0, 0, OriginalImage.Width, OriginalImage.Height) + ResizedPicture = PrepareForExport(OriginalImage, ResizedPicture.Width, ResizedPicture.Height) ExportPicture = Set_BrightnessAndContrast(ResizedPicture, Slider_Brightness.Value, Slider_Contrast.Value) ExportPicture = Set_Grayscale_Average(ExportPicture)