when you reduce an image, it becomes darker and sharper
when you enlarge an image, it becomes lighter and softer
i am using StretchBlt to zoom the image
is there a simpe way to overcome this problem without totally processing the image with each zoom step ?
i thought, maybe, there was some flag to select
or, maybe, someone has dealt with this, before
at the moment, i am using
INVOKE SetStretchBltMode,eax,HALFTONE
;
;
;
INVOKE StretchBlt,...................,SRCCOPY
i am going from 5:1 to 1:5
the problem is not too bad when enlarging, but the image deteriorates rapidly when reducing
i can limit that range to ease the problem, but a better solution would be nice :U
Hi Dave,
When reducing the image try COLORONCOLOR instead of HALFTONE, I use HALFTONE for enlarging and COLORONCOLOR for reducing, it seems to work for me. Also make sure you set the brush origin when using HALFTONE.
invoke SetStretchBltMode,[mdc1],HALFTONE
invoke SetBrushOrgEx,[mdc1],0,0,offset pt
invoke SelectObject,[mdc1],[hbmp]
mov [hbmp],eax
invoke SelectObject,[mdc2],[id3info.APIC]
mov [id3info.APIC],eax
invoke StretchBlt,[mdc1],0,0,[rect.right],[rect.bottom],[mdc2],0,0,[bmp.bmWidth],[bmp.bmHeight],SRCCOPY
Edgar
Thanks, Edgar :U
i had tried COLORONCOLOR, but it had little effect - at least, on my display system
i was not aware of the brush alignment thing, though :P
a little digging, and i found the SetColorAdjustment function...
http://msdn.microsoft.com/en-us/library/dd162968%28v=vs.85%29.aspx
it sounds promising - although, i may have to learn more than i wanted to to use it - lol
ah well - you only have to learn it once... or twice
i have a little familiarity from playing with image enhancement, in the past
so - it might not be too bad
doing a little reading on the subject...
http://www.4p8.com/eric.brasseur/gamma.html
Eric had an interesting test image i thought you might like :P
(http://www.4p8.com/eric.brasseur/gamma-1.0-or-2.2.png)
i sucks...
(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10624)
Hi Dave,
I tried GDI plus to get better scaling. The results are slightly better than with the GDI though still not great and I only tested it on a single size, for what its worth here's the picturebox subclass, you can try to play around with it if you like:
invoke GdipLoadImageFromFile,L"gamma-1.0-or-2.2.png",offset pPic1
StaticProc1 FRAME hwnd, uMsg, wParam, lParam, uIdSubclass, dwRefData
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
LOCAL pGraphics:%PTR
.WM_PAINT
cmp D[uMsg],WM_PAINT
jne >>.DEFPROC
invoke BeginPaint,[hwnd],offset ps
invoke GetClientRect,[hwnd],offset rect
invoke GdipCreateFromHDC,[ps.hdc], offset pGraphics
invoke GdipSetPixelOffsetMode,[pGraphics],PixelOffsetModeDefault
invoke GdipSetInterpolationMode,[pGraphics],InterpolationModeHighQuality
invoke GdipDrawImageRectI,[pGraphics],[pPic1],0,0,[rect.right], [rect.bottom]
invoke GdipDeleteGraphics, [pGraphics]
invoke EndPaint,[hwnd],offset ps
xor eax,eax
ret
.DEFPROC
invoke DefSubclassProc, [hwnd], [uMsg], [wParam], [lParam]
RET
ENDF
Note that I use SetWindowSubclass to subclass windows, if you need to be compatible with Windows prior to XP define the CCUSEORDINALS switch in GoAsm and it will be available for all versions back to Win98.
Edgar
thanks again, Edgar
i wonder if the SetWorldTransform function would help
a lot of stuff to try, i guess
i will play with some of it today
grrrrr - lol
all i did was get it double-buffered so i could play with it, and it fixed itself
previous code, 1:5 reduction
(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10626)
current code, 1:5 reduction
(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10627)
image at 1:1, for comparison
(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10628)
i must have been doing something wrong
now, i have to try and figure it out, so i know what not to do :P
my current test code looks like this
INVOKE BeginPaint,hWnd,addr ps
invoke CreateCompatibleDC,ps.hdc
mov hdcMem1,eax
invoke SelectObject,hdcMem1,hBitmap
mov hbmpPrev1,eax
invoke CreateCompatibleDC,ps.hdc
mov hdcMem2,eax
invoke CreateSolidBrush,757A6Bh
mov hbrMem2,eax
invoke SetBkMode,hdcMem2,OPAQUE
invoke SelectObject,hdcMem2,hbrMem2 ;not doing what i want :-)
mov hbrPrev2,eax
invoke CreateCompatibleBitmap,ps.hdc,200,200
mov hbmpMem2,eax
invoke SelectObject,hdcMem2,hbmpMem2
mov hbmpPrev2,eax
invoke SetStretchBltMode,hdcMem2,COLORONCOLOR
invoke StretchBlt,hdcMem2,50,50,100,100,hdcMem1,0,0,500,500,SRCCOPY
invoke BitBlt,ps.hdc,0,0,200,200,hdcMem2,0,0,SRCCOPY
invoke SelectObject,hdcMem2,hbmpPrev2
invoke DeleteObject,hbmpMem2
invoke SelectObject,hdcMem2,hbrPrev2
invoke DeleteObject,hbrMem2
invoke DeleteDC,hdcMem2
invoke SelectObject,hdcMem1,hbmpPrev1
invoke DeleteDC,hdcMem1
INVOKE EndPaint,hWnd,addr ps
xor eax,eax
ret
the problem i am having now should be an easy one for you more experienced programmers :P
i am trying to set the background color that surrounds the reduced bitmap
any help ???
(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10631)
i changed the order to this, which seems to make more sense
INVOKE BeginPaint,hWnd,addr ps
invoke CreateCompatibleDC,ps.hdc
mov hdcMem1,eax
invoke SelectObject,hdcMem1,hBitmap
mov hbmpPrev1,eax
invoke CreateCompatibleDC,ps.hdc
mov hdcMem2,eax
invoke CreateCompatibleBitmap,ps.hdc,200,200
mov hbmpMem2,eax
invoke SelectObject,hdcMem2,hbmpMem2
mov hbmpPrev2,eax
invoke CreateSolidBrush,757A6Bh
mov hbrMem2,eax
invoke SetBkMode,hdcMem2,OPAQUE
invoke SelectObject,hdcMem2,hbrMem2
mov hbrPrev2,eax
invoke SetStretchBltMode,hdcMem2,COLORONCOLOR
invoke StretchBlt,hdcMem2,50,50,100,100,hdcMem1,0,0,500,500,SRCCOPY
invoke BitBlt,ps.hdc,0,0,200,200,hdcMem2,0,0,SRCCOPY
invoke SelectObject,hdcMem2,hbrPrev2
invoke DeleteObject,hbrMem2
invoke SelectObject,hdcMem2,hbmpPrev2
invoke DeleteObject,hbmpMem2
invoke DeleteDC,hdcMem2
invoke SelectObject,hdcMem1,hbmpPrev1
invoke DeleteDC,hdcMem1
INVOKE EndPaint,hWnd,addr ps
xor eax,eax
ret
still get black, though :'(
PatBlt works :U
thanks for your help, Edgar :U
(http://www.masm32.com/board/index.php?action=dlattach;topic=18750.0;id=10703)