Old 04-06-2007   #1 (permalink)
Monster Member
 
FuRbY*'s Avatar
 
Join Date: Dec 2006
Location: the immunity syndicate
Age: 30
Posts: 2,998
Rep Power: 5
Default VB6 - transparent images

a current software assignment requires us to create a program where a user can select certain features and it will generate a persons face. im having trouble with adding things like hair to the head without have the transparent images (created in PSP) maintain a white background.

help.
FuRbY* is offline   Reply With Quote
Old 04-06-2007   #2 (permalink)
Honorary Member
 
slpz's Avatar
 
Join Date: Jan 2007
Posts: 1,021
Rep Power: 3
Default

rofl, im doing vb6 atm but nothing near wat u had jus said.

im making an application form which allows the user to save his data then calc prices for product etc.. urs seems hard

cant help u cuz im programming noob
slpz is offline   Reply With Quote
Old 04-06-2007   #3 (permalink)
Contributing Member
 
Join Date: Jun 2006
Location: Sydney
Age: 21
Posts: 636
Rep Power: 3
Send a message via MSN to Henry
Default

http://www.codeguru.com/csharp/.net/...cle.php/c4661/

It's for .net but it should work.

The magic of google for everything programming related

Edit: Apparently it won't work for vb6. Try this http://en.allexperts.com/q/Visual-Ba...re-Boxes-1.htm

That's pretty loltastic
Henry is offline   Reply With Quote
Old 04-06-2007   #4 (permalink)
Monster Member
 
FuRbY*'s Avatar
 
Join Date: Dec 2006
Location: the immunity syndicate
Age: 30
Posts: 2,998
Rep Power: 5
Default

Quote:
Originally Posted by Henry View Post
http://www.codeguru.com/csharp/.net/...cle.php/c4661/

It's for .net but it should work.

The magic of google for everything programming related

Edit: Apparently it won't work for vb6. Try this http://en.allexperts.com/q/Visual-Ba...re-Boxes-1.htm
that is quite a bit of code. its a yr11 assignment and if it requires that much coding....
FuRbY* is offline   Reply With Quote
Old 04-06-2007   #5 (permalink)
Contributing Member
 
Join Date: Jun 2006
Location: Sydney
Age: 21
Posts: 636
Rep Power: 3
Send a message via MSN to Henry
Default

I just post what the internets tell me man. I'd help more but VB aint my thang :P

btw those links took me about 2 seconds to find if you try for 2 mins you might get a better site. I doubt it though I'm the pro Googler
Henry is offline   Reply With Quote
Old 04-06-2007   #6 (permalink)
Pro Member
 
chemicalNova's Avatar
 
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
Default

You want the white parts to be transparent? You'll need to generate a mask for the picture. Something like this:
PHP Code:
' chemicalNova

Option Explicit

Private Declare Function BitBlt Lib "gdi32" _
  (ByVal hDCDest As Long, ByVal XDest As Long, _
   ByVal YDest As Long, ByVal nWidth As Long, _
   ByVal nHeight As Long, ByVal hDCSrc As Long, _
   ByVal xSrc As Long, ByVal ySrc As Long, _
   ByVal dwRop As Long) As Long

Private Declare Function CreateBitmap Lib "gdi32" _
  (ByVal nWidth As Long, _
   ByVal nHeight As Long, _
   ByVal nPlanes As Long, _
   ByVal nBitCount As Long, _
   lpBits As Any) As Long

Private Declare Function SetBkColor Lib "gdi32" _
   (ByVal hdc As Long, _
    ByVal crColor As Long) As Long

Private Declare Function SelectObject Lib "gdi32" _
  (ByVal hdc As Long, _
   ByVal hObject As Long) As Long

Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
  (ByVal hdc As Long, _
   ByVal nWidth As Long, _
   ByVal nHeight As Long) As Long

Private Declare Function CreateCompatibleDC Lib "gdi32" _
   (ByVal hdc As Long) As Long

Private Declare Function DeleteDC Lib "gdi32" _
   (ByVal hdc As Long) As Long

Private Declare Function DeleteObject Lib "gdi32" _
   (ByVal hObject As Long) As Long

Sub TransparentBlt(OutDstDC As Long, DstDC As Long, SrcDC As Long, SrcX As Integer, SrcY As Integer, DstX As Integer, DstY As Integer, TransColor As Long)
   
  '
DstDCDevice context into which image must be
  
'drawn transparently
  
  '
OutDstDCDevice context into image is actually drawn,
  
'even though it is made transparent in terms of DstDC

  '
SrcDevice context of source to be made transparent
  
'in color TransColor

  '
SrcRectRectangular region within SrcDC to be made
  
'transparent in terms of DstDC, and drawn to OutDstDC

  '
DstXDstY Coordinates in OutDstDC (and DstDC)
  
'where the transparent bitmap must go. In most
  '
casesOutDstDC and DstDC will be the same
  Dim nRet 
As LongAs IntegerAs Integer
  Dim MonoMaskDC 
As LonghMonoMask As Long
  Dim MonoInvDC 
As LonghMonoInv As Long
  Dim ResultDstDC 
As LonghResultDst As Long
  Dim ResultSrcDC 
As LonghResultSrc As Long
  Dim hPrevMask 
As LonghPrevInv As Long
  Dim hPrevSrc 
