Author Topic: How to create images?  (Read 4072 times)

0 Members and 1 Guest are viewing this topic.

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
How to create images?
« on: July 15, 2021, 04:45:57 am »
I think it is a simple issue... but I haven't found nothing.
I don't have to load images into QB64, I have to transform images created with QB64 in images as PNG, BMP, JPG. How to do that?

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: How to create images?
« Reply #1 on: July 15, 2021, 05:25:47 am »
From what you are saying, and the way that I understand what you are saying, is that you need to transform or convert images into other graphics formats? If that is the case, then I am not sure if QB64 has a method of doing that, but you best method would be to use a graphics editor like Photoshop or Gimp to convert the images.

I hope this helps.

J

ps: If I have mis-understood your meaning then I apologize.
Logic is the beginning of wisdom.

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: How to create images?
« Reply #2 on: July 15, 2021, 05:43:25 am »
From what you are saying, and the way that I understand what you are saying, is that you need to transform or convert images into other graphics formats? If that is the case, then I am not sure if QB64 has a method of doing that, but you best method would be to use a graphics editor like Photoshop or Gimp to convert the images.

I hope this helps.

J

ps: If I have mis-understood your meaning then I apologize.

no no. I have images like "image&" created in QB64 with _NEWIMAGE and graphics statements, like LINE, POINT and so on, and I want to create the corresponding output files, in PNG or BMP or JPG format, for example.

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: How to create images?
« Reply #3 on: July 15, 2021, 05:50:31 am »
@bartok

If your created images are actually shown on the computer screen you can do this a number of ways...

A non-QB64 way in Windows 10 is to take a screenshot (---> .png file) and then use eg MS Paint to convert the .png to other formats.

A very fast QB64 way (using _MEM memory blocks) is an adaption of @SMcNeill method in Steve's Save Image2.3


https://www.qb64.org/forum/index.php?topic=2701.0


to save a .BMP  etc. file.

If your images are stored in an array, you can use BSAVE (not recommended use PUT # instead) - refer

 QB64 IDE  > Help > Keyword Index > BSAVE   (example 2  BSAVEing a bitmap)


Hope the above helps.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: How to create images?
« Reply #4 on: July 15, 2021, 06:12:13 am »
Bartok,

Ah. My mistake. I had obviously misunderstood your request. Just ignore my suggestion and go with Richard's.

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to create images?
« Reply #5 on: July 15, 2021, 07:30:32 am »
I think it is a simple issue... but I haven't found nothing.
I don't have to load images into QB64, I have to transform images created with QB64 in images as PNG, BMP, JPG. How to do that?

Steve McNeill has code for that
https://www.qb64.org/forum/index.php?topic=1651.0

I used it and works pretty well, Ken Sierra used it to save pictures drawn in his Paint like program if I recall :)
Update: maybe it was Dav who set him up with something...  but Dav's not here (as much), he's got gig's again. :)

@SMcNeill  might have a more current SaveImage version floating around in another thread with a bug fix.

From Steve's forum (currently closed to new members):
https://qb64.freeforums.net/thread/55/save-image-library
« Last Edit: July 15, 2021, 07:54:55 am by bplus »

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: How to create images?
« Reply #6 on: July 16, 2021, 03:17:21 am »
This subroutine works perfectly:

http://www.qb64.org/wiki/SAVEIMAGE

but I have to say that I don't have understood anything at all how it works, also reading the explanation.

Starting from:
  b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)             

It a mystery. Someone has an idea?

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: How to create images?
« Reply #7 on: July 16, 2021, 03:39:05 am »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How to create images?
« Reply #8 on: July 16, 2021, 06:55:58 am »
Steve McNeill has code for that
https://www.qb64.org/forum/index.php?topic=1651.0

@SMcNeill  might have a more current SaveImage version floating around in another thread with a bug fixes.

As far as I know, v2.3b is probably going to be the last, and final, version of SaveImage.  (It’s the version linked to above.)

As it exists, it saves images as PNG, BMP, JPG, and GIF formats.  I really don’t have the time, interest, or need to decode some other image format, so I doubt I’ll expand it to add additional formats anytime soon.  (I’d once considered adding the webp format, but then I learned it’s not universally adopted, and I really don’t have a need for anything else.)

V2.3b fixes all the known bugs and reported issues that I know of, and unless something in QB64 (or the c-compiler we use)  itself changes over time, or somebody reports an issue that needs fixing, it’ll probably sit unchanging for the foreseeable future.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bartok

  • Newbie
  • Posts: 80
    • View Profile
