FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Draw a bitmap
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Draw a bitmap
Posted: Wed Oct 05, 2022 07:42 PM
Hi,

The monitor resolution is 1920x1080. I need to put a bitmap on the window (the window is expanded to full screen).

Code (fw): Select all Collapse
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 ?
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Draw a bitmap
Posted: Thu Oct 06, 2022 12:27 AM
hi Natter,

use a Manifest with

Code (fw): Select all Collapse
  <application xmlns="urn:schemas-microsoft-com:asm.v3">
       <windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
           <dpiAware>true</dpiAware>
       </windowsSettings>
  </application>

so it does not care about SCALE and use "native" Size

p.s. i still have Problem using FiveWin / MSVC and Manifest which does not show "Detail" e.g. Fileversion
greeting,

Jimmy
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Draw a bitmap
Posted: Thu Oct 06, 2022 05:35 AM
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 (fw): Select all Collapse
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 (fw): Select all Collapse
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 // STRETCH
The 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: 2
The 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: 3
Image 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 (fw): Select all Collapse
   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 (fw): Select all Collapse
   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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Draw a bitmap
Posted: Thu Oct 06, 2022 08:55 AM
Thanks !

I would strongly suggest you run the above small sample, replacing the value of "nResizeMode" with all values I suggested.


I tried all the modes. Everything works. However, it does not look very nice. After all, to insert a 1920-width bitmap into a 1536-width window, the drawimage() method compresses this bitmap. As a result, bitmap doesn't look very good :-)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Draw a bitmap
Posted: Thu Oct 06, 2022 03:06 PM

Dear Natter,

Have you tested all the nResizeModes that Mr. Rao has explained you ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Draw a bitmap
Posted: Thu Oct 06, 2022 03:17 PM

Are you trying to take a screen shot from a 1980x1024 monitor and display full screen on a 1536 monitor?
Can you please let me know what is width and height of the 1536 monitor?

Regards



G. N. Rao.

Hyderabad, India
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: Draw a bitmap
Posted: Thu Oct 06, 2022 06:41 PM

If I understood the question correctly..

I do everything on one monitor. Its resolution is 1920x1080, scale 125%.
I open the FW window and expand it to full screen. In this case, oWnd:nWidth has the value 1536 (height is not important).
I take a full screenshot and get a bitmap size of 1920x1080. Then I try to put it on the FW window using the method DrawImage().

Continue the discussion