Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Tuesday, April 3, 2012

Simple Compiler in C# [source code]


This is a simple compiler programmed in C# that accept arithmetic operations with integers, "/", "^" and parenthesis symbols.

The project passes through three phases:
  1. Scanning phase: this stage check the code from syntax errors and unacceptable symbols
  2. Parsing phase: this stage do the semantic rules over the code and detect logical errors, rules are steted in parsing table.
  3. Evaluating phase: after two previous phases are checked and completed successfully the evaluating process complete its work and return the result.

Sample snapshots



Download the source code

Monday, April 2, 2012

How To Retrieve an image SQL Server Data type into Picture Box Using C#

Note: Before reading this blog,  you need to know (How To Store an Image to image SQL Server Data type Using C#)

Images are stored in SQL Server database as series of bytes; to retrieve an image into Picture Box follow these steps

1- Crete a stored procedure that do select command on an image
2- In C# code get the array byte retrieved from the database and convert it to Image 
        
        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }


3- Set the converted image to the picture box 


For more details watch this video







and download the source code for experiment purposes

Saturday, March 31, 2012

How To Store an Image to image SQL Server Data type Using C#


Note: It is not recommended to use this method if you want to store a large amount of images (ex. gallery). Instead, try storing images in an external file and use image path as an [nvarchar] data type.

Image in real is a set of color points arranged a certain way to form a picture, in computer language color point called Pixel, each pixel is a combination of different values of Red, Green & Blue (RGB), computer dealing with image as a series of bytes, each byte represent an image pixel, image data type in SQL Server can store up to  (2,147,483,647) bytes.

In this example i used a Picture Box as an image input way, then converted the input image to array byte

       
private static byte[] imagetoByte(Image img)
        {
            MemoryStream ms = new MemoryStream();
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            return ms.ToArray();
        }

       Byte[] img = imagetoByte(PictureBox1.Image);

For more details watch this video


and download the source code for experiment purposes