//ContextMenuExportBitmap private void SaveBitmapAs(ImageFormat i_imgFormat) { string fileName = @"image_export."; int zoomFactor = Convert.ToByte(numericUpDownZoomFactor.Value); int bitmapWidth = this.bitmapGridSpriteView.getGridWidth() * zoomFactor; int bitmapHeight = this.bitmapGridSpriteView.getGridHeight() * zoomFactor; if (i_imgFormat == null) { byte[] arrSprite = GraphicsTools.GetBytesFromBitmap(this.bitmapGridSpriteView); SaveScreenBytes(arrSprite, this.bitmapGridSpriteView.getGridWidth() / 8, this.bitmapGridSpriteView.getGridHeight()); return; } else { if (i_imgFormat == ImageFormat.Png) { fileName += "png"; } else if (i_imgFormat == ImageFormat.Jpeg) { fileName += "jpg"; } else if (i_imgFormat == ImageFormat.Bmp) { fileName += "bmp"; } else { Locator.Resolve <IUserMessage>().Error("Invalid format to save!"); return; } } string filePath = Path.Combine(Utils.GetAppFolder(), fileName); if (File.Exists(filePath)) { File.Delete(filePath); } //save cropped bitmap Bitmap bmp = pictureZXDisplay.Image as Bitmap; Bitmap cloneBitmap = bmp.Clone(new Rectangle(0, 0, bitmapWidth, bitmapHeight), bmp.PixelFormat); cloneBitmap.Save(filePath, i_imgFormat); Locator.Resolve <IUserMessage>().Info(String.Format("File '{0}' saved to root app directory!", fileName)); }
private void buttonExportSelectionArea_Click(object sender, EventArgs e) { //export selection area to picture or bytes if (_mouseSelectionArea == null || _mouseSelectionArea.isSelected() == false) { return; } int width = _mouseSelectionArea.getCroppedArea().Width / 2; int height = _mouseSelectionArea.getCroppedArea().Height / 2; Bitmap croppedArea = GraphicsTools.GetBitmapCroppedArea(bmpZXMonochromatic, new Point(_mouseSelectionArea.getCroppedArea().X / 2, _mouseSelectionArea.getCroppedArea().Y / 2), new Size(width, height)); if (croppedArea == null) { Locator.Resolve <IUserMessage>().Warning("Could not get cropped area...nothing done!"); return; } byte[] arrScreenBytes = GraphicsTools.GetBytesFromBitmap(croppedArea); SaveScreenBytes(arrScreenBytes, width, height); //croppedArea.Save(@"image_export_cropped.bmp"); }