A other question to Mike Williams, or others

A other question to Mike Williams, or others

Post by Tim » Thu, 24 Nov 2005 20:18:51


Hi

I have a last problem with a logo. I need to print it on top of a photo. The
original logo is an EPS file in RGB and has a transparent background.
Because I can't print this logo via Printer.Paintpicture so I have saved it
as a GIF format.

Whatever I try it still prints with a white background despite all the file
format I can process. Is there a way to do this.

Thanks in advance

Tim
 
 
 

A other question to Mike Williams, or others

Post by Mike Willi » Thu, 24 Nov 2005 20:46:32


Yes. You can do it with the TransparentBlt API. This allows you to print the
picture transparently at any size you wish and using whatever colour you
wish for the "transparent" colour. Try the following example on a Form with
a Command Button and a Picture Box. The example prints a picture
transparently on top of a filled rectangle and it prints the transparent
picture at a size of 3 x 2.5 inches. Just alter the "hard coded" path to the
picture of your choice (it can be a bitmap, jpeg or gif). In the example the
"transparent" colour is white, but you can use some other colour if you
wish. By the way, make sure that the actual "white" in the picture is true
white, and not just "nearly white". Also, you will get unpredictable results
witrh animated gifs (although of course your own picture as you've explained
will definitely be a standard static gif).

Mike

Private Declare Function TransparentBlt Lib "msimg32.dll" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, _
ByVal crTransparent As Long) As Boolean

Private Sub Command1_Click()
' NOTE: TransparentBlt will also print transparently over the top of
' and already pre-printed sheet of paper
Printer.ScaleMode = vbInches
' print a filled box just to prove tyransparency
Printer.Line (0, 0)-(4, 4), RGB(192, 240, 255), BF
' transparent blit 3 x 2.5 inches
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
Picture1.AutoSize = True
Picture1.Picture = LoadPicture("c:\tpic1.bmp")
DoEvents
TransparentBlt Printer.hdc, 0, 0, _
Printer.ScaleX(3, vbInches, vbPixels), _
Printer.ScaleX(2.5, vbInches, vbPixels), _
Picture1.hdc, 0, 0, _
Picture1.ScaleWidth, _
Picture1.ScaleHeight, vbWhite
Printer.EndDoc
End Sub

 
 
 

A other question to Mike Williams, or others

Post by Mike Willi » Thu, 24 Nov 2005 20:51:01


. . . oh, just one more thing I forgot to mention, if the picture itself
contains white portions that you wish to be actually printed as white then
you will need to make those portions "nearly white" or (alternatively) use
some otherwise unused colour for the transparent parts. An alternative would
be to create a "mask" that specifies the actual shape of the picture, but
that would require some more code and you would need to use two or three
separate blits to draw it to the printer as a "sprite".

Mike