Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Copying a Part of an Image to Paste in other Place

Author
Message
Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 00:04
Its about Get Image
and Yes this has been asked alot
I searched the forums and read lots of Post
But I still don't get it

Its concerning my 2D Editor and so far everythings good
I cutted especially the "items" out of other Images so I can use them

But then I got an Idea to change this and instead of always cutting them out I wanted to be able to load the actual "big" Image with all the Items in in and then being able to select an certain area of that Image (Like a House for example) and paste it on the Map.

The Problem is i don't fully understand how to do this as I read through the forum and got only more and more confused.

Im using Load Image to load it and then paste it instead of 0,0 Im pasting it to Top Right Border because the Map is actually on the Top Left Border

My Idea was to do something like this


Only result I get is a black Image in the Panel and nothing on the place where the image gets pasted
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Mar 2010 00:19 Edited at: 26th Mar 2010 00:24
I normally spend a lot of time telling newcomers they should be using Load Image when they have been mistakenly using Load Bitmap.

However, this time it's one of those rare occasions where it's the other way around.

This is exactly what Load Bitmap is for.

You should load your big image into a bitmap with Load Bitmap. But don't use bitmap 0, use bitmap 1 (or one of the 30 others) because if you use 0 it will be seen by the user.

All the bitmaps apart from 0 are hidden from the user.

