Thursday, 13 August 2015

Difference between bitmap and vector images?

Bitmap (or raster) images are stored as a series of tiny dots called pixels. Each pixel is actually a very small square that is assigned a color, and then arranged in a pattern to form the image. When you zoom in on a bitmap image you can see the individual pixels that make up that image. Bitmap graphics can be edited by erasing or changing the color of individual pixels using a program such as Adobe Photoshop or Fireworks, You can easily increase the size of image in any of these image editing tool and check pixel level.
Unlike bitmaps, vector images are not based on pixel patterns, but instead use mathematical formulas to draw lines and curves that can be combined to create an image from geometric objects such as circles and polygons. Vector images are edited by manipulating the lines and curves that make up the image using a program such as Adobe Illustrator.
Vector images have some important advantages over bitmap images. Vector images tend to be smaller than bitmap images. That’s because a bitmap image has to store color information for each individual pixel that forms the image. A vector image just has to store the mathematical formulas that make up the image, which take up less space.
Vector images are also more scalable than bitmap images. When a bitmap image is scaled up you begin to see the individual pixels that make up the image. This is most noticeable in the edges of the image. There are ways of making these jagged edges less noticeable but this often results in making the image blurry as well. When a vector image is scaled up, the image is redrawn using the mathematical formula. The resulting image is just as smooth as the original.
Unfortunately, vector formats are not well supported on the web. The two most popular image formats used on the Web, GIF and JPEG are bitmap formats. Most vector images must first be converted into bitmaps images (or rasterized) before they can be used on the Web. An exception is the SWF format used to create animations using Macromedia’s Flash animation software.
Bitmap formats are best for images that need to have a wide range of color gradations, such as most photographs. Vector formats, on the other hand, are better for images that consist of a few areas of solid color. Examples of images that are well suited for the vector format include logos and type.


Bitmap graphics
Vector graphics
What are they made up of?
Pixels of different colours
Objects
What can be edited?
Individual pixels
Individual objects
What is the file size?
Large, as the computer stores details of every pixel
Small, as the computer stores details of objects, which do not require much memory
What happens when they are resized?
They lose quality
They do not lose quality
How real do they look?
Real
Not real (many of them look like cartoon images)
Native formats that the software can read
.bmp
.svg
Common file formats
.bmp, .dib, jpeg, gif, tiff, .png
.cgm, .svg, .odg, .eps, .xml













Saturday, 9 May 2015

Threading in C Sharp

What is Threading ?
Threading means parallel code execution. 
There are two types of thread.
1) Foreground thread 2) Background thread

Lets see a simple example without any threading.
class Program
    {
        static void Main(string[] args)
        {
            Function1();
            Function2();
            Console.ReadLine();
        }

        static void Function1()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Runing from Func 1: {0}", i);
            }
        }

        static void Function2()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Runing from Func 2: {0}", i);
            }
        }
    }

Output:



We can see, Its executing Function 1 first and then Function 2. Its a synchronous process. One by one functions are running.

Now Lets see with Threading.
First import System.Threading namespace
Using System.Threading ;
class Program
    {
        static void Main(string[] args)
        {
            //Created two threads
            Thread obj1 = new Thread(Function1);
            Thread obj2 = new Thread(Function2);

            //Invoke these threads
            obj1.Start();
            obj2.Start();

            Console.ReadLine();
        }

        static void Function1()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Runing from Func 1: {0}", i);
                Thread.Sleep(500);
            }
        }

        static void Function2()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Runing from Func 2: {0}", i);
                Thread.Sleep(500);
            }
        }
    }




As we can clearly see, both the threads running simultaneously.
Note* In reality Processor execute one thread for some time, and then execute another thread for some time, It happens so quickly that it appears that execution is happening simultaneously.

Two Kinds of Thread
1) Foreground Thread: Its a thread which keeps running till its execution is completed, Although main thread execution finished.
2) Background Thread: Its a thread which stops executing whenever main thread stops.