drawing_20a_20transparent_20bitmap
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
drawing_20a_20transparent_20bitmap [2018/03/31 13:19] – external edit 127.0.0.1 | drawing_20a_20transparent_20bitmap [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
* Create the image as a 32-bits-per-pixel ARGB bitmap, in which each pixel consists of a 24-bit **RGB** value (8 bits red, 8 bits green, 8 bits blue) plus an 8-bit **alpha** value. The alpha value defines a ' | * Create the image as a 32-bits-per-pixel ARGB bitmap, in which each pixel consists of a 24-bit **RGB** value (8 bits red, 8 bits green, 8 bits blue) plus an 8-bit **alpha** value. The alpha value defines a ' | ||
* Create the image as a **Transparent GIF** or **PNG** and display it using, for example, the code listed [[/ | * Create the image as a **Transparent GIF** or **PNG** and display it using, for example, the code listed [[/ | ||
- | \\ //by Michael Hutton, July 2009//\\ \\ How do you make a part of a bitmap transparent? | + | \\ //by Michael Hutton, July 2009//\\ \\ How do you make a part of a bitmap transparent? |
- | * [[/ | + | First select a MODE and define some constants: |
- | * [[/ | + | |
- | * 7 KB | + | <code bb4w> |
- | \\ | + | |
- | ==== Explanation: | + | |
- | First select a MODE and define some constants:\\ | + | |
MODE 8 | MODE 8 | ||
Line 26: | Line 23: | ||
cx% = 64 : REM width | cx% = 64 : REM width | ||
cy% = 64 : REM height | cy% = 64 : REM height | ||
- | Next, we have to load the MSIMG32.DLL into memory and get the address of the " | + | </ |
+ | |||
+ | Next, we have to load the MSIMG32.DLL into memory and get the address of the " | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
- | Next, load the image we want (we will assume it's in the same directory and is called star.bmp).\\ | + | </ |
+ | |||
+ | Next, load the image we want (we will assume it's in the same directory and is called star.bmp). | ||
+ | |||
+ | <code bb4w> | ||
bmpfile$ = @dir$ + " | bmpfile$ = @dir$ + " | ||
SYS " | SYS " | ||
IF hbitmap% = 0 THEN ERROR 100," | IF hbitmap% = 0 THEN ERROR 100," | ||
- | Now, because we are using GDI and we only have a handle to the bitmap we have to create a new Device Context and select our bitmap into it. (A bitmap can only be selected into one DC at a time).\\ | + | </ |
+ | |||
+ | Now, because we are using GDI and we only have a handle to the bitmap we have to create a new Device Context and select our bitmap into it. (A bitmap can only be selected into one DC at a time). | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
- | \\ | + | </ |
+ | |||
+ | Now, we can ask GDI to transfer that bitmap into our main window. When using " | ||
+ | |||
+ | <code bb4w> | ||
FOR I% = 0 TO 50 | FOR I% = 0 TO 50 | ||
xpos% = RND(640) | xpos% = RND(640) | ||
Line 48: | Line 61: | ||
WAIT 1 | WAIT 1 | ||
NEXT | NEXT | ||
- | \\ | + | </ |
+ | |||
+ | Now we must remember to cleanup all the GDI objects we have created otherwise we will end up with a leak. | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
Line 54: | Line 71: | ||
SYS " | SYS " | ||
END | END | ||
- | \\ | + | </ |
+ | |||
+ | The example | ||
+ | |||
+ | <code bb4w> | ||
MODE 8 | MODE 8 | ||
Line 95: | Line 116: | ||
END | END | ||
- | \\ | + | </ |
+ | |||
+ | And there we are! Enjoy.\\ \\ Michael Hutton |
drawing_20a_20transparent_20bitmap.1522502357.txt.gz · Last modified: 2024/01/05 00:18 (external edit)