Once the bitmap is loaded, use Set Current Bitmap to tell DB which bitmap you loaded the image into then go and do your Get Image(s). (If grabbing more than one, don't forget to use different image numbers).

When you've done that, use Set Current Bitmap to switch back to bitmap 0 and you can paste in the images you just grabbed wherever you want.

If you don't need the big image again, use Delete Bitmap to destroy it. If you do, then just leave it sitting there for when you need it and delete it when you exit the program.

Note that destroying a bitmap does NOT destroy the images grabbed from it with Get Image.

Quote: "and then paste it instead of 0,0 Im pasting it to Top Right Border"


You can't do it like that - you're effectively pasting the image off the screen, leaving a black screen and grabbing images off that.

But don't worry about that, forget it - if you use Load Bitmap it automatically places the image in the top left corner - you just need to know the top left and bottom right corner X/Y locations on the big image for the Get Image command - so it grabs the image from the correct place on the bitmap screen.

TDK

Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 00:35 Edited at: 26th Mar 2010 00:36
thanks for the quick reply
I'll test it as soon as I'm back home
Quote: "You can't do it like that - you're effectively pasting the image off the screen, leaving a black screen and grabbing images off that. "

Yea I meant more like the right side of the Image will be at the right side of the screen and the top of the Image on position Y=0

Something like this, and yea I actually drawed it in a post with symbols xD

Quote: "
You should load your big image into a bitmap with Load Bitmap. But don't use bitmap 0, use bitmap 1 (or one of the 30 others) because if you use 0 it will be seen by the user.

All the bitmaps apart from 0 are hidden from the user.
"


well in the Editor I could use 0 because the User has to see it
but for the Game later I'll use 1 to 30
I wanted the Editor to be Done befor I begin with the actual Game
Got the most Ideas already set for the Game but like I said I wanted to change the method of "getting" the Objects
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Mar 2010 00:54
Quote: "But then I got an Idea to change this and instead of always cutting them out I wanted to be able to load the actual "big" Image with all the Items in in and then being able to select an certain area of that Image (Like a House for example) and paste it on the Map."

If you are using tiles, this is probably not the best way to do it.

Normally in an editor you would plot the tiles into the Array one index at a time such as:


But if you want to select multiple tiles together like a house you'll best change the method of plotting tiles onto the array rather than grabbing images from the tileset.


There are many ways to determine the values of SpanX and SpanY, you can use the arrow keys to span your values, click and drag the mouse, or punch in the values.
Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 00:59
I am actually doing it exactly that way for a 1x1 Tile and for an 4x4 or bigger

its only: I didnt want to cut always the Objects out of those big images where all Objects are put together like I used to and then Load into a BlueGUI Listview (as an ImageListView)
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Mar 2010 01:09
Wait let me get this correct, do you only GetImage when you select the tiles from the tileset?

Are you using arrays to store the tile data or just plotting images onto the screen?
Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 01:32 Edited at: 26th Mar 2010 01:34
OK wait not get confused

I actually done everything with Arrays, the Arrays had stored in them what Tile has to use which Image

That means that different Tiles contain different Images
Like for Example: I got a Image for Grass and another one for Soil
The Tile/Array(x,y) which was "Painted" with Grass contains the String "Grass.bmp" and another Tile/Array(a,b) which was "Painted" with Soil contains "Soil.bmp"

At the very start of the Editor, the Editor checks Specific Directories for Image Files and loads all of them
So when drawing/redrawing the Map everytime I Paint something onto it, it assigns the Tile with the proper Image/Sprite

but well that is another History
what Im after is:

Load a Big Image containing lots of Objects (Buildings in this case)
Divide it into lots of Tiles of Dimension 16x16

Now the hard part:
Put the Cursor over the Image and drag like a bigger Selection Box (like in most Painting Programs when Selected Areas)
The Selected Area gets "Copied"/Saved into an Array for example
And then whereever I click on the Map to "Paint", the Selected Area gets drawed

Heres an Image with the Cursor
I didnt impliment the Idea of Selecting a bigger Area than 1x1 for the moment as I try to get it to work the simplest way for a 1x1 Area atm
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Mar 2010 01:36 Edited at: 26th Mar 2010 01:39
[Edit] Ignore this post. While I was typing, you cleared a few things up which render my post void. What I thought you were doing is nothing like what you are actually doing!

Quote: "Yea I meant more like the right side of the Image will be at the right side of the screen and the top of the Image on position Y=0"


Ah OK - I understand now.

So to clarify:

The user sees this big image with lots of smaller images on it and he selects the house right? When he moves the mouse cursor over one of the 16 smaller images, a pop-up previews it.

You said you were getting black images - which means your Get Image rectangle is not set properly or the image isn't on the screen when you try to do the grab.

When you grab the house, you have to remember to add the offset value for X because the image is not at 0 like Y is.

Actually I just checked out your code snippet again and was wondering why you were pasting it as a sprite instead of an image?

There's no problem if it needs to be a sprite - I've just had to solve a similar problem with the Onion-skinning feature in Dark Sprites. You may have the same problem.

Paste Sprite doesn't appear work without a Sync to update the screen after creating the sprite and before pasting. But, if you don't actually need it to be a sprite, using Paste Image is preferable - and then the problem no longer exists.

It looks like your big image is a 4x4 grid of 16x16 images so I don't follow why you are grabbing the whole 64x64 rectangle when the mouse button is clicked.

Actually the whole snippet isn't making sense, as without the rest of the program, I'm probably reading it out of context. Especially the If MouseX() line which is just plain weird!

A such, this post is rapidly turning into a ramble. I just hope you can make some sense out of it when I've finished!

You are creating the sprite then pasting the sprite in the same place, but you aren't deleting it - so it's still there on top of the pasted version.

So, in a nutshell, assuming you are trying to do what I think you are, you are making it overly complicated. All you need to do is calculate the top left and bottom right corner's X and Y of the big image and deduct the top left X from the mouse's current X screen position.

If you divide this by the tile's X size and divide the mouse Y position by the tile's Y size you get the current column and row on the grid that the mouse is over.

GridY*4+GridX+1 (if I remember correctly) then gives you the image number to preview.

Finally, I noticed that you are starting some variable names with an underscore. I don't think this is a good idea, though a lot of people do it.

Starting labels with underscores is fine, but with variables you get confusing things like this line from your snippet:

for y=0 to _y

When I read it on here, I saw:

for y=0 to y

because the underscore merged with the line below. That threw me for a few minutes. Far too confusing for me lol!

TDK

Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 01:49
about the variables with underscore: its the first time Ive done it and Ive done it only on this piece of code because I was (like always infact) lazy of thinking of a Name
and Yea that really looks strange.

About the Editor now:
Its really hard to explain because one has to see the rest of the program befor one can really understand my (crazy, always too complicate thinking) mind behind it
I often do things much more complicated than needed, its only that Im like this: I get an Idea and I have to put it to code, the Optimization comes only at the End so I check if I couldve actually done it way easier

I also had the Idea of Posting the Editor onto the WIP Board but wasnt very sure as only the Editor is standing and no Game :/
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Mar 2010 06:10
You can post the codes here too, in fact it'll be easier to get help if you do post codes as I'm sure most of us here (me too) understand codes better than speech.
Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 17:01
Yes but posting only a part from this mad code would be even more confusing.

That's why I wrote a bit more Comments and Uploaded the Exe and the Project. I wasn't very eager of releasing the Source but as Im still learning I thought it would bring me more if I release it and People can take a look an tell me if Ive done well or if Im doing something way more complicated than it needs to be (like always when I program infact)

When somethings not clear tell me

Attachments

Login to view attachments
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Mar 2010 20:06 Edited at: 26th Mar 2010 20:08
Your editor looks very nice and easy to use .

I think I'm starting to understand. Do you want to copy the tiles on the Map for paste?

You will have to setup an array for copying. I have one such functionality in my own pokemon project.

To get this to work, you must have everything in the same tile size. I notice that your house size are not the same as your terrain, you must split your house into smaller tiles.

I'll show you my project to get an idea.

Controls:
- Ctrl+L to LoadMap
- Ctrl+S to SaveMap

MapArea:
- LeftClick will paste a selected tile to the Map.
- RightClick will erase a tile(s).
- Spacekey+LeftClick+Drag will scroll the MapArea.
- Ctrl+LeftClick+Drag will copy part of Map for paste.

SelectionArea:
- LeftClick will select a tile for paste.
- LeftClick+Drag will select multiple tiles for paste.
- Spacekey+LeftClick+Drag will scroll the SelectionArea.

Is this what you're asking about?

Attachments

Login to view attachments
Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 20:22 Edited at: 26th Mar 2010 20:23
Thanks

I see that Im still way behind
Ive got to do something about this, I really like your Editor, its well made imo

And yes thats exactly what Im trying to accomplish:
to select an Area of a Image that I then can paste onto the Map

Quote: " I notice that your house size are not the same as your terrain, you must split your house into smaller tiles."


Well the House is a 64x64 Image so according to my default Tile Size = 16, the House has a length and Width of 4, means 4x4

Or what exactly did You mean?
Im very open for Suggestions and Tips
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Mar 2010 20:54 Edited at: 26th Mar 2010 21:01
You have to cut your house into multiple tiles at size of 16x16, you shouldn't use as one large image of 64x64.

In fact the pokemon tiles are actually 8x8. My project use 8x8, I just scale sprite to 200%. You are able to make a lot more images with smaller tile size than you would with larger ones.

When selecting tiles from the map for paste, you are really copying the image pointer used in the array. If you are not using a true tile based structure then you cannot copy what is not there.

[edit]
Also keep in mind that a lot of work goes to preparing the tile set for this whole thing to work.
Sakuya
15
Years of Service
User Offline
Joined: 16th Feb 2009
Location: IB*ET
Posted: 26th Mar 2010 21:08
yeah at the Beginning I though of cutting one big into few small
this would solve the "problem", you could call it, of the thickness of the Objects.

I used to fill the Array where the house should be with "Block"
so infact only 1 Tile had the actuall Image

but now that You've remembered me what I was actually after, Ill have to rewrite my Functions a bit

Thanks

Ill try to change this probably this weekend
Will post the result here

If I got some more Questions Ill post them here
Im gonna show You soon a Nice Editor and someday the Game to it
Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Mar 2010 21:10
Awesome keep up the good work!
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Mar 2010 21:00 Edited at: 27th Mar 2010 21:05
Hi all there !

@Sakuya
@Ashingda 27 Nice codes !!

Time ago, I made my own 2D Editor for my purpose, and when I started, it was frustrating having to copy only the square areas.I couldn`t sleep at night...as I need to put a lot of palms all around the map...I didn`t want to see the fateful black area in my map, or in front of another object.So, I started with a subroutine that was capable of doing such work.
I`ll show you a part of this code, and you will realize, that you can prepare circular areas, triangle areas, a camel area all that you want....but we have to had images prepared.

It works, just using mask than can be just white if you want to copy directly from your image, or can be colored as a simple palm tree
I hope this code can help someone in the same boat.





I'm not a grumpy grandpa

Attachments

Login to view attachments
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Mar 2010 21:07
I double post as forum didnĀ“t let me adding file.rar and images

Here is the comple example.


cheers

I'm not a grumpy grandpa

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-24 17:38:09
Your offset time is: 2024-11-24 17:38:09