Re: How to create images?
« Reply #9 on: July 16, 2021, 12:13:46 pm »
Transform an image& into a file, I see that it is not so easy as to load a file into an image&. Probabily it would be a good idea to create a specific QB64 command to do that. I have finally taken the subroutine (http://www.qb64.org/wiki/SAVEIMAGE) even if I absolutely didn't understand anything of it, but it works fine. Never mind the code od SMCNeil that it count even 3 files... and that is even more complicated! Maybe I will try to undestand when I finish the program.

Offline RhoSigma

  • QB64 Developer
  • Forum Resident
  • Posts: 565
    • View Profile
Re: How to create images?
« Reply #10 on: July 16, 2021, 02:55:26 pm »
As far as I know, v2.3b is probably going to be the last, and final, version of SaveImage.  (It’s the version linked to above.)

Hi @SMcNeill, just note you're a step further already 2.3c:
https://www.qb64.org/forum/index.php?topic=2701.0
My Projects:   https://qb64forum.alephc.xyz/index.php?topic=809
GuiTools - A graphic UI framework (can do multiple UI forms/windows in one program)
Libraries - ImageProcess, StringBuffers (virt. files), MD5/SHA2-Hash, LZW etc.
Bonus - Blankers, QB64/Notepad++ setup pack

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How to create images?
« Reply #11 on: July 16, 2021, 03:18:03 pm »
This subroutine works perfectly:

http://www.qb64.org/wiki/SAVEIMAGE

but I have to say that I don't have understood anything at all how it works, also reading the explanation.

Starting from:
  b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)             

It a mystery. Someone has an idea?

BMP files are actually rather simple to create and decode.  The way they work is to basically store your image in 2 parts — the header and then the data.

The header is a leading batch of information that basically stores your height, width, color size, and such, and it looks like:

TYPE BMPEntry              ' Description                          Bytes    QB64 Function
   ID AS STRING * 2        ' File ID("BM" text or 19778 AS Integer) 2      CVI("BM")
   Size AS LONG            ' Total Size of the file                 4      LOF
   Res1 AS INTEGER         ' Reserved 1 always 0                    2
   Res2 AS INTEGER         ' Reserved 2 always 0                    2
   Offset AS LONG          ' Start offset of image pixel data       4      (add one for GET)
END TYPE                   '                                 Total 14

TYPE BMPHeader          'BMP header also used in Icon and Cursor files(.ICO and .CUR)
   Hsize AS LONG           ' Info header size (always 40)           4
   PWidth AS LONG          ' Image width                            4      _WIDTH(handle&)
   PDepth AS LONG          ' Image height (doubled in icons)        4      _HEIGHT(handle&)
   Planes AS INTEGER       ' Number of planes (normally 1)          2
   BPP AS INTEGER          ' Bits per pixel(palette 1, 4, 8, 24)    2      _PIXELSIZE(handle&)
   Compression AS LONG     ' Compression type(normally 0)           4
   ImageBytes AS LONG      ' (Width + padder) * Height              4
   Xres AS LONG            ' Width in PELS per metre(normally 0)    4
   Yres AS LONG            ' Depth in PELS per metre(normally 0)    4
   NumColors AS LONG       ' Number of Colors(normally 0)           4       2 ^ BPP
   SigColors AS LONG       ' Significant Colors(normally 0)         4
END TYPE                   '                 Total Header bytes =  40 


After the header, unless you’re storing a color palette, or using RLE compression, comes the data, which is basically the color value of each pixel which encompasses an image.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: How to create images?
« Reply #12 on: July 16, 2021, 05:02:51 pm »
Hi @SMcNeill, just note you're a step further already 2.3c:
https://www.qb64.org/forum/index.php?topic=2701.0

The Librarian ought to update that some day.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How to create images?
« Reply #13 on: July 16, 2021, 05:12:01 pm »
Hi @SMcNeill, just note you're a step further already 2.3c:
https://www.qb64.org/forum/index.php?topic=2701.0

Aye, but this one was such an unique use-case correction, it’s more or less unnecessary except for Petr’s specific application.  It doesn’t really hurt to have the change for others, but in most use-cases, it’ll never affect anything one way or the other.  Personally, 2.3b is the version I tend to keep and use myself.  It corrected the CRC issues which sometimes rendered PNG images unreadable in certain apps, so I’d definitely suggest everyone *at least* use that version, or above, and not any of the older ones. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to create images?
« Reply #14 on: July 16, 2021, 05:18:25 pm »
The Librarian ought to update that some day.

Done!  Yeah I noticed this morning that Richard had already linked to the last updated version. I thought there was one after 2.3b.

@SMcNeill  are you still archiving at
https://qb64.freeforums.net

or just github now?