Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

(Solved)How to get a part of an image? J# (C# can work too)

I'm trying to code a map editor to learn new stuff and I've done pretty much everything except when i click on the screen it's gonna draw that picture on so doesn't i know how to get that part of the image I selected. So, can anyone help me on how to get a part of the image?

as stated so do i code in J# but i can often translate C# to J#

and yes I've been searching on google... for hours...
and here's a screenshot of my editor I'm making to just learn new stuff:

http://i48.servimg.com/u/f48/11/28/71/73/my_map10.png[/img]
 
Well, when you are blitting images, there should be an optional paramater you can pass for src rect or source or something similar. So you want to blit the tileset image to the map using the src_rect to blit only the part of the image you want to blit. At least that is the way that I do it. I've never done it with any microsoft languages, though so it may be different.
 
i haven't seen anything about Blit and here's the for when mouse is over it and clicking on it

Code:
private void sceneryTilesPic_MouseMove(Object sender, MouseEventArgs e)
	{
		double x = System.Convert.ToDouble(e.get_X());
		double y = System.Convert.ToDouble(e.get_Y());

		x = (x / 32);
		x = Math.floor(x);
		y = (y / 32);
		y = Math.floor(y);

		int xPosition = System.Convert.ToInt32(x * 32);
		int yPosition = System.Convert.ToInt32(y * 32);

		int x2 = Convert.ToInt32(x);
		int y2 = Convert.ToInt32(y);
		sceneryX = x2;
		sceneryY = y2;
		int ID = ((y2 * 10) + x2);
		if (newMap)
		{
			statusLabel.set_Text("Scenery Tile ID: " + ID + " Layer: " + (sceneryLayer + 1));
		}
	}

private void sceneryTilesPic_Click(Object sender, EventArgs e)
	{
		int xPosition = (sceneryX * 32);
		int yPosition = (sceneryY * 32);

		int ID = ((sceneryY * 10) + sceneryX);
		sceneryID = ID;

		sceneryTilesPic.Refresh();
		this.sceneryTilesPic.CreateGraphics().DrawRectangle(new Pen(sceneryRectangleColor, 2), (xPosition + 1), (yPosition + 1), 30, 30);

			tileIDSelected.set_Text("Scenery Tile ID Selected: " + sceneryID);

	}
 

OS

Sponsor

*The below is from my experience in C#

In the OnPaint method (or whatever you have called your Paint method), you need to use your GraphicsDevice's DrawImage method, using the parameters below:

graphics.DrawImage( image, source, destination, color );

Source is the part of the Rectangle in the Image you want to use, such as the grass tile in RMXP (at pos 0,0 in the image). The Rectangle would be at 0,0 with the dimensions 32,32.

The destination is the part of the Drawing Canvas/Pane/etc. that you are drawing to. It is also a Rectangle. (0,0),(32,32).

I hope this is helpful. Peace.
 
OS":28v8hzge said:
*The below is from my experience in C#

In the OnPaint method (or whatever you have called your Paint method), you need to use your GraphicsDevice's DrawImage method, using the parameters below:

graphics.DrawImage( image, source, destination, color );

Source is the part of the Rectangle in the Image you want to use, such as the grass tile in RMXP (at pos 0,0 in the image). The Rectangle would be at 0,0 with the dimensions 32,32.

The destination is the part of the Drawing Canvas/Pane/etc. that you are drawing to. It is also a Rectangle. (0,0),(32,32).

I hope this is helpful. Peace.

Thank you. I figured out the code from that and by the way it was:

graphics.DrawImage( Image, Destination, Source, GraphicsUnit);

here's my command for the drawing:
Code:
gameScreen.CreateGraphics().DrawImage(sceneryTilesPic.get_Image(), (x * 32), (y * 32), new Rectangle(i, j, 32, 32), GraphicsUnit.Pixel);

SOLVED Thanks to OS Tip

http://i48.servimg.com/u/f48/11/28/71/73/map_ed11.png[/img]
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top