Obtención de la distancia entre dos coordenadas geográficas en C#

/// <summary>
        /// Obtiene la distancia entre dos coordenadas geográficas
        /// </summary>
        /// <param name="long1InDegrees">Longitud del punto 1 en grados</param>
        /// <param name="lat1InDegrees">Latitud del punto 1 en grados</param>
        /// <param name="long2InDegrees">Longitud del punto 2 en grados</param>
        /// <param name="lat2InDegrees">Latitud del punto 2 en grados</param>
        /// <returns>Distancia entre los dos puntos en metros</returns>
        private static double GetDistance(decimal long1InDegrees, decimal lat1InDegrees, decimal long2InDegrees, decimal lat2InDegrees)
        {
            double lats = (double)(lat1InDegrees - lat2InDegrees);
            double lngs = (double)(long1InDegrees - long2InDegrees);

            //Paso a metros
            double latm = lats * 60 * 1852;
            double lngm = (lngs * Math.Cos((double)lat1InDegrees * Math.PI / 180)) * 60 * 1852;
            double distInMeters = Math.Sqrt(Math.Pow(latm, 2) + Math.Pow(lngm, 2));
            return distInMeters;
        }

Cambiar proporción de una imágen en C#

public static string ChangeImageProportion(string strImgPath, string strImgOutputPath, int iWidth, int iHeight)
{
    try
    {
        //Comprueba la extensión
        //if (Path.GetExtension(strImgPath).ToLower() != ".jpg")
        //{
        //    throw new Exception("El fichero debe estar en formato JPG. (" + strImgPath + ")");
        //}

        //Lee el fichero en un stream
        Stream mystream = null;

        if (strImgPath.StartsWith("http"))
        {
            HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(strImgPath);
            HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
            mystream = wresp.GetResponseStream();
        }
        else
            mystream = File.OpenRead(strImgPath);

        // Cargo la imágen
        Bitmap source = new Bitmap(mystream);

        int _targetWidth = source.Width;
        int _targetHeight = source.Height;

        /*** Calculo de las proporciones finales ***/
        double _relation = ((double)source.Width) / ((double)source.Height);
        double _canvasRelation = ((double)iWidth) / ((double)iHeight);

        if (_relation > _canvasRelation)
        {
            // El ancho es el lado grande, hay que aumentar el alto
            _targetHeight = iHeight * source.Width / iWidth;
        }
        else if (_relation < _canvasRelation)
        {
            // El alto es el lado grande, hay que aumentar el ancho
            _targetWidth = iWidth * source.Height / iHeight;
        }

        // Ahora miro el desfase
        int iTop = (_targetHeight - source.Height) / 2;
        int iLeft = (_targetWidth - source.Width) / 2;

        // La nueva
        Bitmap target = new Bitmap(_targetWidth, _targetHeight);
        Graphics g = Graphics.FromImage(target);
        g.CompositingQuality = CompositingQuality.HighQuality;

        Color cW = Color.White;
        Brush brush = new SolidBrush(cW);
        g.FillRectangle(brush, 0, 0, _targetWidth, _targetHeight);
        g.DrawImage(source,
                    new Rectangle(iLeft, iTop, source.Width, source.Height),
                    0,
                    0,
                    source.Width,
                    source.Height,
                    GraphicsUnit.Pixel);

        // We will store the correct image codec in this object
        ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); ;
        // This will specify the image quality to the encoder
        EncoderParameter epQuality = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 99L);
        // Store the quality parameter in the list of encoder parameters
        EncoderParameters eps = new EncoderParameters(1);
        eps.Param[0] = epQuality;

        // Genero un nuevo nombre de fichero
        //strImgPath = Path.Combine(Path.GetDirectoryName(strImgPath),Guid.NewGuid().ToString() + ".jpg");

        target.Save(strImgOutputPath, ici, eps);

        source.Dispose();
        target.Dispose();
        g.Dispose();

        return strImgPath;
    }
    catch
    {
        throw;
    }
}

Redimensionar una imágen en C#

Método mediante el cual se puede redimensionar una imágen (.jpg, .png, .gif o .bmp) al tamaño dado, respetando las proporciones dadas.

public static string ResizeImage(string strImgPath, string strImgOutputPath, int iWidth, int iHeight)
{
    try
    {
        bool mismaImagen = strImgPath.Equals(strImgOutputPath);
        if (mismaImagen)
        {
            strImgOutputPath = strImgPath + "___.jpg";
        }

        string[] extensiones = {
                                   ".jpg",
                                   ".png",
                                   ".bmp",
                                   ".gif"
                               };

        if (!extensiones.Contains(Path.GetExtension(strImgPath)))
            throw new Exception("Extensión no soportada");

        //Lee el fichero en un stream
        Stream mystream = null;

        if (strImgPath.StartsWith("http"))
        {
            HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(strImgPath);
            HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
            mystream = wresp.GetResponseStream();
        }
        else
            mystream = File.OpenRead(strImgPath);

        // Cargo la imágen
        Bitmap imgToResize = new Bitmap(mystream);

        Size size = new Size(iWidth, iHeight);

        int sourceWidth = imgToResize.Width;
        int sourceHeight = imgToResize.Height;

        float nPercent = 0;
        float nPercentW = 0;
        float nPercentH = 0;

        nPercentW = ((float)size.Width / (float)sourceWidth);
        nPercentH = ((float)size.Height / (float)sourceHeight);

        if (nPercentH < nPercentW)
            nPercent = nPercentH;
        else
            nPercent = nPercentW;

        int destWidth = (int)(sourceWidth * nPercent);
        int destHeight = (int)(sourceHeight * nPercent);

        Bitmap b = new Bitmap(destWidth, destHeight);
        Graphics g = Graphics.FromImage((Image)b);
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;

        g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
        g.Dispose();

        // We will store the correct image codec in this object
        ImageCodecInfo ici = GetEncoderInfo("image/jpeg"); ;
        // This will specify the image quality to the encoder
        EncoderParameter epQuality = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 99L);
        // Store the quality parameter in the list of encoder parameters
        EncoderParameters eps = new EncoderParameters(1);
        eps.Param[0] = epQuality;
        b.Save(strImgOutputPath, ici, eps);

        imgToResize.Dispose();
        mystream.Close();
        mystream.Dispose();
        b.Dispose();
        g.Dispose();

        if (mismaImagen)
        {
            File.Delete(strImgPath);
            File.Move(strImgOutputPath, strImgPath);
        }

        return strImgPath;
    }
    catch
    {
        throw;
    }
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
    int j;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for (j = 0; j < encoders.Length; ++j)
    {
        if (encoders[j].MimeType == mimeType)
            return encoders[j];
    }
    return null;
}