Moving Java Applications to .NET

Microsoft .NET is much more than XML Web services. At the heart of Microsoft .NET is the .NET Framework, consisting of the common language runtime and the class libraries. These two components provide the execution engine and programming APIs for building .NET applications. Applications compiled for the .NET Framework are not compiled directly to native code. Instead, they are compiled to an intermediate language called Microsoft Intermediate Language (MSIL). When an application is run for the first time, the common language runtime just-in-time compiler compiles the MSIL code into native code before it is executed. The common language runtime is more than a simple JIT compiler; it is also responsible for providing low-level execution services, such as garbage collection, exception handling, security services, and runtime type-safety checking. Because of the common language runtime's role in managing execution, programs that target the .NET Framework are sometimes called "managed" applications. The .NET Framework also includes a set of classes for building applications that run on the common language runtime. These class libraries provide rich support for a wide range of tasks, including data access, security, file IO, XML manipulation, messaging, class reflection, XML Web services, user-interface construction, text processing, ASP.NET, and Microsoft Windows services. Perhaps the most unique attribute of the .NET Framework is its support for multiple languages. Microsoft ships .NET compilers for four commercial languages: Visual C# .NET, Visual Basic .NET, the Managed Extensions for C++, and Visual J# .NET. Apart from these, support for over 20 programming languages including Perl, Python, and COBOL is available for use with the .NET Framework. Relying on the common language runtime, code compiled with these compilers can interoperate.

Wednesday, August 18, 2010

how to resize a image

private int resizeWidth;
    private int resizeHeight;

    public event ResizeInfoEventHandler resizeOK;

    public frmResizeInfo()
    {
      InitializeComponent();
    }

    private void butOK_Click(object sender, EventArgs e)
    {
      if (tbHeight.Text != "" && tbWidth.Text != "")
      {
        this.resizeHeight = Convert.ToInt32(tbHeight.Text);
        this.resizeWidth = Convert.ToInt32(tbWidth.Text);

        this.Hide();

        ResizeInfoEventArgs resizeEventArgs = new ResizeInfoEventArgs(this.resizeHeight, this.resizeWidth);
        this.ResizeInfoOK(resizeEventArgs);
      }
    }

    protected virtual void ResizeInfoOK(ResizeInfoEventArgs eventArgs)
    {
      if (this.resizeOK != null)
      {
        this.resizeOK(this, eventArgs);
      }
    }
  }

  public class ResizeInfoEventArgs : EventArgs
  {
    public int Height;
    public int Width;

    public ResizeInfoEventArgs(int height, int width)
    {
      this.Height = height;
      this.Width = width;
    }
  }

how to create water mark on image


 public string AddWatermark(string pPath, string pWatermark)
        {
            Image image = Image.FromFile(pPath);
            Bitmap bmp = new Bitmap(image);
            bmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            ImageCodecInfo iciJpegCodec = null;
            //find the correct Codec and specify its quality
            EncoderParameter epQuality = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80L);
            // Get all image codecs that are available
            ImageCodecInfo[] iciCodecs = ImageCodecInfo.GetImageEncoders();
            // Store the quality parameter in the list of encoder parameters
            EncoderParameters epParameters = new EncoderParameters(1);
            epParameters.Param[0] = epQuality;
            // Loop through all the image codecs
            for (int i = 0; i < iciCodecs.Length; i++)
            {
                // Until the one that we are interested in is found, which is image/jpeg
                if (iciCodecs[i].MimeType == "image/jpeg")
                {
                    iciJpegCodec = iciCodecs[i];
                    break;
                }
            }

            using (Graphics gr = Graphics.FromImage(bmp))
            {
                StringFormat strFormat = new StringFormat();
                strFormat.Alignment = StringAlignment.Center;
                
                gr.DrawImage(image, new Rectangle(0,0, bmp.Width, bmp.Height));
                //gr.DrawString(pWatermark, new Font("Arial", 40), Brushes.White, new PointF(5, bmp.Height - 20));
                gr.DrawString(pWatermark, new Font("Tahoma", 20), Brushes.White, new RectangleF(0, 0, 500, 500), strFormat);
            }

            bmp.Save(pPath + "test.jpg", iciJpegCodec, epParameters);
          
            bmp.Dispose();
            return "Water Mark done successfully";
        }      
       }