Reduce size of FolderItem .png Image to fit inside a reduce size Canvas

I have a purchased 3rd Party Source Code Plugin, will call it EW that reduced the size my project window to fit the smaller screen resolution of a computer. I now have a canvas that has been resized smaller to the AspectRatio of the reduced window size.

My old code loaded a FolderItem .png Image that had a canvas with the same dimensions of the old lager non resized window so I could get away with using the Canvas.Dackdrop property command.

My new problem is I have to use the DrawPicture Property Command to resize the .png Image to fit inside the smaller Canvas that has a Super of the EWCanvas Object Paint Event.

[code]'EWCanvas Canvas Object
'EWCanvas Paint Event Handler

Paint(g As Graphics, area() As REALbasic.Rect)
// do math
dim iNewWidth as integer = me.Width
dim iNewHeight as integer = me.Height
dim bHandleResize As Boolean = not Paint(g, areas)

if bHandleResize then
if SourceImage <> nil then g.DrawPicture SourceImage, 0, 0, iNewWidth, iNewHeight, 0, 0, SourceImage.Width, SourceImage.Height
end if[/code]

I am very new in getting my head around OOP concepts (I’m an old school VB6 procedural programmer) I am stuck with using the EWCanvas Object as my Super to the Canvas. Sorry I don’t have a clue on how to write the resize DrawPicture code from the EWCanvas Object Paint Event Above. How do I go about it with the code below. Thanks

Dim strFrtKeyBrdPath, strFrtKeyBrd As String
Dim f As FolderItem
Dim FrtKeyBrdImg As New Picture(iNewWidth, iNewHeight, 32) ’ Sorry iNewWidth & iNewHeight Integers aren’t declared
strFrtKeyBrd = “24FrtGtr6FrtBrdRsWd800x162.png” // Image File

#If TargetWin32 Then
#If DebugBuild Then
strFrtKeyBrdPath = “D:\My Data_DocsApps\Real Studio Projects\Graphics\FretKeyBrd”
f = GetFolderItem(“strFrtKeyBrdPath”).Child(“strFrtKeyBrd”)
f = GetFolderItem(“Graphics”).Child(“FretKeyBrd”).Child(“strFrtKeyBrd”)
#ElseIf TargetMacOS Then
#If DebugBuild Then
strFrtKeyBrdPath = “/Library/Graphics/GAGraphics/FrtKetBrd/”
f = GetFolderItem(“strFrtKeyBrd”),FolderItem,PathTypeShell)


#ElseIf TargetOSLinux Then


Old Code
'If f <> Nil Then
'cvsGuitFrtBrd.Backdrop = Picture.Open(f)
'End IF

??? Graphics.DrawPicture[/code]

[quote=195807:@Jeffrey Cox]Old Code
'If f <> Nil Then
'cvsGuitFrtBrd.Backdrop = Picture.Open(f)
'End IF[/quote]

You could simply use the ProportionalScale method posted at

Simply remove Extends in the first line of that method to become

Function ProportionalScale(Pic as Picture, Width as integer, Height as Integer) As Picture

Then go :

If f <> Nil Then cvsGuitFrtBrd.Backdrop = ProportionalScale(Picture.Open(f), cvsGuitFrtBrd.Width, cvsGuitFrtBrd.Height) End IF

As you see, your old code can be used with a minimal modification.

Thanks Michel - I never knew you could do that with backdrop I’ll try it out.

Oh, by the way ; RubberViews takes care of resizing pictures in Canvas backdrop for you automatically. In Image Well too.

I had to carefully go through your above link examples and I had to make a few tweaks with factor calculations and it worked perfect. The reduced picture size was not pix-elated either.

Thank you for making me explore and learn new ways of how to make a function work.

PS. I just purchased the Source Code last week to Rubber Views and will be exploring how to use it more in my future Projects.

Thanks again Michel you’ve been awesome.

You’re welcome, Jeffrey :slight_smile: