15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


How to make ImageList transparent??

Steve Schow -- sjs@corp.portal.com
Tuesday, January 07, 1997

Environment: VC++ 4.2-flat, Win NT 4.0

Anyone know how to make the images in an ImageList transparent?

I am using an Image list for ListCtrl's and TreeCtrl's, but when
desktop schemes are set such that the window background color is not
white, it looks all wrong.  I need to make sure the bitmaps have a
transparent background instead of white.  ANyone know how to do this?

Perhaps there is a better way to use actual icon files to fill an
imagelist for a List or Tree control?

Anything?  Anyone?

Thanks in advance

-steve





Grant Shirreffs Great Elk -- Grant.S@greatelk.com
Wednesday, January 08, 1997

[Mini-digest: 3 responses]



>Original Message-----
From:	Steve Schow [SMTP:sjs@corp.portal.com]
Sent:	Wednesday, 08 January, 1997 11:24
To:	'mfc-list'
Subject:	How to make ImageList transparent?? 

Environment: VC++ 4.2-flat, Win NT 4.0

Anyone know how to make the images in an ImageList transparent?

I am using an Image list for ListCtrl's and TreeCtrl's, but when
desktop schemes are set such that the window background color is not
white, it looks all wrong.  I need to make sure the bitmaps have a
transparent background instead of white.  ANyone know how to do this?

Perhaps there is a better way to use actual icon files to fill an
imagelist for a List or Tree control?

Anything?  Anyone?

Thanks in advance

-steve

[Grant Shirreffs (Great Elk)]  
The Create member of CImageList isn't flexible enough.  Try this
instead:

	CImageList Images;
	Images.Attach(ImageList_Create(16,15,ILC_COLORDDB | ILC_MASK,10,10));
	CBitmap bmp;
	bmp.LoadBitmap(IDB_RESULT);
	Images.Add(&bmp,RGB(0,0,128));

>In this example, the bitmap background is RGB(0,0,128)
-----From: Steve 


There is a member of CImageList called SetBkColor.  Get the background =
window color using GetSysColor, and give the image list this information =
via the SetBkColor method.
----------
From: 	Steve Schow
Sent: 	07 January 1997 22:24
To: 	'mfc-list'
Subject: 	How to make ImageList transparent??=20

Environment: VC++ 4.2-flat, Win NT 4.0

Anyone know how to make the images in an ImageList transparent?

I am using an Image list for ListCtrl's and TreeCtrl's, but when
desktop schemes are set such that the window background color is not
white, it looks all wrong.  I need to make sure the bitmaps have a
transparent background instead of white.  ANyone know how to do this?

Perhaps there is a better way to use actual icon files to fill an
imagelist for a List or Tree control?

Anything?  Anyone?

Thanks in advance

-steve

-----From: Mike Blaszczak 

At 14:24 1/7/97 -0800, Steve Schow wrote:
>Environment: VC++ 4.2-flat, Win NT 4.0

>Anyone know how to make the images in an ImageList transparent?

Set up a masked imaged list.  Make sure you use the masking colour
in your image when you want the image to be transparent.



.B ekiM
http://www.nwlink.com/~mikeblas/
Why does the "new" Corvette look like a 1993 RX-7?
These words are my own. I do not speak on behalf of Microsoft.




Dana M. Epp -- eppdm@uniserve.com
Wednesday, January 08, 1997

[Mini-digest: 8 responses]

Select a color to use as a transparent one, and remember the RGB. I usually
use a bright green RGB( 0, 255, 0 ).

In the 4th parameter for create on an image list.. you can set the
transparent color. 

Example:

m_Images.Create( IDB_USERTREE, 16, 7, RGB( 0, 255, 0 ) ); // Grab our ImageList


Thats it.. transparency for your ImageLists...

>
>Anyone know how to make the images in an ImageList transparent?
>
PC'ing you,                     
Dana M. Epp          
eppdm@uniserve.com
http://bedrock.cyberhq.com/dana

     "How can one work with the technology of today, using yesterdays
      software and methods, and still be on the leading edge tomorrow?
      Why settle for less... I won't! "

-----From: Syed 

At 02:24 PM 1/7/97 -0800, you wrote:
>Environment: VC++ 4.2-flat, Win NT 4.0
>
>Anyone know how to make the images in an ImageList transparent?
>
>I am using an Image list for ListCtrl's and TreeCtrl's, but when
>desktop schemes are set such that the window background color is not
>white, it looks all wrong.  I need to make sure the bitmaps have a
>transparent background instead of white.  ANyone know how to do this?

That's part of Imagelist implementation actually. For example, I always do
this:-

CImageList m_imgList;
m_imgList.Create(ID_FOLDER, 16, 1, RGB(0xFF,0xFF,0xFF));

In the code above, white color is the transparent color.

-----From: Roma 

Steve Schow wrote:
> 
> Environment: VC++ 4.2-flat, Win NT 4.0
> 
> Anyone know how to make the images in an ImageList transparent?
> 
  Check the Technical Note 060 in the Books Online under:
 VC++ books
     MFC4.0
         TechNotes
	    TN Index
		TN060

  There is a section which describes how to use CImageList class.
Transparent bitmaps are
also discussed there. The main idea as I understand is to declare your
ImageList masked
and provide black-white mask for each image so when these images are
overlapped, part of
the original color image became transparent.

-Roma
-----From: Doug Persons 

Steve Schow wrote:
> 
> Environment: VC++ 4.2-flat, Win NT 4.0
> 
> Anyone know how to make the images in an ImageList transparent?
> 
> I am using an Image list for ListCtrl's and TreeCtrl's, but when
> desktop schemes are set such that the window background color is not
> white, it looks all wrong.  I need to make sure the bitmaps have a
> transparent background instead of white.  ANyone know how to do this?
> 
> Perhaps there is a better way to use actual icon files to fill an
> imagelist for a List or Tree control?
> 
> Anything?  Anyone?
> 
> Thanks in advance
> 
> -steve

Use the CImageList create function of the form:

BOOL Create( UINT nBitmapID, int cx, int nGrow, COLORREF crMask );

as in:

CImageList anImageList;
anImageList.Create(IDB_IMAGE_LIST, 16, 0, RGB(255,255,255));
anImageList.SetBkColor(::GetSysColor(COLOR_WINDOW));


In this case all of the white pixels in your bitmap will be transparent 
(will show the background color of the image list).  You can use other 
colors as the mask color (such as red or green).

You should also handle the OnSysColorChange() message and change the 
color of your image list background when the user changes their window 
colors.

-- 
Doug Persons                206-822-6800    persons@esca.com
Cegelec ESCA Corporation    Bellevue, WA    http://www.esca.com
-----From: Mario Contestabile

>Anyone know how to make the images in an ImageList transparent?
>
>I am using an Image list for ListCtrl's and TreeCtrl's, but when
>desktop schemes are set such that the window background color is not
>white, it looks all wrong.  I need to make sure the bitmaps have a
>transparent background instead of white.  ANyone know how to do this?

You would want the window background color to shine through, as it can be 
changed
at any time. There are two types of images in a CImageList, masked and unmasked.
A masked image lets the background shine through, whereas an unmasked image list
does something like BitBlt. When you are calling the Create CImageList member,
specify the image to be masked, 
m_IMG.Create(::GetSystemMetrics(SM_CXSMICON),...,TRUE/*masked*/, nImages, 0);

mcontest@universal.com

-----From: hou@tfn.com (Bing Hou)

     What about the CImageList::SetBkColor(COLORREF) function? Is it used 
     for drawing a transparent image?
     
     -Bing


______________________________ Reply Separator _________________________________
Subject: How to make ImageList transparent?? 
Author:  Steve Schow  at Internet
Date:    1/7/97 2:24 PM


Environment: VC++ 4.2-flat, Win NT 4.0
     
Anyone know how to make the images in an ImageList transparent?
     
I am using an Image list for ListCtrl's and TreeCtrl's, but when 
desktop schemes are set such that the window background color is not 
white, it looks all wrong.  I need to make sure the bitmaps have a 
transparent background instead of white.  ANyone know how to do this?
     
Perhaps there is a better way to use actual icon files to fill an 
imagelist for a List or Tree control?
     
Anything?  Anyone?
     
Thanks in advance
     
-steve
     
     
-----From: Adam Partridge 

If you use a colour mask when creating the image list you shouldn't 
have any problems.
E.g.
Create a bitmap with 16 pixel wide images and use magenta as the 
transparent colour,
then to create the imagelist .....

m_myList.Create(IDB_MYBITMAP,16,0, RGB(255,0,255));

If you need a more detailed example then E-mail me direct.

AdamP@AbcSystems.com

-----Original Message-----
From:	Steve Schow [SMTP:sjs@corp.portal.com]
Sent:	Tuesday, January 07, 1997 10:24 PM
To:	'mfc-list'
Subject:	How to make ImageList transparent??

Environment: VC++ 4.2-flat, Win NT 4.0

Anyone know how to make the images in an ImageList transparent?

I am using an Image list for ListCtrl's and TreeCtrl's, but when
desktop schemes are set such that the window background color is not
white, it looks all wrong.  I need to make sure the bitmaps have a
transparent background instead of white.  ANyone know how to do this?

Perhaps there is a better way to use actual icon files to fill an
imagelist for a List or Tree control?

Anything?  Anyone?

Thanks in advance

-steve



-----From: "Michael R. Muller" 


	You need to use the crMask arg in the CImageList's Create member
function.

 I have this in my dialog class header file:

CImageList *m_pImageList;

 This is in my dialog class OnInitDialog member function:

// create the imagelist from a bitmap resource
m_pImageList->Create(IDB_CONNECTION, 20, 1, RGB(255, 255, 255));
                                               ^^^^^^^^^^^^^^^^^
                                               (my bitmap background is
white)
// set the imagelist for the tree control
m_treeConnections.SetImageList(m_pImageList, TVSIL_NORMAL);

Hope this help,

Michael Muller
mmuller@esri.com


----------
> From: Steve Schow 
> To: 'mfc-list' 
> Subject: How to make ImageList transparent?? 
> Date: Tuesday, January 07, 1997 2:24 PM
> 
> Environment: VC++ 4.2-flat, Win NT 4.0
> 
> Anyone know how to make the images in an ImageList transparent?
> 
> I am using an Image list for ListCtrl's and TreeCtrl's, but when
> desktop schemes are set such that the window background color is not
> white, it looks all wrong.  I need to make sure the bitmaps have a
> transparent background instead of white.  ANyone know how to do this?
> 
> Perhaps there is a better way to use actual icon files to fill an
> imagelist for a List or Tree control?
> 
> Anything?  Anyone?
> 
> Thanks in advance
> 
> -steve
> 
> 




| Вернуться в корень Архива |