• Print

Author Topic: images  (Read 149 times)

23452

  • Jr. Member
  • **
  • Posts: 72
    • Email
images
« on: January 20, 2013, 07:10:49 PM »
I know this is probably really easy, but does anyone know how to save whats on the screen as an image and then use that image as the new screen.


Gorlock

  • Sr. Member
  • ****
  • Posts: 337
    • Email
Re: images
« Reply #1 on: January 20, 2013, 08:12:37 PM »
Try taking a look at these:

For program screen: http://qb64.net/wiki/index.php?title=PCOPY
For entire screen: http://qb64.net/wiki/index.php?title=SAVEIMAGE (also sorry, I think this is wrong, i used nircmd.exe in my program, but you can take a look into this)

EDIT: Woah just thought of an awesome idea, will post it in a second!
« Last Edit: January 20, 2013, 08:18:09 PM by Gorlock »

Gorlock

  • Sr. Member
  • ****
  • Posts: 337
    • Email
Re: images
« Reply #2 on: January 20, 2013, 08:27:40 PM »
Hehe, just made this, its fun to play with ;D

Code: [Select]
SCREEN _NEWIMAGE(640, 480, 32)
DO
    _LIMIT 4
    SHELL _HIDE "nircmd.exe savescreenshot a.jpg"
    a = _LOADIMAGE("a.jpg")
    _PUTIMAGE (0, 0)-(639, 479), a
LOOP UNTIL INKEY$ > ""
SYSTEM

You need nircmd.exe file in the program folder, I have included it as a file.

SMcNeill

  • Hero Member
  • *****
  • Posts: 2414
    • Email
Re: images
« Reply #3 on: January 20, 2013, 09:14:29 PM »
If you need to save the screen image for later, use my PNG Export Library:  http://www.qb64.net/forum/index.php?topic=9999.0

It allows you to take screen shots of your programs and save them for later.   :)
http://bit.ly/TextImage -- Library of QB64 code to manipulate text and images, as a BM library.
http://bit.ly/Color32 -- A set of color CONST for use in 32 bit mode, as a BI library.

http://bit.ly/DataToDrive - A set of routines to quickly and easily get data to and from the disk.  BI and BM files

DSMan195276

  • Hero Member
  • *****
  • Posts: 1978
  • Yes
    • Email
Re: images
« Reply #4 on: January 20, 2013, 10:37:14 PM »
I feel as though you're talking about a QB64 image, not a file image. In that case, there are a few options you have. The easiest (And slowest) Is to set your _DEST to '0' (Which is the screen) and _SOURCE to your new image. Then, just just use POINT and PSET to sequencally read (POINT) every pixel on the screen and PSET it into the new screen. This requires lots of reads and writes and is very slow.

The second way is by far a lot faster, but has the draw back of being a bit more complicated. You can use _MEMIMAGE to get the location of the images memory and store it in a _MEM. If you create a second image the same size as your screen, and then use _MEMIMAGE() to get _MEM's that point to both images, you can then use a single _MEMCOPY command to copy the contents of the screen's memory to the new images memory. example:

Code: [Select]
DIM src as _MEM, dest as _MEM
SCREEN _NEWIMAGE(640, 480, 32)
img& = _NEWIMAGE(640,480,32)
src = _MEMIMAGE(0)
dest = _MEMIMAGE(img&)
_MEMCOPY src, src.OFFSET, src.SIZE TO dest, dest.OFFSET

Much faster (Use $CHECKING:OFF on the _MEMCOPY to make it even faster). And a word to the wise: The Wiki currently notes that all _MEM's created by _MEMIMAGE should be freed. This is a BAD idea. I'm going to ask Galleon directly on this as the Wiki states this for every command returning a _MEM, but freeing the src/dest in the above example will free the memory currently being used by that image an will mostly likely seg fault your program when you try to access that image. So. Don't do it. If you want to free an image, use _FREEIMAGE.

Matt
"Cast your cares on the Lord and he will sustain you; he will never let the righteous be shaken" -- Psalm 55:22
QB64 Linux Installer

fluffrabbit

  • Sr. Member
  • ****
  • Posts: 393
Re: images
« Reply #5 on: January 20, 2013, 10:48:57 PM »
You could also do it the QBASIC way.

Code: [Select]
SCREEN 7

FOR x = 1 TO 50
    PRESET (RND * 320, RND * 200), 15
NEXT

DIM myimg%(imgbytes%(0, 0, 319, 199, 7))
GET (0, 0)-(319, 199), myimg%()

CLS

PUT (0, 0), myimg%()

END

FUNCTION imgbytes% (x1!, y1!, x2!, y2!, sm%)
SELECT CASE sm%
    CASE 1
        bpp% = 2
        p% = 1
    CASE 2
        bpp% = 1
        p% = 1
    CASE 7
        bpp% = 1
        p% = 4
    CASE 8
        bpp% = 1
        p% = 4
    CASE 10
        bpp% = 1
        p% = 2
    CASE 11
        bpp% = 1
        p% = 1
    CASE 12
        bpp% = 1
        p% = 4
    CASE 13
        bpp% = 8
        p% = 1
END SELECT
imgbytes% = 4 + INT(((PMAP(x2!, 0) - PMAP(x1!, 0) + 1) * (bpp%) + 7) / 8) * p% * (PMAP(y2!, 1) - PMAP(y1!, 1) + 1)
END FUNCTION

mcalkins

  • Hero Member
  • *****
  • Posts: 1269
    • qbasicmichael.com
    • Email
Re: images
« Reply #6 on: January 20, 2013, 11:00:05 PM »
_SCREENIMAGE

Regards,
Michael
The QBASIC Forum Community: http://www.network54.com/index/10167 Includes off-topic subforums.
QB64 Off-topic subforum: http://qb64offtopic.freeforums.org/

  • Print