I need some help with strechig bitmap in the center of a window.

i put a bitmap in the center of a windowclass, and i am trying to strecth accordingly to the window.

What i want is every time i enlarge or reduce the window, the centered bitmap, enlarge of reduce accordly.

The bitmap is 320X240. This is what i coded:

.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax

; -------------------------
; Load the resource bitmap
; -------------------------
invoke LoadBitmap,hInstance,333
mov hBmp, eax
invoke GetCommandLine
mov CommandLine, eax

invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

(...regular stuff)
; -------------------------------------------------
; Size & centre window at 75% x 75% of screen size
; -------------------------------------------------
invoke LoadMenu,hInst,203 ; menu ID
mov hMenu, eax

invoke CreateWindowEx,WS_EX_CLIENTEDGE,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPEDWINDOW,
Wtx,Wty,Wwd,Wht,
NULL,hMenu,
hInst,NULL
(...)

return msg.wParam

WinMain endp
#########################################################################

WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD

(...regular stuff)
.if uMsg == WM_COMMAND
mov eax, wParam

.elsif .......

.elseif uMsg == WM_PAINT
invoke BeginPaint,hWin,ADDR Ps
mov hDC, eax
invoke Paint_Proc,hWin,hDC
invoke EndPaint,hWin,ADDR Ps
return 0
invoke DefWindowProc,hWin,uMsg,wParam,lParam

ret

WndProc endp

; #########################################################################

Paint_Proc proc hWin:DWORD, hDC:DWORD
LOCAL hOld:DWORD
LOCAL memDC :DWORD

LOCAL rect:RECT
LOCAL bmpWdt :DWORD
LOCAL bmpHdt :DWORD

invoke CreateCompatibleDC,hDC ; create memory device context
mov memDC, eax

invoke SelectObject,memDC,hBmp ; select bitmap handle into it
mov hOld, eax

invoke GetClientRect,hWnd,addr rect

mov bmpWdt,320 ; Width of the image = 320
mov eax,rect.right
sub eax,bmpWdt
shr eax,1 ; (ClientWidht-BitmapWidth)/2

mov bmpHdt,240 ; ---Height of the image
mov ebx,rect.bottom
sub ebx,bmpHdt
shr ebx,1 ; (ClientHeidht-BitmapHeidth)/2

invoke BitBlt,hDC,eax,ebx,rect.right,rect.bottom,memDC,0,0,SRCCOPY ; This was first create to center the image to the window screen and keep it centered after reducing/enlarging

invoke SetStretchBltMode, hDC, COLORONCOLOR

; ---This is the problem
invoke StretchBlt,hDC,eax,ebx,rect.right,rect.bottom,memDC,-160,120,640,240,SRCCOPY

; I tryed change all values maintaing the image centerd, but while i reduce the window, the image was reducing, but with wrong coordinates (y)...So i have to put negative values to fix the Y value, but it is still wrong..I know that or -160 , 120 should be variables, bu i can't figure how to make them work properly. (and the screen flicks a lot while resizing...Will look after at EXAMPLE4\ANIMATE on masmv7, seems that the paintproc should be at WM_COMMAND ?)

invoke SelectObject,hDC,hOld ; reselect the old object
invoke DeleteDC,memDC ; delete the memory device context

return 0


Paint_Proc endp

; #########################################################################

Regards

Beyond2000!
Posted on 2002-02-27 23:47:45 by Beyond2000!
The centered image does not fit wioth the window size...It initially looks like the picture, and after resizing the windos, teh centered bitmap should resize or enlarge accordly
Posted on 2002-02-28 00:02:53 by Beyond2000!
Is this what you want?
Posted on 2002-02-28 12:41:38 by roaknog
Tks, roaknog


it's almost what i looking for.

When you code a boundary data, you resized the image on center.

The resize/enlarge procedures is exactly what i was looking.

The point is...The image you wrote on the center should not be enlarged at first. It should remain as the original value 320*240, and just be modified after you enlarge/reduce the windows.

Lets say if you client area is 756 * 526 .....After 75% of a desktop 1024*768)

The image should begin with 320*240, inside the cliente area (756*526), and after resizing the window the image should resize accordly.
Posted on 2002-02-28 14:55:01 by Beyond2000!
How about this?
Posted on 2002-02-28 16:49:56 by roaknog
No, not yet, the problem is just at the boundary....it should be a variable, not a fixed value.

Maybe with ratio variables it could be better to fix.
Posted on 2002-02-28 17:31:24 by Beyond2000!
This one allows you to change the boundary size with a scroll bar.
The button is for putting your picture outside your window.
There is not much more I can do.
Posted on 2002-03-01 12:59:23 by roaknog
Good job.


But i don't want to put a bitmap oustide the window...it's just as done before..inside the client area, but when resizing...all coordinates should make the job proporcionally as you strecth the windows.


I am working on it...

The stretchblt function has a weird way to put the coordinates on the source picture....

I am using matematical functions to calculate teh ratio of a predetermined area and stored it in memory and release when you resize the windows...

Iam having some trouble with my system now...and i have to fix a thing or two, but i'll comeback later and release what i have done so far.

