private void SetImage(Crownwood.Magic.Controls.TabPage tabPage, Image image) { if (tabPage == null) { return; } try { ImageList lst = tabPage.ImageList; if (lst != null) { tabPage.ImageIndex = -1; tabPage.ImageList = null; lst.Dispose(); } if (image != null) { lst = new ImageList(); lst.ColorDepth = ColorDepth.Depth32Bit; lst.ImageSize = new Size(16, 16); Image copie = CUtilImage.CreateImageImageResizeAvecRatio( image, lst.ImageSize, Color.FromArgb(0, 0, 0, 0)); lst.Images.Add(copie); tabPage.ImageList = lst; tabPage.ImageIndex = 0; } } catch { } }
public byte[] GetImageBytesResized(int nMaxWidth, int nMaxHeight) { byte[] btResult = null; Image img = null; try { img = ImageCarte; if (img != null) { if (nMaxWidth > 0 && nMaxHeight > 0 && (img.Width > nMaxWidth || img.Height > nMaxHeight)) { Size sz = CUtilImage.GetSizeAvecRatio(img, new Size(nMaxWidth, nMaxHeight)); Image img2 = CUtilImage.CreateImageImageResizeAvecRatio(img, sz, Color.White); img.Dispose(); img = img2; } MemoryStream stream = new MemoryStream(); img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); btResult = stream.GetBuffer(); stream.Close(); stream.Dispose(); img.Dispose(); } } catch { } finally { if (img != null) { img.Dispose(); } } return(btResult); }