Search This Blog

Tuesday, December 10, 2013

C# Create new bitmap example

C# > Drawing > Bitmap

Bitmap contains  pixel data for a graphics image. You can save bitmap to GDI+ file formats: BMP, GIF, EXIF, JPG, PNG and TIFF.

Example
Create new bitmap in runtime


Bitmap bmp = new System.Drawing.Bitmap(200, 200);
for (int x = 0; x < bmp.Height; ++x)
   for (int y = 0; y < bmp.Width; ++y)
     bmp.SetPixel(x, y, Color.Coral );
for (int x = 0; x < bmp.Height / 2; ++x)
   for (int y = 0; y < bmp.Width / 2; ++y)
     bmp.SetPixel(x, y, Color.Blue );
pictureBox1.Image = bmp;






C# Drawing Font

C# > Drawing > Font

With Font you can format text and set properties like face, size, style.

FontStyle Enumeration




C# Drawing

C# > Drawing

Provides methods for drawing to the display device using GDI+ basic graphics functionality.
Examples




Friday, December 6, 2013

Abs C# example

C#  > System > Math class > Abs

Abs returns the absolute value of a number.

Example:

int i = -32;
int j = Math.Abs(i); // 32




Math class C#

C#  > System > Math class

Math is a static class which contains constants and methods mathematical functions.




System namespace in C#

C# > System Namespace

System namespace in C# contains fundamental classes and base classes.





Guid, NewGuid C# example

C#  > System > Guid

Guid is globally unique identifier and stored on 128 bit integer.
The probability to be duplicated over networks and computers is very low.

Example
1. Use NewGuid method to get a new guid.
  Guid g = Guid.NewGuid();