News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Copy tiles from an image

Started by Kman1011, February 27, 2007, 07:28:34 PM

Previous topic - Next topic

Kman1011

In the docs it says that you can 'GETIMAGE' from a screen OR and Image

I used 'RenderToImage' but the program didn't work. I drew the image to the screen and copied from there fine.

I'm not sure what i did wrong. ???

; PROJECT : ImageExploder
; AUTHOR  : Kman
; CREATED : 2/27/2007
; EDITED  : 2/27/2007
; ---------------------------------------------------------------------
LoadImage "Enemy40.bmp",1

;DrawImage 1,0,0,0
imwid=GetImageWidth(1):imht=GetImageHeight(1)
rgridX=imwid/8:rgridY=imht/8

RenderToImage 1
For Y=0 To imht Step 8
For x=0 To imwid Step 8
Inc f
Print Str$(x)+" : "+Str$(y)
GetImage f,X,Y,X+8,Y+8
;PrepareFXImage f
Next x
Next y

Sync
WaitKey
WaitNoKey
Sync
f=0:RenderToScreen
Cls 0
For y=0 To imht Step 8
For x=0 To imwid Step 8
Inc f
DrawImage f,x*2,y*2,0
Next x
Next y

Sync
WaitKey

End


If you enable 'PrepareFXImage' the program gets a nasty runtime error.

If you see what i don't see..let me know

Thanx
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

gvillarreal

Hey Kman,

I think the problem you are having is that you are trying to GETIMAGE into an unallocated image number 'f'.

You need to do something like:


For Y=0 To imht Step 8
  For x=0 To imwid Step 8

    // Get a free image index
    f = GetFreeImage()

    // Allocate memory for the image
    CreateImage f,8,8

    Print Str$(x)+" : "+Str$(y)
    GetImage f,X,Y,X+8,Y+8
    PrepareFXImage f
  Next x
Next y


I haven't actually tested the above, but I think that should accomplish what you want.
You can also skip the 'PrepareFXImage f' by using 'CreateFXImage f,8,8'.

Hope that helps! :)
"The Matrix is the world that has been pulled over your eyes to blind you from the truth."  - Morpheus

Unplugging one mind at a time...

stef

Hi!

It would be better to store the grabbed images in an array or type

Lets say you want to split an 80x40 image into parts of 8x8:

dim f(9,4)
for x = 0 to 9
for y = 0 to 4
f(x,y)=getfreeimage()
createimage f(x,y)...

/
getimage f(x,y)...


next
next



Kman1011

OK!

I see what both of you are saying.

You have to initiate the image just like a sprite. You have to create it using 'getfreeimage()'

I never thought to use arrays but in this game I should use it to track the individule parts.

I'll test run this and keep you posted on results..

Thanx :)
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

kevin


You can use GetImage to grab/copy sections of either existing images or to create new images.   It behaves like the following.


* If the Image number you supply doesn't exist. 

    1)  It creates this image of size   x2-x1, y2-y1
    2) Then it copies the rect of pixels from the current buffer to the new image

   ie.

     GetImage  100,0,0,16,16

    ='s

   CreateImage 100, 16-0,16-0
   CopyREct CurrentSurface(),0,0,16,16,100,0,0
     

* If the Image number you supply already exists and is the same size as the get image region. 
     1) it just copies the rect of pixels from the current buffer to the new image, so it basically just doing a CopyRect

However,  that's the way it should work, but there does seem to be something odd running your demo in PB1.59 & 1.67 here.   What version are you running ??


Kman1011

#5
I'm using Version 1.49. This is a full version I'm using. I downloaded all the updateds i recieved too.

I guess I need to upgrade. I thought i had the latest release.

CopyRect doesn't show up in my docs. However when I use 'Getfreeimage()' (as gvillarreal suggested)the demo actually works.

Perhaps I need to get 1.67.

Right now i'm just getting the mathematics to simulate an explosion of the image using rotation,scale etc..

Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

kevin


QuoteI guess I need to upgrade. I thought i had the latest release.

  There are number of patches newer than 1.49

  Patches starting at PB1.49


QuoteCopyRect doesn't show up in my docs. However when I use 'Getfreeimage()' (as gvillarreal suggested)the demo actually works.

  Have you updated the doc's package ?  The CopyRect command was added in September 2005 - although that doesn't necessarily mean it was documented in that edition.  Many new commands aren't!

  The best way to find NEW commands or functionality changes, is to  always read the HISTORY files for new releases.   




QuotePerhaps I need to get 1.67.

  not necessary.