Author Topic: convert bmp to data  (Read 147 times)

Offline codevsb12

  • Newbie
  • Posts: 22
convert bmp to data
« 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.

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 1906
  • LET IT = BE
    • QB64.org
Re: convert bmp to data
« Reply #1 on: February 13, 2020, 06:49:48 PM »
Just use _LOADIMAGE?

Offline Pete

  • Forum Resident
  • Posts: 1730
  • Cuz I sez so, varmint!
Re: convert bmp to data
« Reply #2 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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 2371
    • Steve’s QB64 Archive Forum
Re: convert bmp to data
« Reply #3 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 1730
  • Cuz I sez so, varmint!
Re: convert bmp to data
« Reply #4 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
« Last Edit: February 14, 2020, 12:45:43 PM by Pete »

Offline Petr

  • Forum Resident
  • Posts: 1196
  • The best code is the DNA of the hops.
Re: convert bmp to data
« Reply #5 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.
« Last Edit: February 14, 2020, 03:57:31 PM by Petr »