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

0 Members and 1 Guest are viewing this topic.

Offline codevsb12

  • Newbie
  • Posts: 23
    • View Profile
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.

FellippeHeitor

  • Guest
Re: convert bmp to data
« Reply #1 on: February 13, 2020, 06:49:48 pm »
Just use _LOADIMAGE?

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • 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: 2361
  • Cuz I sez so, varmint!
    • View Profile
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 »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
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 »