Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Debug Display On
#Debug Error On
%Unicode=1
#Include "Win32API.inc"
Function PBMain() As Long
Local hBMP As Dword
Local Portrait, x,y,wNew,hNew,w,h,wcont,hcont,hCanvas,wCanvas,wImg,hImg, xPPI, yPPI As Long
Clipboard Get Bitmap To hBMP 'put image in memory bitmap
Graphic Attach hBMP,0
Graphic Get Canvas To wImg,hImg
'wCont,hCont = container size : hImg,wImg = original image size : wNew,hNew = image size to fit in container
XPrint Attach Default
XPrint Get PPI To xPPI, yPPI
Portrait = 0
If Portrait = 1 Then
XPrint Get Canvas To wCanvas,hCanvas
XPrint Set Orientation 1
wCont = 5 * xPPI
hCont = 7 * yPPI
Else
XPrint Get Canvas To hCanvas,wCanvas
XPrint Set Orientation 2
wCont = 7 * xPPI
hCont = 5 * yPPI
End If
wNew = wImg / Max(wImg / wCont, hImg / hCont)
hNew = hImg / Max(wImg / wCont, hImg / hCont)
x = (wCanvas-wNew)/2 : y = (hCanvas-hNew)/2 'upper/left position so resized image is centered
XPrint Stretch hBMP, 0, (0,0)-(wImg-1,hImg-1) To (x,y)-(x+wNew-1,y+hNew-1) 'copy (resized) from memory bitmap to visible image
Local x1,x2,y1,y2 As Long
x1 = (wCanvas-wCont)/2
x2 = x1 + wCont
y1 = (hCanvas-hCont)/2
y2 = y1 + hCont
XPrint Box (x1,y1)-(x2,y2),,%Black
XPrint Close
End Function
http://www.garybeene.com/sw/gbsnippets.htm