Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I found this code on the internet and thought that it would be nice to share with everyone who want to make a nice spash screen or something like it.

 

files :

- Bitmap2Region.cs

- Mouse.bmp

 

namespace : BitmapToRegion

How it work:

 

[size=2]Bitmap bmp = [/size][size=2][color=#0000ff]new[/color][/size][size=2] Bitmap(@"C:\mouse.bmp");
Region reg = BitmapToRegion.BitmapToRegion.Convert(bmp, Color.White, BitmapToRegion.TransparencyMode.ColorKeyTransparent);

[/size][size=2][color=#0000ff]this[/color][/size][size=2].BackgroundImage = Image.FromFile(@"C:\mouse.bmp");

[/size][size=2][color=#0000ff]this[/color][/size][size=2].Region = reg;[/size]

 

This is my code that I used with the current bmp. Just try it ! You'll probably find many utility to this little piece of code.

 

N.B.: It contains UNSAFE CODE.

To allow compilation of Unsafe code :

  1. Project / Properties
  2. Configuration Properties
  3. Under "Code Generation" set Allow unsafe code blocks to true.

Have fun !

 

-------------------------------------

 

[edit]I found that some "white" stay or that the image got cut sometime. I don't know what's the bug and if some find it... tell me ![/edit]

Bitmap2Region.zip

Edited by Arch4ngel

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

A code is called unsafe when it don't use the garbage collector.

This is the case for API function called from DLL. But if the code is well built... you can call it safe if you want :). The only danger with unsafe code is that it can cause memory leak. Unless that it's np.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

  • Administrators
Posted
Unsafe code does get garbage collected, you just have to follow a few rules before you are allowed to use memory in this way. Unsafe refers to the fact that you are calling code from outside the .Net managed environment and as such the .Net security policies cannot be applied and the resulting IL cannot be verified i.e. it may do unexpected (possibly illeagal operations) things. If the code attempts to do things the .Net application doesn't have permission to do then there is nothing to stop it executing.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Oh. Thanx for more explication and details on what I though it were working. :D

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...