Re: Help needed for printing Bitmap to specific Hdc
- Posted by Al Getz <Xaxo at aol.com> Mar 13, 2006
- 484 views
Rad wrote: > > Hi, > > I am trying to print a bitmap to a specific Hdc. > This Hdc is provided by a printpreview dll. > I could create a fontHandle using CreateFontA() and print to > the same Hdc, but printing of bitmap fails. > > I am using CreateCompatibleBitmap() using the specified Hdc and > trying to use following code: > > }}} <eucode> > > --=================================================================================== > -- This function creates a compatible bitmap > global function cCreateBitmap(atom Hdc, integer WidthInPx, integer HeightInPx) > atom hBitmapHandle > hBitmapHandle=w32Func( xCreateCompatibleBitmap, {Hdc, WidthInPx, HeightInPx} > ) > return hBitmapHandle > end function > > > --=================================================================================== > > x = 10 > y = 10 > w = 0 > h = 0 > vertFactor = 1 > horzFactor = 1 > > name = "temp.bmp" > > data = repeat(0,4) > fn=open(name,"rb") > > if fn = -1 then > fn = message_box("Failed to open "&name, "printDIB error", MB_OK) > return w32True > end if > > for i=1 to 18 do > bmp = getc(fn) > end for > > data[1]=getc(fn) > data[2]=getc(fn) > data[3]=getc(fn) > data[4]=getc(fn) > wbmp=bytes_to_int(data) > data[1]=getc(fn) > data[2]=getc(fn) > data[3]=getc(fn) > data[4]=getc(fn) > hbmp=bytes_to_int(data) > close(fn) > > -- Get printed size > > if w = 0 and h = 0 then > wpic = wbmp -- pixel count > same > hpic = hbmp * (vertFactor/horzFactor) > elsif w = 0 then > hpic = h * vertFactor -- height defined > wpic = hpic * (wbmp/hbmp) * (horzFactor/vertFactor) > elsif h = 0 then > wpic = w * horzFactor -- width defined > hpic = wpic * (hbmp/wbmp) * (vertFactor/horzFactor) > else > wpic = w * horzFactor -- both defined > hpic = h * vertFactor > end if > > wpic = floor(wpic) > hpic = floor(hpic) > > -- Load the bitmap into memory > > bmp = loadBitmapFromFile(name) > > gl_hBitmap=cCreateBitmap(Hdc, wpic, hpic) > > hPreviousGdiObject= w32Func( xSelectObject, {Hdc, gl_hBitmap} ) > > stretchBlt( Hdc, -- copy to TheWindow > x, y, -- put at {10,10} in TheWindow > wpic, hpic, -- size of printed bitmap > bmp, -- copy from loaded bitmap > 0, 0, -- upper left hand corner is {0,0} > wbmp, hbmp, -- copy a wbmp x hbmp pixel portion > SRCCOPY ) -- replace destination with image > > result= w32Func( xSelectObject, {Hdc,hPreviousGdiObject} ) > > </eucode> {{{ > > Nothing gets printed to Hdc. > Can somebody help me out in this? > > Regards, > Rad. Hi there, There's a clear example in the file "Bitmaps.ew" in my WinClass library. If you download the lib you get that file. Take care, Al And, good luck with your Euphoria programming! My bumper sticker: "I brake for LED's"