Regards,

Beyond2000!
Posted on 2002-03-01 22:26:29 by Beyond2000!
i did it.

tThis file strecths the bitmap exactly as needed.

It resamples the centered image as the user resizes the window cleint area.


It's totally proportionall.

I used FPU instructions to calculate the ratio of (client/Bmp) in order to resize correctly.

I't does exactly as a resample, but not on the pixels effetcs stuffs...just the area coordinate.

There is a problem that need to be fuixed.

When storing the ration, it doen't grab the decimal (fractinoal) values, just the integer.

Ie.: If the ratio is 2.3265....The ratio used is 2

I need to fix it...but i don't know how.
Posted on 2002-03-06 22:24:03 by Beyond2000!
; #########################################################################

Paint_Proc proc hWin:DWORD, hDC:DWORD

LOCAL hOld:DWORD
LOCAL memDC :DWORD

LOCAL rect:RECT
LOCAL bmpWdt :DWORD ; The value of the final Width of BMP
LOCAL bmpHdt :DWORD ; The value of the final Heigth of BMP
LOCAL var1_BmpWidthOriginal : REAL4
LOCAL var2_BmpHeightOriginal : REAL4
LOCAL var3_WidthRatio : REAL4
LOCAL var4_HeightRatio : REAL4


invoke CreateCompatibleDC,hDC ; create memory device context
mov memDC, eax

invoke SelectObject,memDC,hBmp ; select bitmap handle into it
mov hOld, eax

invoke GetClientRect,hWnd,addr rect

.if movit == 0
; -------------------
; for normal repaint
; -------------------

; ----------Calculate the Width ratio (Client Width / Bmp Width)

mov var1_BmpWidthOriginal,320 ; Original value of the bitmap width
mov eax,rect.right ; 02F4 (756) in my case for client width
mov WidthClient,eax ; WidthClient = 02F4 (756)
fild WidthClient ; Store it (756)
fidiv var1_BmpWidthOriginal ; divide 756/320
fistp var3_WidthRatio ;----Beginning 2.3625


; ----------Calculate the Height ratio (Client Height / Bmp Height)

mov var2_BmpHeightOriginal,240
mov ebx,rect.bottom ; 020E (526) in my case for client height
mov HeightClient,ebx
fild HeightClient
fidiv var2_BmpHeightOriginal ; 526/240
fistp var4_HeightRatio ;----Beginning 2.1916666666666



mov bmpWdt,320 ; Width of the image = 320

mov bmpHdt,240 ; ---Height of the image


fild var3_WidthRatio ; Routine to put WidthRatio to RatioBuffer data (can be ripped)
fidiv RatioBufferWidthClient
fistp RatioBufferWidthClient

fild var4_HeightRatio ; Routine to put HeigthRatio to RatioBuffer data (can be ripped)
fidiv RatioBufferHeightClient
fistp RatioBufferHeightClient

.else
; --------------------------
; when you resize the window
; --------------------------
; ********************************************************

mov eax,rect.right ; Grab the value of the new client width

mov bmpWdt,eax ; Small routine to calc the new bmp width. bmpwdt=EAX=Widthclient
fild bmpWdt ; Store the value of the new client width
fidiv RatioBufferWidthClient ; Divide for the ratio stored (2.3625). The problem is the ratio is 2 not 2.3625
; It can be divided by var3_WidthRatio, but the value is aproximated (no frations)
fistp bmpWdt ;(New value of bmp) ; Store as a new value for bmp width



mov ebx,rect.bottom

mov bmpHdt,ebx
fild bmpHdt
fidiv RatioBufferHeightClient ; Divide for the ratio stored (2.1916666666666). The problem is the ratio is 2 not 2.1916666666666
; It can be divided by var4_HeightRatio, but the value is aproximated (no frations)
fistp bmpHdt ;(New value of bmp)

.endif

mov eax,rect.right ; Routine to calc the coord of X point of the source (bitmap width)
sub eax,bmpWdt
shr eax,1 ; (ClientWidht-BitmapWidth)/2

mov ebx,rect.bottom ; Routine to calc the coord of Y point of the source (bitmap heigth)
sub ebx,bmpHdt
shr ebx,1 ; (ClientHeidht-BitmapHeidth)/2

invoke StretchBlt,hDC,eax,ebx,bmpWdt,bmpHdt,memDC,0,0,320,240,SRCCOPY

mov movit,1

invoke SelectObject,hDC,hOld ; reselect the old object
invoke DeleteDC,memDC ; delete the memory device context

return 0


Paint_Proc endp


________________________________

How to make fistp stores and frational number 2.3625 ?
It just grabbs "2", instead the rest after the dot.

That's why the image seems to jump a little. But it alters all the ratio to 2, instead the proper values.
Posted on 2002-03-06 22:29:21 by Beyond2000!
Here goes the fixed version.


All proportions working now.


Tks bitRAKE !!!


Only flickering, but trying to solve now.

Any clues on fix the flick are welcome
Posted on 2002-03-07 19:14:16 by Beyond2000!
here is the file.
Posted on 2002-03-07 19:14:54 by Beyond2000!