Transparent bitmaps

This is a discussion on Transparent bitmaps within the Smalltalk forums in Programming Languages category; I am trying to make a view with a transparent ImageView bitmap that appears on top of a static color decoration. I have set the imageView as transparent, the actual bitmap file is transparent, and I am using this code to load the bitmap in the presenter: (Bitmap fromFile: 'chessProgram\graphics\whiteKnight.bmp') isTransparent: true. Everything already works fine except the transparency. I considered just having 2 images, one for a dark square and one for a light square (it's a chess program), but in that case the user would still be dragging the entire square with background color instead of just the ...

Go Back   Application Development Forum > Programming Languages > Smalltalk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-04-2008, 02:47 AM
zenchess
Guest
 
Default Transparent bitmaps

I am trying to make a view with a transparent ImageView bitmap that
appears on top of a static color decoration. I have set the imageView
as transparent, the actual bitmap file is transparent, and I am using
this code to load the bitmap in the presenter: (Bitmap fromFile:
'chessProgram\graphics\whiteKnight.bmp') isTransparent: true.

Everything already works fine except the transparency. I considered
just having 2 images, one for a dark square and one for a light square
(it's a chess program), but in that case the user would still be
dragging the entire square with background color instead of just the
piece.

I have tried gdiplus image view as well.
Reply With Quote
  #2  
Old 09-04-2008, 04:54 PM
Louis Sumberg
Guest
 
Default Re: Transparent bitmaps

> I am trying to make a view with a transparent ImageView bitmap that
> appears on top of a static color decoration.


Try taking a look at GdiplusGraphics>>exampleGdipGAlphaBlending. I
believe this shows what you want. You would probably need to create
your own imageview and override #onPaintRequired: (or other method if,
for example, you subclass DoubleBufferedView. Offhand I forget what
that is). Hope this helps.

-- Louis
Reply With Quote
  #3  
Old 09-30-2008, 07:54 PM
zenchess
Guest
 
Default Re: Transparent bitmaps

On Sep 4, 3:54*pm, Louis Sumberg <lsumb...@mindspring.com> wrote:
> > I am trying to make a view with a transparent ImageView bitmap that
> > appears on top of a static color decoration.

>
> Try taking a look at GdiplusGraphics>>exampleGdipGAlphaBlending. *I
> believe this shows what you want. *You would probably need to create
> your own imageview and override #onPaintRequired: (or other method if,
> for example, you subclass DoubleBufferedView. *Offhand I forget what
> that is). *Hope this helps.
>
> -- Louis


Can anyone give me more clues on what to do here? I have tried over-
riding onPaintRequired, but I'm kind of at a loss of what to do. I've
tried a lot of different combinations of things. I don't have any
clue how alpha transparency works in dolphin. Surely someone has had
this issue before?

Reply With Quote
  #4  
Old 10-01-2008, 05:32 AM
Udo Schneider
Guest
 
Default Re: Transparent bitmaps

Hihi,

> Can anyone give me more clues on what to do here? I have tried over-
> riding onPaintRequired, but I'm kind of at a loss of what to do. I've
> tried a lot of different combinations of things. I don't have any
> clue how alpha transparency works in dolphin. Surely someone has had
> this issue before?


I think I didn't really get your intention. Could you create a mockup
picture of what you want to achieve and send it over?

CU,

Udo
Reply With Quote
  #5  
Old 10-07-2008, 12:13 AM
zenchess
Guest
 
Default Re: Transparent bitmaps

On Oct 1, 4:32*am, Udo Schneider <Udo.Schnei...@homeaddress.de> wrote:
> Hihi,
>
> > * Can anyone give me more clues on what to do here? *I have tried over-
> > riding onPaintRequired, but I'm kind of at a loss of what to do. *I've
> > tried a lot of different combinations of things. *I don't have any
> > clue how alpha transparency works in dolphin. *Surely someone has had
> > this issue before?

>
> I think I didn't really get your intention. Could you create a mockup
> picture of what you want to achieve and send it over?
>
> CU,
>
> Udo


I want to create a chessboard with draggable pieces. The squares
themselves are colored, decorated, etc. The piece graphics will have
alpha transparency. If you drag the piece
the transparent part of the image should work so that the user is not
dragging a big square that covers up what is behind it. For a
picture, pretty much any chess interface that I've ever seen
like winboard, chessbase, java interfaces, etc. all have a piece
graphic with transparency so you are not dragging a huge square but
just the piece itself.

Figuring out how drag and drop works is another issue, but I'll save
any questions I have about that for later =)
Reply With Quote
  #6  
Old 10-07-2008, 11:01 AM
Udo Schneider
Guest
 
Default Re: Transparent bitmaps

zenchess schrieb:
> I want to create a chessboard with draggable pieces. The squares
> themselves are colored, decorated, etc. The piece graphics will have
> alpha transparency. If you drag the piece
> the transparent part of the image should work so that the user is not
> dragging a big square that covers up what is behind it. For a
> picture, pretty much any chess interface that I've ever seen
> like winboard, chessbase, java interfaces, etc. all have a piece
> graphic with transparency so you are not dragging a huge square but
> just the piece itself.
>
> Figuring out how drag and drop works is another issue, but I'll save
> any questions I have about that for later =)


If I understood you correctly you want each piece to be a independent
view which is shown in front of the board view - although possible I
would not recommend that route.

Using this approach you are trying to convince Windows to use
transparent/non-rectangular views for the pieces. Although possible it's
very hard to get convincing and deterministic results using this way.
Don't get me wrong: This is *not a Dolphin problem*! Windows is the
limitation here! If you want to try anyway you should get familiar with
the #isTransparent property (which is not as straightforward as it
sounds - it just maps the Windows property) and the #onEraseRequired:
event handler.

You basically have to tell Windows to draw underlying controls (using
#isTransparent) and on the top view you have to catch #onEraseRequired:
to prevent windows from erasing the controls background with it's
default background color. Another point that makes life hard here is the
fact that there are subtle (but visible!) differences in the way
childViews of the same parent are ordered. I can offer three "official"
Windows ways which produce totally different results.
IMHO Windows does not allow childViews of the same parent to overlap -
or at least the result is not deterministic.

So this was the long answer why I would not use the one view/piece approach.

Why not simply to all the drawing on your own? GDI+ has no problems
handling bitmaps with alpha transparency (e.g. PNGs).

I hacked together a little example:
http://udos.s3.amazonaws.com/USSimpleChess.zip

Just download it and install "US SimpleChess" in your image. After
fixing the path in ChessTileState>>tileImage you can evaluate
"USChessBoardView show": Clicking into the squares moves the figure.

Please note that the code /just works/. It's neither beautifull nor (I
assume) bug free. However it might give you a hint on how to proceed.

Hope this helps.

CU,

Udo
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:04 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.