[racket] make only selected color to transparent

33 views
Skip to first unread message

김태윤

unread,
Nov 20, 2010, 8:55:22 PM11/20/10
to users
it's about 10 hours since I stuck at overlaying several images
(make only selected color to transparent)
could somebody give me an little advice?
just little hint about big picture would be very helpful for me.
please~~!

#lang racket/gui
(define base-dc (make-object bitmap-dc% (make-object bitmap% 320 320 #f) ))
(define m-canvas%
  (class canvas%
    (override on-paint)
    (define on-paint (λ () (send (send this get-dc) draw-bitmap (send base-dc get-bitmap) 0 0)))
    (super-new)))
(define color (make-object color% "red"))
(define f (new frame% (label "a")))
(define c (new m-canvas% (parent f)(min-width 320) (min-height 320)))
(send base-dc draw-bitmap (make-object bitmap% "./src/arena.png") 0 0 )
(send base-dc set-argb-pixels 0 0 288 256 (make-bytes (* 4 288 256)))
(send base-dc draw-bitmap (make-object bitmap% "./src/char4.png") 0 0 )
(send f show #t)

Matthew Flatt

unread,
Nov 21, 2010, 9:08:06 AM11/21/10
to 김태윤, users

Is the problem that "arena.png" and "char4.png" are images with
transparency, but `draw-bitmap' draws them solid?

If so, you need to supply 'png/mask as the after the pathname when
loading the bitmap

(define bm1 (make-object bitmap% "./src/arena.png" 'png/mask))

and then use the bitmap mask when drawing:

(send base-dc draw-bitmap bm1
0 0 solid
(send the-color-database find-color "black")
(send bm1 get-loaded-mask))


It's much simpler in the current development version of Racket, where
transparency is more directly supported on bitmaps. In version
5.0.99.2,

(send base-dc draw-bitmap (read-bitmap "./src/arena.png") 0 0)

automatically loads and uses transparency information.

_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/users

김태윤

unread,
Nov 21, 2010, 9:34:26 AM11/21/10
to Matthew Flatt, users
thank you so much!
it works very well~!
and I realize that the png files what I used is does not have any transparency 
could you let me know how to set a color as transparent as well?

Jens Axel Søgaard

unread,
Nov 21, 2010, 9:45:31 AM11/21/10
to 김태윤, users
> and I realize that the png files what I used is does not have any
> transparency
> could you let me know how to set a color as transparent as well?

Here is how to do it in GIMP:

http://fabiovisentin.com/tutorial/GIMP_transparent_image/gimp_how_to_make_transparent_image.asp


--
Jens Axel Søgaard

Reply all
Reply to author
Forward
0 new messages