Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Splitting images WITH Alpha channel

Author
Message
Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 9th Jan 2011 14:41
For my current project I have a function in place to load and split an image into several smaller images with increasing image numbers, where "first" is the number of the first image and hor and ver tell the routine into how many pieces the image is to be split.
TempBmp and ScreenBmp are constants pointing to the appropriate bitmaps.



This should be kind of similar to what the animated sprite loading routine does but since I need to paste the seperate images at will onto another bitmap I cannot use sprites to do this.

The routine itself works perfectly but it has one mayor setback which I don't know how to solve:
I would like to split the initial image with the same result AND keep any alphachannel-data on the imageparts intact (I am using PNG images here).

Right now I am only "cheating" on this by putting the background of the picture into the smaller pictures but this kind of makes it very unflexible.
I was thinking of memblocks but unfortunately I still need to get into memblocks
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Jan 2011 16:58
before creating the bitmap:

SET BITMAP FORMAT 21

That will fix it

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Jan 2011 17:32
You might want to take a look at this snippet I made awhile ago which will load an image into a memblock and cut it into individual tile images.
http://forum.thegamecreators.com/?m=forum_view&t=164293&b=6

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Jan 2011 17:42 Edited at: 9th Jan 2011 17:43
You could also use Image Kit to divide your images without creating/editing a bitmap using ik copy image.

Quote: "I was thinking of memblocks but unfortunately I still need to get into memblocks"


I encourage you to do so. It is usually faster than using get image.

[edit] Lol, Phaelax I was looking for that one but couldn't find it

Cheers!
Sven B

Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 9th Jan 2011 20:10
Quote: "before creating the bitmap:

SET BITMAP FORMAT 21

That will fix it "


lol, why is the solution for a problem I've been trying to solve always that simple
I didn't have to change a single line of code except for adding this command once to make it work as intended.

The other two solutions also look very promising. The memblock version looks like it can be easily modified to work with the different image segmentations I use, so I won't have to change a single command outside the function. I'm guessing this will also be much faster then my Get Image solution.

The image kit solution also looks very interesting, I'll take a closer look at that as well.

Are those two solutions free to use in a game intended to be sold (as shareware or something like that) at some point?

Thanks for the help everyone!
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Jan 2011 21:22
Quote: "Are those two solutions free to use in a game intended to be sold (as shareware or something like that) at some point?"


Of course. Image Kit is completely royalty free.
Not sure about phaelax's code, but he's a nice guy so I don't think he'll mind

Cheers!
Sven B

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Jan 2011 23:18
The memblock method is much faster than GET IMAGE. I created exactly the same solution myself a few years ago and timed them to compare, it was lightning fast in comparison. If you get your head around the methods, it comes in handy for so many more techniques.

Sven's Image Kit is fantastic, I use it mainly for resizing images with good quality, but would use the other commands when I see a need.

GET IMAGE is perfectly fine if you intend to chop up your images outside of the game loop.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jan 2011 02:04
Yup, my code is free to use

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein

Login to post a reply

Server time is: 2026-07-21 20:36:13
Your offset time is: 2026-07-21 20:36:13