Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old September 20th, 2003, 12:28 AM
kalikaye kalikaye is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 kalikaye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
creating transparent jpg images(at VB runtime)

Hi

Does anyone know how to create transparent bmp images at VB runtime. Sort of like the images you'd get if you clicked the transparent box in Windows Paint.

I am using the savepicture function to create these images. I managed to download a program that transfers the picture from the source without the background to the destination

But once you save the file it is still opaque.

thanks

Reply With Quote
  #2  
Old September 21st, 2003, 02:08 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
A sample:
Transparent Bitmap Background for VB (or Office) Addin Buttons and Menu Items:
When a VB Addin tries to add a button to a VB commandbar or menu, it has no simple way to properly specify a transparent background for the button or menu item bitmap. Since we have to use the clipboard to transfer the image to the button, it can't be an icon. This generally makes the button look very ugly, especially when the user has selected a fancy color scheme. Since built-in addins display their bitmapped buttons properly, I guessed that there should be a way... Here it is.

First add the following declarations to your General section in your addin:



private Type COLORMAP
from as Long
to as Long
End Type

private Type PICTDESC
Size as Long
Type as Long
hBmp as Long
hPal as Long
Reserved as Long
End Type

private Type IID
Data1 as Long
Data2 as Integer
Data3 as Integer
Data4(7) as Byte
End Type

private Declare Function CreateMappedBitmap _
Lib "comctl32.dll" (byval hInstance as Long, _
byval idBitmap as Long, _
byval wFlags as Long, _
lpColorMap as COLORMAP, _
byval iNumMaps as Long) as Long

private Declare Function OleCreatePictureIndirect _
Lib "olepro32.dll" (desc as PICTDESC, RefIID as IID, _
byval fPictureOwnsHandle as Long, IPic as IPicture) as Long

private Declare Function GetSysColor Lib "user32" (byval nIndex as Long) as Long
Const COLOR_MENU = 4

Dim g_map as COLORMAP


This declares Win32 API and OLE functions that we'll need later. Then add the following function to your addin:


Function BitmapToPicture(byval hBmp as Long, _
optional byval hPal as Long = 0) as IPicture

' Code adapted from HardCore Visual Basic articles in MSDN
' Fill picture description
Dim IPic as IPicture, picdes as PICTDESC, iidIPicture as IID

picdes.Size = len(picdes)
picdes.Type = vbPicTypeBitmap
picdes.hBmp = hBmp
picdes.hPal = hPal

' Fill in magic IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
iidIPicture.Data1 = &H7BF80980
iidIPicture.Data2 = &HBF32
iidIPicture.Data3 = &H101A
iidIPicture.Data4(0) = &H8B
iidIPicture.Data4(1) = &HBB
iidIPicture.Data4(2) = &H0
iidIPicture.Data4(3) = &HAA
iidIPicture.Data4(4) = &H0
iidIPicture.Data4(5) = &H30
iidIPicture.Data4(6) = &HC
iidIPicture.Data4(7) = &HAB

' Create picture from bitmap handle
OleCreatePictureIndirect picdes, iidIPicture, true, IPic
set BitmapToPicture = IPic

End Function

Finally, when your addin is about to add the bitmap representing your command in the VB menu or CommandBar, use the following code (assuming that mcbMenuCommandBarCtrl is the target CommandBarControl that you just created).



g_map.from = RGB(192, 192, 192)
g_map.to = GetSysColor(COLOR_MENU)

Clipboard.SetData BitmapToPicture(CreateMappedBitmap(App.hInstance, BMP_ID, 0, g_map, 1))
mcbMenuCommandBarCtrl.PasteFace

BMP_ID being the resource identifier of the bitmap.

A few explanations : CreateMappedBitmap is a Win32 API function creating a new bitmap from an existing bitmap resource by translating specified a specified color to another color. The "from" and "to" colors are specified in a COLORMAP structure. You can translate as many colors as you wish. Here, we merely translate the bitmap background color (in that case RGB(192, 192, 192)) to the background color of menus and commandbars (which we get from GetSysColor)

However, CreateMappedBitmap returns a bitmap handle which we can't use as-is. BitmapToPicture is a handy function that is partially described and implemented in the MSDN. It creates an IPicture interface from the bitmap handle (a picture in VB actually points to an IPicture COM interface). So, you can assign the result of BitmapToPicture to a Picture object variable.

Once we have a "standard" VB picture, we can copy it to the clipboard and then paste it to the button face.

We use a global variable for the COLORMAP because we may have to re-use it if the CommandBarControl changes its state and therefore changes its bitmap.

That's it. Your VB Addin buttons and menu items will now be displayed properly. The Downloads section points to a VB Addin using this technique (and also allowing to automatically restore the last project when launching VB).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > creating transparent jpg images(at VB runtime)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway