Skip to content

Commit

Permalink
Fixed Aspekt Ratio for Exported Image
Browse files Browse the repository at this point in the history
The exported Wallpaper was previously not proportionally resized
  • Loading branch information
Schneppi committed May 31, 2024
1 parent 8053056 commit 1bf8f0b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
35 changes: 35 additions & 0 deletions Module_Extensions.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Supernote Wallpaper Maker.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions Window_Main.xojo_window
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1bf8f0b

Please sign in to comment.