QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: codevsb12 on February 13, 2020, 06:44:53 pm

Title: convert bmp to data
Post by: codevsb12 on February 13, 2020, 06:44:53 pm
help me, im about to make my first game and i made the graphics separately in .bmp. is there a site or software that can convert a bitmap image to data for use in qbasic? and NO i wont make a header or else the code will be extremely huge for a simple dos game.
Title: Re: convert bmp to data
Post by: FellippeHeitor on February 13, 2020, 06:49:48 pm
Just use _LOADIMAGE?
Title: Re: convert bmp to data
Post by: Pete on February 14, 2020, 12:18:59 am
Ah, old school. You know who knows all about this, TheBOB. I'll put up the bat signal on the ol' QB Forum site...

Pete
Title: Re: convert bmp to data
Post by: SMcNeill on February 14, 2020, 12:40:34 am
pic = _LOADIMAGE(“mybmpfile.bmp”)
_SOURCE pic
ImageHeight = _HEIGHT - 1
ImageWidth = _WIDTH - 1

OPEN “mybmpdata.txt” FOR OUTPUT AS #1

FOR y = 0 to ImageHeight
    FOR x = 0 to ImageWidth
        kolor = POINT(x,y)
        PRINT #1, kolor
    NEXT
NEXT



You now have all the x/y color values in a text file which you can now read with INPUT and PSET for use in QB45 programs.
Title: Re: convert bmp to data
Post by: Pete on February 14, 2020, 12:39:29 pm
Well the ^^0^^ signal worked. Would color be an issue? Bob didn't see a way to get the pixels color in Steve's code, and questioned if the POINT function would work if a 24-bit image was being used; so he came up with this code that could be added...

Code: QB64: [Select]
  1. '4/8-bit palette; output to file
  2. OUT &H3C7, 0
  3. FOR n% = 1 TO 48' or 768 for 8-bit
  4. Hue% = INP(&H3C9)
  5. PRINT #1, Hue%
  6. NEXT n%
  7.  
  8. 'input from file and set the palette
  9. OUT &H3C8, 0
  10. FOR n% = 1 TO 48 'or 768
  11. INPUT #1, Hue%
  12. OUT &H3C9, Hue%
  13. NEXT n%

There's a bit more explanation. To view the entire thread, go to: https://www.tapatalk.com/groups/qbasic/viewtopic.php?p=213140#p213140

As always, don't shoot me, I'm only the messenger, and FYI, I shoot back! :D

Pete
Title: Re: convert bmp to data
Post by: Petr on February 14, 2020, 03:55:53 pm
In terms of size, what to BMP files convert to PNG or JPG and then use BASE64 to store this binary data with only a slight increase in size? If the program will be for QB64? BASE64 saves this as text in DATA blocks and can also convert it back. Try a few experiments with ready BASE64 converters from / to source here: 

https://www.qb64.org/forum/index.php?topic=2017.msg112443#msg112443     - my version (not so fast)
https://www.qb64.org/forum/index.php?topic=2041.0                                        - AndyA version (really fast)

If you convert your images to source code as BASE64 text, then you secure your images in exe file. Then, if exe file start, you can extract this images from exe to harddrive, then load it to memory and delete from disk.