Heya,

I used Ernies Image.lib to load an image from my HD and received an handle to it.

Now I want to resize this thing in memory before I want to pass it to another proc which needs the handle of the image to work.

I tried StretchBlt'ing from one DC to another, Creating Bitmaps and StretchBlt'ing on their DC
and what more... I just don't get it.
Anyone knows how to achieve my little goal ?

Tia,
Jimmy
Posted on 2002-08-17 19:54:50 by JimmyClif
Create a new device context with CreateCompatibleDC, then SelectObject onto a bitmap that you create with CreateCompatibleBitmap (with dimensions of target image). Then StretchBlt the source device context onto the newly created one.
Posted on 2002-08-17 20:21:35 by comrade
and then ?

I need to pass a handle to a Bitmap. Not a DC :(

I use these littleprocs I've written to get the DC for the Bitmap



;========================================================================
; GetBitmapDC
;========================================================================
; Usage:
; invoke GetBitmapDC, ADDR BitmapDC, ADDR NameOfBitmap, ADDR hBitmap, hwnd
;========================================================================
GetBitmapDC proc AnotherDC:DWORD, BitmapADDR:DWORD,HandleOfBitmap:DWORD, hwnd:DWORD
invoke GetDC,hwnd
push eax ;1 push DC for release later
invoke CreateCompatibleDC,eax
mov edx,AnotherDC
push eax ;2 push DC for SelectObject
mov [edx],eax
invoke LoadBitmap,hInstance,BitmapADDR
mov edx,HandleOfBitmap
pop ecx ;2 pop Created DC
mov [edx],eax
invoke SelectObject,ecx,eax
pop eax ;1 pop DC to release
invoke ReleaseDC,hwnd,eax
ret
GetBitmapDC endp


Then I create a Beautiful DC using this code :


;========================================================================
; GetCompatibleBitmap
;========================================================================
; Usage:
; invoke GetCompatibleDC, ADDR ImageDC, ADDR hImageDC, hwnd, 500, 300
;========================================================================
GetCompatibleBitmap proc AnotherDC:DWORD, HandleOfDC:DWORD, hwnd:DWORD, xLenght:DWORD, yWidth:DWORD
invoke CreateCompatibleDC,NULL
mov edx,AnotherDC
push eax
mov [edx],eax
invoke GetDC,hwnd
push eax
invoke CreateCompatibleBitmap,eax,xLenght,yWidth
mov edx,HandleOfDC
mov ecx,[esp] ;pop ecx
mov [esp],eax ;push eax
mov [edx],eax
invoke ReleaseDC,hwnd,ecx
pop eax ;HandleOfDC
pop ecx ;AnotherDC
invoke SelectObject,ecx,eax
ret
GetCompatibleBitmap endp


And all I do is:


invoke GetBitmapDimensionEx,hBitmap,a$ lpDimension ;and I wonder if this works also if I get a gif instead of a bmp.
invoke StretchBlt,PaintDC, 0, 0, 132, 132, BitmapDC, 0, 0, lpDimension.x, lpDimension.y


Now it's on the PaintDC how I like it (132,132)

But how do I get a Bitmap handle to pass on ?

I tried it with CreateBitmap but I don't know where to get a color array from.
And how should I do that anyway?
Posted on 2002-08-17 21:07:01 by JimmyClif
I got it... :grin: :grin: :grin: :grin:

Gotta Delete the DC before passing the Handle.
That easy.
Posted on 2002-08-18 12:54:04 by JimmyClif
Youy could als use the CopyImage api with the LR_COPYDELETEORG constant.

From my Api guide:

The CopyImage function creates a new image (icon, cursor, or bitmap) and copies the attributes of the specified image to the new one. If necessary, the function stretches the bits to fit the desired size of the new image.

HANDLE CopyImage(

HANDLE hImage, // handle to the image to copy
UINT uType, // type of image to copy
int cxDesired, // desired width of new image
int cyDesired, // desired height of new image
UINT fuFlags // copy flags
);

Parameters

hinst
Identifies an instance of the module that contains the image to be copied.

uType
Specifies the type of image to be copied. This parameter can be one of the following values:
Value Meaning
IMAGE_BITMAP Copies a bitmap.
IMAGE_CURSOR Copies a cursor.
IMAGE_ICON Copies an icon.

cxDesired
Specifies the desired width, in pixels, of the image.

cyDesired
Specifies the desired height, in pixels, of the image.

fuFlags
Specifies a combination of the following values:
Value Meaning
LR_COPYDELETEORG Deletes the original image after creating the copy.
LR_COPYRETURNORG Creates an exact copy of the image, ignoring the cxDesired and cyDesired parameters.
LR_MONOCHROME Creates a new monochrome image.
LR_COPYFROMRESOURCE Tries to reload an icon or cursor resource from the original resource file rather than simply copying the current image. This is useful for creating a different-sized copy when the resource file contains multiple sizes of the resource. Without this flag, CopyImage stretches the original image to the new size. If this flag is set, CopyImage uses the size in the resource file closest to the desired size.This will succeed only if hImage was loaded by LoadIcon or LoadCursor, or by LoadImage with the LR_SHARED flag.


Return Values

If the function succeeds, the return value is the handle to the newly created image.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.
Posted on 2002-08-20 20:34:08 by Joshua
Joshua,

Thanks, I had never heard of this API before. Looks really handy.

JimmyClif
Posted on 2002-08-21 06:28:37 by JimmyClif
While I think Joshua'a solution is the most practical here for future reference its worth remembering that GetObject can be used to get a Bitmap or other objects back from a Dc. :)
Posted on 2002-08-21 07:30:58 by Eóin