Use of the Global Namespace Aliases

Ankit tewari
Ankit t...
Member
112 Points
11 Posts

Hi,

  Here is code for cropping image using Js. I want to know that why we are using such type of name space 

using SD = System.Drawing;

SD is worked here like object but we can  access directly properties if we added namespace. But in this code I don't understand how SD worked. 

using (SD.Image OriginalImage = SD.Image.FromFile(Img))

Whole code is as following.... 

using System.IO;
using SD = System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

static byte[] Crop(string Img, int Width, int Height, int X, int Y)
{
  try
  {
    using (SD.Image OriginalImage = SD.Image.FromFile(Img))
    {
      using (SD.Bitmap bmp = new SD.Bitmap(Width, Height))
      {
        bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);

        using (SD.Graphics Graphic = SD.Graphics.FromImage(bmp))
        {
          Graphic.SmoothingMode = SmoothingMode.AntiAlias;
          Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
          Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
          Graphic.DrawImage(OriginalImage, new SD.Rectangle(0, 0, Width, Height), X, Y, Width, Height, SD.GraphicsUnit.Pixel);
          MemoryStream ms = new MemoryStream();
          bmp.Save(ms, OriginalImage.RawFormat);
          return ms.GetBuffer();
        }
      }
    }
  }
  catch (Exception Ex)
  {
    throw (Ex);
  }
}
Views: 9586
Total Answered: 3
Total Marked As Answer: 1
Posted On: 26-Oct-2017 21:35

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Teacher
4822 Points
23 Posts
         

It is Global Namespace Alias. The global namespace alias is useful when the member might be hidden by another entity of the same name. 

In your case, I think, you can remove it if there is no entity with same name in imported namespaces. For more see https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/namespaces/how-to-use-the-global-namespace-alias

Posted On: 26-Oct-2017 23:52
Nice...
 - hambi  13-Nov-2017 06:38
Smith
Smith
None
2568 Points
74 Posts
         

It is useful to disambiguate - for example:

using WinformTimer = System.Windows.Forms.Timer;
using ThreadingTimer = System.Threading.Timer;

Otherwise, if you use both System.Windows.Forms.Timer and System.Timers.Timer in the same file you'd have to keep giving the full names (since Timer could be confusing).

Posted On: 27-Oct-2017 00:09
Ankit tewari
Ankit t...
Member
112 Points
11 Posts
         

Thanks..

Posted On: 27-Oct-2017 03:47
 Log In to Chat