Visual C# Windows Forms PictureBox Clipping and Color Filter

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

Visual C# Windows Forms PictureBox Clipping and Color Filter

Post by OmenFelix »

Hey guys I was wondering if I had a sprite-sheet and I wanted to load only a certain 32x32 region of it into a 'PictureBox' of a Windows Form, how would I go about doing that? Also as a bonus, how would I filter the Magenta(255,0,255) and render as alpha, like SDL colour-keying. NOTE: I'm not too bothered about the second question, as that can be done somewhat manually by creating a magenta to alpha program.

Thanks in advance. ;)
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Visual C# Windows Forms PictureBox Clipping and Color Fi

Post by dandymcgee »

A better questions is why would you want to do that? I hope this is an editor question..
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

Re: Visual C# Windows Forms PictureBox Clipping and Color Fi

Post by OmenFelix »

dandymcgee wrote:A better questions is why would you want to do that? I hope this is an editor question..
Yes it is. It's only a temporary measure as none of the team really have experience with editors nor want to do much about it. Just to test the tiling system really.
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Visual C# Windows Forms PictureBox Clipping and Color Fi

Post by tappatekie »

OmenFelix wrote:Hey guys I was wondering if I had a sprite-sheet and I wanted to load only a certain 32x32 region of it into a 'PictureBox' of a Windows Form, how would I go about doing that? Also as a bonus, how would I filter the Magenta(255,0,255) and render as alpha, like SDL colour-keying. NOTE: I'm not too bothered about the second question, as that can be done somewhat manually by creating a magenta to alpha program.

Thanks in advance. ;)
You could use cropping?

Code: Select all

Bitmap bmp = new Bitmap(32,32);
//Draw the spritesheet bitmap
Graphics.DrawImage(spritesheet, new Rectangle(-spiteX, -spriteY, 32, 32));
//Set the picture box image and size
pictureBox.Image = bmp;
pictureBox.Size = bmp.Size;
spriteX and spriteY is negative since we want to offset the render of the main sprite image and select 32x32 pixels of it.
It'l do the job...

This however may not be the best way to go about this since I'm not sure than rendering the spritesheet for every sprite is as-efficent.

You could also use

Code: Select all

Bitmap mySprite = (Bitmap)spritesheet.Clone(new Rectangle(spriteX, spriteY, 32,32), PixelFormat.Gdi);
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

Re: Visual C# Windows Forms PictureBox Clipping and Color Fi

Post by OmenFelix »

tappatekie wrote:
OmenFelix wrote:Hey guys I was wondering if I had a sprite-sheet and I wanted to load only a certain 32x32 region of it into a 'PictureBox' of a Windows Form, how would I go about doing that? Also as a bonus, how would I filter the Magenta(255,0,255) and render as alpha, like SDL colour-keying. NOTE: I'm not too bothered about the second question, as that can be done somewhat manually by creating a magenta to alpha program.

Thanks in advance. ;)
You could use cropping?

Code: Select all

Bitmap bmp = new Bitmap(32,32);
//Draw the spritesheet bitmap
Graphics.DrawImage(spritesheet, new Rectangle(-spiteX, -spriteY, 32, 32));
//Set the picture box image and size
pictureBox.Image = bmp;
pictureBox.Size = bmp.Size;
spriteX and spriteY is negative since we want to offset the render of the main sprite image and select 32x32 pixels of it.
It'l do the job...

This however may not be the best way to go about this since I'm not sure than rendering the spritesheet for every sprite is as-efficent.

You could also use

Code: Select all

Bitmap mySprite = (Bitmap)spritesheet.Clone(new Rectangle(spriteX, spriteY, 32,32), PixelFormat.Gdi);
This code isn't for a PictureBox is it?
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Visual C# Windows Forms PictureBox Clipping and Color Fi

Post by tappatekie »

OmenFelix wrote:
tappatekie wrote:
OmenFelix wrote:Hey guys I was wondering if I had a sprite-sheet and I wanted to load only a certain 32x32 region of it into a 'PictureBox' of a Windows Form, how would I go about doing that? Also as a bonus, how would I filter the Magenta(255,0,255) and render as alpha, like SDL colour-keying. NOTE: I'm not too bothered about the second question, as that can be done somewhat manually by creating a magenta to alpha program.

Thanks in advance. ;)
You could use cropping?

Code: Select all

Bitmap bmp = new Bitmap(32,32);
//Draw the spritesheet bitmap
Graphics.DrawImage(spritesheet, new Rectangle(-spiteX, -spriteY, 32, 32));
//Set the picture box image and size
pictureBox.Image = bmp;
pictureBox.Size = bmp.Size;
spriteX and spriteY is negative since we want to offset the render of the main sprite image and select 32x32 pixels of it.
It'l do the job...

This however may not be the best way to go about this since I'm not sure than rendering the spritesheet for every sprite is as-efficent.

You could also use

Code: Select all

Bitmap mySprite = (Bitmap)spritesheet.Clone(new Rectangle(spriteX, spriteY, 32,32), PixelFormat.Gdi);
This code isn't for a PictureBox is it?
You can apply the code to a picture box... with "pictureBox.Image = croppedBitmap;", the cropped bitmap would be the mySprite bit in the code...

Unless you want the picturebox to only show a certain part of the image (spritesheet) with the picture box image property set to the spritesheet image, if so, please be more specific, you said to "load only a certain 32x32 region of it into a 'PictureBox' " ("INTO"...)
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

Re: Visual C# Windows Forms PictureBox Clipping and Color Fi

Post by OmenFelix »

tappatekie wrote:
OmenFelix wrote:
tappatekie wrote:
OmenFelix wrote:Hey guys I was wondering if I had a sprite-sheet and I wanted to load only a certain 32x32 region of it into a 'PictureBox' of a Windows Form, how would I go about doing that? Also as a bonus, how would I filter the Magenta(255,0,255) and render as alpha, like SDL colour-keying. NOTE: I'm not too bothered about the second question, as that can be done somewhat manually by creating a magenta to alpha program.

Thanks in advance. ;)
You could use cropping?

Code: Select all

Bitmap bmp = new Bitmap(32,32);
//Draw the spritesheet bitmap
Graphics.DrawImage(spritesheet, new Rectangle(-spiteX, -spriteY, 32, 32));
//Set the picture box image and size
pictureBox.Image = bmp;
pictureBox.Size = bmp.Size;
spriteX and spriteY is negative since we want to offset the render of the main sprite image and select 32x32 pixels of it.
It'l do the job...

This however may not be the best way to go about this since I'm not sure than rendering the spritesheet for every sprite is as-efficent.

You could also use

Code: Select all

Bitmap mySprite = (Bitmap)spritesheet.Clone(new Rectangle(spriteX, spriteY, 32,32), PixelFormat.Gdi);
This code isn't for a PictureBox is it?
You can apply the code to a picture box... with "pictureBox.Image = croppedBitmap;", the cropped bitmap would be the mySprite bit in the code...

Unless you want the picturebox to only show a certain part of the image (spritesheet) with the picture box image property set to the spritesheet image, if so, please be more specific, you said to "load only a certain 32x32 region of it into a 'PictureBox' " ("INTO"...)
Thanks! I'll try it later. :3
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
Post Reply