Draw a bitmap

Draw a bitmap

Postby Natter » Wed Oct 05, 2022 7: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: 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 ?
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Draw a bitmap

Postby Jimmy » Thu Oct 06, 2022 12:27 am

hi Natter,

use a Manifest with

Code: Select all  Expand view
 <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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Draw a bitmap

Postby nageswaragunupudi » Thu Oct 06, 2022 5: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: 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 // 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: 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Draw a bitmap

Postby Natter » Thu Oct 06, 2022 8: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 :(
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am

Re: Draw a bitmap

Postby Antonio Linares » Thu Oct 06, 2022 3:06 pm

Dear Natter,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Draw a bitmap

Postby nageswaragunupudi » Thu Oct 06, 2022 3: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
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Draw a bitmap

Postby Natter » Thu Oct 06, 2022 6: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().
Natter
 
Posts: 1221
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: FAST WebCrawler [Crawler], Google [Bot] and 49 guests

cron