/// <summary> /// Resize & Save Bitmap /// </summary> /// <param name="bmp">Bitmap</param> /// <param name="newSize">New size</param> /// <param name="destinationFile">Absolute path of the file to save</param> /// <returns>Bitmap resized operation result</returns> private bool ResizeImage(ref Bitmap bmp, AndroidSize newSize, string destinationFile) { try { using (var tmp = new Bitmap(newSize.Width, newSize.Height)) { using (var g = Graphics.FromImage(tmp)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(bmp, 0, 0, newSize.Width, newSize.Height); } tmp.Save(destinationFile); } return(true); } catch (Exception e) { return(false); } }
/// <summary> /// Load sizes from INI file /// </summary> private void LoadSizes() { //display lstFiles.Items.Clear(); //Load INI file var ini = IniFile.LoadFromFile(Utils.FILE_SIZES); //get all fields foreach (var field in ini.Fields) { //cast field value to size var size = Size.Empty; try { var split = field.Value.ToLower().Trim().Split('x'); int w = Convert.ToInt32(split[0]); int h = Convert.ToInt32(split[1]); size = new Size(w, h); } catch { } //check if (!size.IsEmpty) { //create AndroidSize class var andrSize = new AndroidSize(field.Header, size.Width, size.Height); //add to check-list lstSizes.Items.Add(andrSize); lstSizes.SetItemChecked(lstSizes.Items.Count - 1, true); } } }