# Using \`draw-bitmap\` and \`draw-bitmap-section\` with transparent color images

**URL:** https://racket.discourse.group/t/using-draw-bitmap-and-draw-bitmap-section-with-transparent-color-images/694
**Category:** Questions & Answers
**Created:** [February 14, 2022, 2:33pm UTC](https://racket.discourse.group/t/using-draw-bitmap-and-draw-bitmap-section-with-transparent-color-images/694 "2022-02-14T14:33:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [February 14, 2022, 2:33pm UTC](https://racket.discourse.group/t/using-draw-bitmap-and-draw-bitmap-section-with-transparent-color-images/694/1 "2022-02-14T14:33:29Z")

</div>

Hi All,

I need help to draw a "sprite" (small bitmap) on top of a bitmap.  
The sprite in question is consists of a transparent background and has a solid yellow circle in the center.

My test program looks like this (scroll to see the end of the program):

```scheme
#lang racket
(require racket/gui)
(define w 200)
(define h 200)

(define bm (make-object bitmap% w h))
(define dc (new bitmap-dc% [bitmap bm]))
(define black (send the-color-database find-color "black"))
(define sprite (make-object bitmap% "sprites.png"))

(send dc set-background black)
(send dc clear)
bm
sprite

(send dc set-smoothing 'unsmoothed)
(send dc draw-bitmap-section
      sprite ; source 
      0 0 ; dest
      0 0 16 16 ; source
      'solid ; ignored for color bitmaps
      black ; ignored for color bitmaps
      sprite ; use the α channel as mask
      )
bm

```

The output is shown below. It shows that the sprite is drawn on top of the black background.  
I was expecting a "solid" yellow, but the black background is seen below the sprite.

Why?

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/9df823426a9cb63a4cd4a59f9b64e6935e2df1e1.jpeg)

The image "sprites.png" is here:

![sprites](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/3c28ffd44348750c47c0b6c76269a23978e3edbe.png)

---

<div class="post-metadata">

### Author: ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)
#### Post date: [February 14, 2022, 3:01pm UTC](https://racket.discourse.group/t/using-draw-bitmap-and-draw-bitmap-section-with-transparent-color-images/694/2 "2022-02-14T15:01:50Z")

</div>

I think I found a fix:

```scheme
(define sprite (make-object bitmap% "sprites.png" 'png/alpha))

```

I think for some reason the implementation decides to just load your particular image with kind `'png` so to force it to load it with alpha I set it explicitly. I am not sure how it decides what kind to use when it is implicitly choosen and whether it can be influenced by the image and what format it has etc.

But I could imagine that images with particular formats may have different kinds assigned implicitly.  
For example I saw that your image uses indexed colors with an alpha channel which is relatively rare in circumstances I am used too, maybe that influences it? Well all of that is speculation for more answers we would have to dig into the implementation...

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [February 14, 2022, 3:06pm UTC](https://racket.discourse.group/t/using-draw-bitmap-and-draw-bitmap-section-with-transparent-color-images/694/3 "2022-02-14T15:06:40Z")

</div>

That's it!

I assumed that the png was loaded with its alpha channel automatically.

Thanks for find the error - it was beginning to bug me 🙂
