Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another.
Copy an image's region to another. Copy an image's region to another.
Copy an image's region to another.
Go Back  Xtreme Visual Basic Talk > > > Copy an image's region to another.


Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2011, 12:13 PM
WhatsMyUsername's Avatar
WhatsMyUsername WhatsMyUsername is offline
Regular
 
Join Date: Jan 2011
Location: Currently? Costa Rica
Posts: 52
Default Copy an image's region to another.


Following my test project for making a map editor, I finally got the tile selection part covered.
The application can already tell which tile(s) is selected.

So now we will work on "click the map and the tiles will be drawn" part.

When the user clicks the map, I need to "copy" a selected tiles in the tile selector, and "paste" them on the map. The process is a bit longer actually.

My idea was to first create a new Bitmap. Then draw into it the selected tiles. And then, on my map picturebox Graphics, use the .draw_image function taking the new Bitmap as parameter.

Or is there a way to directly copy the selected tiles to the map image?
Reply With Quote
  #2  
Old 01-25-2011, 02:04 PM
AtmaWeapon's Avatar
AtmaWeaponCopy an image's region to another. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

It sounds like you need a tilemap.

A tilemap is a 2D array of numbers where each number represents a tile from the possible tiles. To draw, you loop over each element and draw the corresponding tile for the number.

Your tile selector probably already stores the tiles in such a way that you could number them. If not, the formula rowIndex * columns + columnIndex is a convenient way to convert 2D coordinates into a continuous set of 1D indices.

You might start off with the tilemap using -1 for each element to represent "no tile", or you might just initialize it to some default tile. When the user selects a tile from the tile selector, stash its index. When the user clicks the map, set the element that represents where the clicked to the index of the selected tile. Then repaint the map; if you don't want to repaint the whole thing just repaint the tile that changed.

You could probably get by using Bitmap values instead of integers in the tilemap, but that would make saving a map file a bit more difficult and I presume that's the next step.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 01-25-2011, 08:51 PM
WhatsMyUsername's Avatar
WhatsMyUsername WhatsMyUsername is offline
Regular
 
Join Date: Jan 2011
Location: Currently? Costa Rica
Posts: 52
Default

I was using hashes. But now that I think of it......... heck. I will remake the application since things got messy (but it won't be a problem, it should be very fast now)

By the way, I am already attempting to copy a rectangle from the tileset image to the map image. But I still can't find a way to copy the rectangle region and paste it =/

Edit: The user can change the map size. If he/she increases the map size, it is possible to also resize the arrays right?
Reply With Quote
  #4  
Old 01-25-2011, 08:54 PM
AtmaWeapon's Avatar
AtmaWeaponCopy an image's region to another. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'm quite confused what that means. If you have the tile in the tileset image, you must have an Image (Bitmap is derived from that so it counts too.) You don't need to copy it, just reuse that object or reload it from the same source and draw it.

Otherwise you'd have to more or less take a screen capture of the tilemap, cut out a small piece, then draw the piece you cut out. It's like lighting a fire by burning wood to create charcoal, cooling the charcoal, then using newspaper and fluid to light the charcoal. Skip the silly steps.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 01-26-2011, 08:26 PM
WhatsMyUsername's Avatar
WhatsMyUsername WhatsMyUsername is offline
Regular
 
Join Date: Jan 2011
Location: Currently? Costa Rica
Posts: 52
Default

I know, I have the tileset image alright, I can reuse it and everything, but.. I don't know how to... err.. draw just a.... part of it. Heck, why is it so hard to explain! Here:

http://i.imgur.com/1WECx.png
Reply With Quote
  #6  
Old 01-27-2011, 06:24 AM
snarfblam's Avatar
snarfblamCopy an image's region to another. snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 896
Default

You need a Graphics object to do drawing. If you're drawing directly to the screen, you can call CreateGraphics on a control to get the Graphics object. The better solution would be to understand the invalidation/painting cycle, and handle the Paint event in which you would be provided with a Graphics object. If you're drawing to another Bitmap, you can call Graphics.FromImage to get a Graphics object for that Bitmap.

Once you have a Graphics object, you can call Graphics.DrawImage to draw part of an image. There are many (far too many) overloads. To draw part of an image, I prefer to use this overload:
Code:
public Sub DrawImage( _
    image As Image, _
    destRect As Rectangle, _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit)
The srcRect and destRect specify where you want to draw from and to.

It's important to specify the units (as pixels) because otherwise GDI+ will try to draw the image at "actual size" taking into account the user's never-properly-configured screen DPI and the erroneous/irrelevant image's DPI data, and the drawn images will be over-sized and blurry.
__________________
C# _VB.NET _
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another. Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another. Copy an image's region to another.
Copy an image's region to another.
Copy an image's region to another.
 
Copy an image's region to another.
Copy an image's region to another.
 
-->