As LonghPrevDst As Long

  W 
SrcX
  H 
SrcY
   
 
'create monochrome mask and inverse masks
  MonoMaskDC = CreateCompatibleDC(DstDC)
  MonoInvDC = CreateCompatibleDC(DstDC)
  hMonoMask = CreateBitmap(W, H, 1, 1, ByVal 0&)
  hMonoInv = CreateBitmap(W, H, 1, 1, ByVal 0&)
  hPrevMask = SelectObject(MonoMaskDC, hMonoMask)
  hPrevInv = SelectObject(MonoInvDC, hMonoInv)
   
 '
create keeper DCs and bitmaps
  ResultDstDC 
CreateCompatibleDC(DstDC)
  
ResultSrcDC CreateCompatibleDC(DstDC)
  
hResultDst CreateCompatibleBitmap(DstDCWH)
  
hResultSrc CreateCompatibleBitmap(DstDCWH)
  
hPrevDst SelectObject(ResultDstDChResultDst)
  
hPrevSrc SelectObject(ResultSrcDChResultSrc)
   
'copy src to monochrome mask
  Dim OldBC As Long
  OldBC = SetBkColor(SrcDC, TransColor)
  nRet = BitBlt(MonoMaskDC, 0, 0, W, H, SrcDC, _
                0, 0, vbSrcCopy)
  TransColor = SetBkColor(SrcDC, OldBC)
   
 '
create inverse of mask
  nRet 
BitBlt(MonoInvDC00WH_
                MonoMaskDC
00vbNotSrcCopy)
   
 
'get background
  nRet = BitBlt(ResultDstDC, 0, 0, W, H, _
                DstDC, DstX, DstY, vbSrcCopy)
   
 '
AND with Monochrome mask
  nRet 
BitBlt(ResultDstDC00WH_
                MonoMaskDC
00vbSrcAnd)
   
 
'get overlapper
  nRet = BitBlt(ResultSrcDC, 0, 0, W, H, SrcDC, _
                0, 0, vbSrcCopy)
   
 '
AND with inverse monochrome mask
  nRet 
BitBlt(ResultSrcDC00WH_
                MonoInvDC
00vbSrcAnd)
   
'XOR these two
  nRet = BitBlt(ResultDstDC, 0, 0, W, H, _
                ResultSrcDC, 0, 0, vbSrcInvert)
   
 '
output results
  nRet 
BitBlt(OutDstDCDstXDstYWH_
                ResultDstDC
00vbSrcCopy)
   
 
clean up
  hMonoMask 
SelectObject(MonoMaskDChPrevMask)
  
DeleteObject hMonoMask

  hMonoInv 
SelectObject(MonoInvDChPrevInv)
  
DeleteObject hMonoInv

  hResultDst 
SelectObject(ResultDstDChPrevDst)
  
DeleteObject hResultDst

  hResultSrc 
SelectObject(ResultSrcDChPrevSrc)
  
DeleteObject hResultSrc

  DeleteDC MonoMaskDC
  DeleteDC MonoInvDC
  DeleteDC ResultDstDC
  DeleteDC ResultSrcDC

End Sub 
..and used like:
PHP Code:
TransparentBlt To.hdcTo.hdcFrom.hdcWidthHeightxyRGB(255255255)  255,255,255 white 
chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots.
-
chemicalNova is offline   Reply With Quote
Old 04-06-2007   #7 (permalink)
Pro Member
 
chemicalNova's Avatar
 
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
Default

Due to the extreme lack of syntax highlighting capabilities of these forums I've uploaded the project.

This example is one I wrote for someone on vbforums.com.

http://www.cdeliasoftware.com/transparent.zip

Run the project, and click the button.. the black is transparent'ed.

chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots.
-
chemicalNova is offline   Reply With Quote
Old 04-06-2007   #8 (permalink)
Monster Member
 
FuRbY*'s Avatar
 
Join Date: Dec 2006
Location: the immunity syndicate
Age: 30
Posts: 2,998
Rep Power: 5
Default

Quote:
Originally Posted by chemicalNova View Post
Due to the extreme lack of syntax highlighting capabilities of these forums I've uploaded the project.

This example is one I wrote for someone on vbforums.com.

http://www.cdeliasoftware.com/transparent.zip

Run the project, and click the button.. the black is transparent'ed.

chem
thankyou for some coding with visuals. will try implementing it.

btw, what am i changing to get the black transparency to white transparency?
does it also matter whether its a picture or image box?

Last edited by FuRbY*; 04-06-2007 at 06:40 PM..
FuRbY* is offline   Reply With Quote
Old 04-06-2007   #9 (permalink)
Pro Member
 
chemicalNova's Avatar
 
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
Default

Changing it from black to white is as simple as changing the last 0 in the example I gave you, to RGB(255,255,255).

ImageBoxes are terrible controls. PictureBoxes, are basically a movable Device Context.

ImageBoxes can load Pictures with transparency.. but you cannot change the contents of an ImageBox. PictureBoxes can't load with transparency, but you can change the contents of the picturebox.

So to answer your question.. yes, it MUST be a PictureBox for that particular piece of code to work.

chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots.
-
chemicalNova is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +10. The time now is 09:15 AM.


Powered by vBulletin® Version 3.7.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0