Natter wrote:Hi,
The monitor resolution is 1920x1080. I need to put a bitmap on the window (the window is expanded to full screen).
- Code: Select all Expand view
hBmp - bitmap 1920x1080
hCropBmp:=FW_TransformBitmap(hBmp, {1, 1, oWnd:nHeight, oWnd:nWidth})
bPnt:=&('{||oLay:DrawImage('+ltrim(str(hCropBmp))+ ;
', {1,1,oWnd:nHeight,oWnd:nWidth},,1)}')
DEFINE DIALOG oLay PIXEL STYLE nOR(WS_POPUP)
ACTIVATE DIALOG oLay ON PAINT eval(oLay:bPnt)
Everything works fine if the Scale is 100%. If, for example, Scale is 125%, then the drawn bitmap is distorted. What can be done ?
No need for any such complex program. No need to resize first and then draw the image.
Method DrawImage(...) itself provides different resizing options.
Syntax:
- Code: Select all Expand view
DrawImage( uImage, [aRect], [lTransp], [nResizeMode], [nAlphaLevel], [lGray], [cAlign], [aColorMap] )
Parameter nResizeMode:
Value: nil or 0: DEFAULT: If the image is smaller than the window client area, the image is not resized and positioned at the center (by default) or at the required position according the parameter "cAlign"
If the image is larger then the window, image is resized to just fit inside the window, respecting the aspect ratio (ratio of width and height). In other words, the image is not distorted.
Value: 1 // STRETCHThe image is resized to exactly fit the width and height of the window, to fill the entire window area with the image.
This mode ignores the aspect ratio of the image. If the aspect ratio of window and image are different, obviously the image gets distorted in this case.
Note: This is the only mode where the aspect ratio of the image is ignored. All other resizing options retain the aspect ratio image perfectly. No distortion.
Value: 2The image is resized to cover the entire area of the window, without changing the aspect ratio of the image (not distorted). If the aspect ratio of window or image are different, either a part of height/width of the resized image is outside the window and not visible.
Value: 3Image is resized to the maximum size to fit totally inside the window without changing the aspect ratio of the image. If the aspect ratios of window and image differ, some parts of the window vertical/horizontal are left blank.
Value "C" or "CIRCLE"The image is resized the maximum to fit inside the window, but cropped into a circle.
Value "E" or "ELLIPSE"The image is resized the maximum to fit inside the window, but cropped into an ellipse.
The program can be as simple as:
- Code: Select all Expand view
local oWnd, nResizeMode := nil // 0,1,2,3,C,E
DEFINE WINDOW oWnd
oWnd:bPainted := { |hDC| oWnd:DrawImage( "c:\fwh\bitmaps\sea.bmp", nil, nil, nResizeMode ) }
ACTIVATE WINDOW oWnd CENTERED
or better:
- Code: Select all Expand view
local oWnd, aBmp, nResizeMode := nil // 0,1,2,3,C,E
DEFINE WINDOW oWnd
aBmp := oWnd:ReadImage( "c:\fwh\bitmaps\sea.bmp" )
oWnd:bPainted := { |hDC| oWnd:DrawImage( aBmp, nil, nil, nResizeMode ) }
ACTIVATE WINDOW oWnd CENTERED
My explanation may not make it very clear.
I would strongly suggest you run the above small sample, replacing the value of "nResizeMode" with all values I suggested. You may choose what is appropriate for you.