0

i want to create SQL CLR integrated function from Visual C#, now my requirement is user will pass a folder path as a paramter, and the function should get all the image file from the the folder, and get its basic property like FileSize, dimension etc.. but it seems SQL project does not supports System.Drawing Namespace... as i created the same function in normal project it worked fine, as i was able to use System.Drawing Namespace, but here i cannot use, System.Drawing Namespace.. so is there any other way to get the image dimension...

below is the code i have used in my normal project.

public DataTable InsertFile(string FolderPath)  
{   
    DataTable dt = new DataTable();  
    DataColumn[] col = new DataColumn[] { new DataColumn("FileName",   typeof(System.String)), new DataColumn("FileSize", typeof(System.Int32)), new   DataColumn("FilePath", typeof(System.String)), new DataColumn("Width",   typeof(System.Int32)), new DataColumn("Height", typeof(System.Int32)) };  
    dt.Columns.AddRange(col);  
    FileInfo info= null;  
    Bitmap bmp = null;  
    foreach (String s in Directory.GetFiles(FolderPath, "*.jpg"))  
    {  
        info = new FileInfo(s);  
        bmp = new Bitmap(s);  
        DataRow dr = dt.NewRow();  
        dr["FileName"] = Path.GetFileName(s); 
        dr["FileSize"] = info.Length / 1024;    
        dr["FilePath"] = s;  
        dr["Width"] = bmp.Width;  
        dr["Height"] = bmp.Height;  
        dt.Rows.Add(dr);  
    }  
    return dt;  
}  

does anyone have any idea how to get image dimension without using System.Drawing Namespace.

2
  • Whats the error/exception you are getting inside the SQL project? Commented Jun 17, 2011 at 16:41
  • Actually in Sql Project, there is no way to import(using System.Drawing) Namespace.. neither it allows to add reference for System.Drawing Commented Jun 17, 2011 at 16:48

2 Answers 2

1

wow never seen anyone try this before, but if using Drawing in a SQL project isn't allowed try reading the header info like this http://www.codeproject.com/KB/cs/ReadingImageHeaders.aspx

Edit included the code, with the change to remove the dependency on Size.

while (binaryReader.ReadByte() == 0xff)
        {
            byte marker = binaryReader.ReadByte();
            ushort chunkLength = binaryReader.ReadLittleEndianInt16();

            if (marker == 0xc0)
            {
                binaryReader.ReadByte();

                int height = binaryReader.ReadLittleEndianInt16();
                int width = binaryReader.ReadLittleEndianInt16();
                return new int[] { width, height };
            }

            binaryReader.ReadBytes(chunkLength - 2);
        }
Sign up to request clarification or add additional context in comments.

2 Comments

thats great article, but the end, its also using bitmap object.. as i said above, SQL Project does not support using System.Drawing Namespace, anything else i can do..
@Abbas: Only as a fallback - if you check the DecodeJfif-method you see the manual attempt.
0

Is the Image object any better for you?

System.Drawing.Image forSize = System.Drawing.Image.FromFile(s);
dr["Width"] = forSize.Width;

and so forth.

That any better or same problem?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.