public ImageSettings(int width, int height, ImageMode mode, string background) { this.Width = width; this.Height = height; this.Mode = mode; this.Background = background; }
public void grayScaleMode(GrayScaleMode scaleMode) { modifiedImage = ImageProcessing.grayScale(image, scaleMode); imageMode = ImageMode.Grayscale; this.scaleMode = scaleMode; changeBitmap(getCurrentImage()); }
private void radioButtonSequential_CheckedChanged(object sender, EventArgs e) { if (radioButtonSequential.Checked) { imageMode = ImageMode.Sequential; } }
private BitmapImage GetImage(ImageMode mode) { BitmapImage tmp = null; if (ImageMode.Image == mode) { tmp = Interlocked.Exchange(ref _ThumbnailImage, null); } else { tmp = Interlocked.Exchange(ref _LargeImage, null); } if (tmp != null) { return(tmp); } if (CacheFile == null) { var task = FetchThumbnailAsync().ConfigureAwait(false); } else { var task = LoadCachedThumbnailImageAsync(mode).ConfigureAwait(false); } return(null); }
private void radioButtonPipeline_CheckedChanged(object sender, EventArgs e) { if (radioButtonPipeline.Checked) { imageMode = ImageMode.Pipelined; } }
private void radioButtonLoadBalanced_CheckedChanged(object sender, EventArgs e) { if (radioButtonLoadBalanced.Checked) { imageMode = ImageMode.LoadBalanced; } }
public ImageForm(string imagePath, Main owner) { InitializeComponent(); this.owner = owner; Owner = owner; imageMode = ImageMode.Default; scaleMode = GrayScaleMode.Null; filter = new ColorFilter(); this.imagePath = imagePath; using (var bmpTemp = new Bitmap(imagePath)) { image = new Bitmap(bmpTemp); originalImage = new Bitmap(bmpTemp); } Text = imagePath; pictureBox.Image = image; MaximumSize = new Size(owner.Width - 100, owner.Height - 150); setSizeAuto(); }
public override void Decode(string tg, CfgData data) { switch (tg) { case "expVis": data.Decode(out _nodeEnteredVisuals); break; case "subVis": data.Decode(out _nodeActiveDefaultVisuals); break; case "disVis": data.Decode(out _nodeInactiveVisuals); break; case "bg_cfg": source.visualStyleConfigs[BoxButtons.classTag] = data; break; case "bg_cfgs": data.Decode_Dictionary(out source.visualStyleConfigs); break; case "URL": imageUrl = data.ToString(); break; case "imgScl": _imageScaling = data.ToFloat(); break; case "imgMd": _mode = (ImageMode)data.ToInt(); break; case "hidTxt": _hideLabel = data.ToBool(); break; case "m": MeshObjectGetOrCreate().DecodeFull(data); break; } }
public void SetImageMode(ImageMode mode) { var imageMode = ""; switch (mode) { case ImageMode.Center: imageMode = "center"; break; case ImageMode.Corner: imageMode = "corner"; break; case ImageMode.Corners: imageMode = "corners"; break; default: throw new Exception("Invalid ImageMode"); } _jsRuntime.InvokeVoid( _p5InvokeFunction, "imageMode", imageMode ); }
public NodeIcon(string key, Bitmap image) { this._normalImage = image; this._normalKey = key; this._imageMode = ImageMode.Normal; this._grayscaledImage = image.GrayScale(); this._grayscaledKey = string.Format("{0}-grayscaled", key); }
public Image(ImageMode mode, ImageSize size, ImageColor color) { int errorCode = Image.NewFromModeSizeColor(mode, ref size, ref color, out this.handle); if (errorCode < 0) { Error.ThrowNativeException(errorCode); } }
public Image(ImageMode mode, ImageSize size, byte[] buffer) { int errorCode = Image.NewFromModeSizeBuffer(mode, ref size, buffer, out this.handle); if (errorCode < 0) { Error.ThrowNativeException(errorCode); } }
/// <summary> /// Initialize image task type, image color filter (as image view mode), image set and /// other variables with defaults /// </summary> /// <param name="mod">One of provided image modifications</param> /// <param name="imageSet">Pointer to image set from engine</param> public ImageTask(ImageModification mod, ImageSet imageSet) { taskType = mod; ongoing = false; previous = null; next = null; iSet = imageSet; iMode = iSet.imageMode; }
private void OnColorModeChanged(ImageMode imageMode) { Astra.ImageMode[] modes = AstraManager.Instance.AvailableColorModes; foreach (var mode in modes) { if (mode.Width == imageMode.width && mode.Height == imageMode.height) { AstraManager.Instance.ColorMode = mode; break; } } }
private async Task LoadCachedThumbnailImageAsync(ImageMode mode) { var file = CacheFile; if (file == null) { DebugUtil.Log("CacheFile is null"); return; } try { using (var stream = await file.GetThumbnailAsync(ThumbnailMode.ListView, 90)) // 90 pix seems to be the best balance between speed and quality { var bmp = new BitmapImage(); bmp.CreateOptions = BitmapCreateOptions.None; await bmp.SetSourceAsync(stream); if (ImageMode.Image == mode) { ThumbnailImage = bmp; } else { LargeImage = bmp; } IsBroken = false; NotifyChanged(nameof(ThumbnailExists)); NotifyChanged(nameof(IsBroken)); } return; } catch { } if (0 < RemainingRetryCount) { var delay = 1000 * (3 - RemainingRetryCount--); DebugUtil.Log(() => "Failed to load thumbnail from file. Retry " + delay + " msec later."); await Task.Delay(delay); NotifyChanged(nameof(ThumbnailImage)); NotifyChanged(nameof(LargeImage)); } else { DebugUtil.Log("Failed to load thumbnail from file. Retry count exhausted."); IsBroken = true; NotifyChanged(nameof(ThumbnailExists)); NotifyChanged(nameof(IsBroken)); } }
public Image(ImageMode mode, ImageSize size, ImageColor color) { //Debug.Assert(mode == ImageMode.Rgba); //FIXME:??? //PixelFormat. __img = new System.Drawing.Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); System.Drawing.Color _backColor = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B); using (System.Drawing.Graphics drawing = System.Drawing.Graphics.FromImage(__img)) { drawing.Clear(_backColor); drawing.Save(); } }
/// <summary> /// http://forums.asp.net/t/2007059.aspx?multiple+users+access+dynamic+generated+image+in+mvc+action /// </summary> /// <param name="guid"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="imageMode"></param> /// <returns></returns> public ActionResult GetImage( /*deserves view model*/ Guid? guid, uint width = 100, uint height = 200, ImageMode imageMode = ImageMode.Fill) { if(guid == null) { guid = Guid.NewGuid(); } var fileUrl = ImageRepository.GetFilePath(new ImageDescriptor(guid.Value)); return new FilePathResult(fileUrl, "html/text");//change mime type to image }
private async Task LoadCachedThumbnailImageAsync(ImageMode mode) { var file = CacheFile; if (file == null) { DebugUtil.Log("CacheFile is null"); return; } try { using (var stream = await file.GetThumbnailAsync(ThumbnailMode.ListView)) { var bmp = new BitmapImage(); bmp.CreateOptions = BitmapCreateOptions.None; await bmp.SetSourceAsync(stream); if (ImageMode.Image == mode) { ThumbnailImage = bmp; } else { LargeImage = bmp; } } return; } catch { } if (0 < RemainingRetryCount) { var delay = 1000 * (3 - RemainingRetryCount--); DebugUtil.Log("Failed to load thumbnail from file. Retry " + delay + " msec later."); await Task.Delay(delay); NotifyChanged("ThumbnailImage"); NotifyChanged("LargeImage"); } else { DebugUtil.Log("Failed to load thumbnail from file. Retry count exhausted."); } }
/// <summary> /// Create restore point and initialize values from current image set /// </summary> /// <param name="mode">Image view mode</param> /// <param name="taskType">Task type</param> /// <param name="image">Main image</param> /// <param name="thumb">Thumbnail image</param> /// <param name="saturation">Saturation level</param> /// <param name="brightness">Brightness level</param> /// <param name="clarity">Clarity level</param> public RestorePoint( ImageMode mode, ImageModification taskType, Bitmap image, Bitmap thumb, int saturation, int brightness, int clarity ) { this.mode = mode; this.taskType = taskType; this.image = image; this.thumb = thumb; this.saturation = saturation; this.brightness = brightness; this.clarity = clarity; }
internal Style(Font font, Pen pen, SolidBrush brush, SolidBrush textBrush, StringFormat format, RectangleMode rectMode, ImageMode imageMode, LineCap strokeMode, DBColorMode colorMode, bool fill) { Font = new Font(font.FontFamily, font.Size); Pen = new Pen(pen.Color, pen.Width); Brush = new SolidBrush(brush.Color); TextBrush = new SolidBrush(textBrush.Color); Format = new StringFormat(); Format.LineAlignment = format.LineAlignment; Format.Alignment = format.Alignment; RectMode = rectMode; ImageMode = imageMode; StrokeMode = strokeMode; ColorMode = colorMode; Fill = fill; }
/// <summary> /// Initialize image set variables to its defaults /// </summary> public ImageSet() { filename = null; origin = null; image = null; imageMode = ImageMode.Full; rectangle = new Rectangle(0, 0, 0, 0); thumb = null; thumbRed = null; thumbGreen = null; thumbBlue = null; thumbRectangle = new Rectangle(0, 0, 0, 0); saturation = 0; brightness = 0; clarity = 0; }
private static extern int NewFromModeSizeColor(ImageMode mode, ref ImageSize size, ref ImageColor color, out int handle);
private void radioButtonSequential_CheckedChanged(object sender, EventArgs e) { if (radioButtonSequential.Checked) imageMode = ImageMode.Sequential; }
private void radioButtonPipeline_CheckedChanged(object sender, EventArgs e) { if (radioButtonPipeline.Checked) imageMode = ImageMode.Pipelined; }
public static void MakeThumbnailImage(string originalImagePath, string thumbnailPath, int width, int height, ImageMode mode) { Image image = Image.FromFile(originalImagePath); int num = width; int num2 = height; int x = 0; int y = 0; int num5 = image.Width; int num6 = image.Height; switch (mode) { case ImageMode.W: num2 = (image.Height * width) / image.Width; break; case ImageMode.H: num = (image.Width * height) / image.Height; break; case ImageMode.Cut: if ((((double)image.Width) / ((double)image.Height)) > (((double)num) / ((double)num2))) { num6 = image.Height; num5 = (image.Height * num) / num2; y = 0; x = (image.Width - num5) / 2; } else { num5 = image.Width; num6 = (image.Width * height) / num; x = 0; y = (image.Height - num6) / 2; } break; } Image image2 = new Bitmap(num, num2); Graphics graphics = Graphics.FromImage(image2); graphics.InterpolationMode = InterpolationMode.High; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.Clear(Color.Transparent); graphics.DrawImage(image, new Rectangle(0, 0, num, num2), new Rectangle(x, y, num5, num6), GraphicsUnit.Pixel); try { try { CreateFolder(GetRemoveFile(thumbnailPath)); image2.Save(thumbnailPath, ImageFormat.Jpeg); } catch (Exception exception) { throw exception; } } finally { image.Dispose(); image2.Dispose(); graphics.Dispose(); } }
private void InitializeStreams() { try { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); _streamSet = Astra.StreamSet.Open(); _readerDepth = _streamSet.CreateReader(); _readerColor = _streamSet.CreateReader(); _readerBody = _streamSet.CreateReader(); _readerMaskedColor = _streamSet.CreateReader(); _readerColorizedBody = _streamSet.CreateReader(); _readerPoint = _streamSet.CreateReader(); _depthStream = _readerDepth.GetStream <DepthStream>(); var depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = depthModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetDepthWidth = 160; int targetDepthHeight = 120; int targetDepthFps = 30; #else int targetDepthWidth = 320; int targetDepthHeight = 240; int targetDepthFps = 30; #endif foreach (var m in depthModes) { if (m.Width == targetDepthWidth && m.Height == targetDepthHeight && m.FramesPerSecond == targetDepthFps) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _readerColor.GetStream <ColorStream>(); var colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = colorModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth = 320; int targetColorHeight = 240; int targetColorFps = 30; #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 30; #endif foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); _bodyStream = _readerBody.GetStream <BodyStream>(); _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>(); _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>(); _pointStream = _readerPoint.GetStream <PointStream>(); _areStreamsInitialized = true; } catch (AstraException e) { Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); } }
private void radioButtonLoadBalanced_CheckedChanged(object sender, EventArgs e) { if (radioButtonLoadBalanced.Checked) imageMode = ImageMode.LoadBalanced; }
public enum ImageMode { Undefined = 0, Plain = 1, Grayscale, ColorMap, Histogram } // careful! this has to match some code in Trainer.cpp. and sync with db: ImageModes table public System.Drawing.Image GetImage(String path, int rows, int cols, ImageMode mode) { if (!File.Exists(path)) return new System.Drawing.Bitmap(100, 100); if (mode == ImageMode.Plain) return Image.FromFile(path); else return GrayscaleImage(path, rows, cols, mode); }
public static String GrayscaleImagePath(String path, int rows, int cols, ImageMode mode) { String grayscaleImagePath = GetTempImagePath(); CAPI.DumpGrayscalePicture(path, grayscaleImagePath, rows, cols, (int)mode); return grayscaleImagePath; }
public void InitializeStreams() { try { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); _streamSet = Astra.StreamSet.Open(); _readerDepth = _streamSet.CreateReader(); _readerColor = _streamSet.CreateReader(); _readerNV21Color = _streamSet.CreateReader(); _readerBody = _streamSet.CreateReader(); _readerMaskedColor = _streamSet.CreateReader(); _readerColorizedBody = _streamSet.CreateReader(); _depthStream = _readerDepth.GetStream <DepthStream>(); var depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = depthModes[0]; int targetDepthWidth, targetDepthHeight, targetDepthFps; #if ASTRA_UNITY_ANDROID_NATIVE //Deeyea and Dabai doesn't support qqvga and qvga resolution. //use 640*400. if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x60e || _depthStream.usbInfo.Pid == 0x608 || _depthStream.usbInfo.Pid == 0x617) { targetDepthWidth = 640; targetDepthHeight = 400; targetDepthFps = 30; } else { targetDepthWidth = 160; targetDepthHeight = 120; targetDepthFps = 30; } #else if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x60e || _depthStream.usbInfo.Pid == 0x608 || _depthStream.usbInfo.Pid == 0x617) { targetDepthWidth = 640; targetDepthHeight = 400; targetDepthFps = 30; } else { targetDepthWidth = 320; targetDepthHeight = 240; targetDepthFps = 30; } #endif foreach (var m in depthModes) { if (m.Width == targetDepthWidth && m.Height == targetDepthHeight && m.FramesPerSecond == targetDepthFps) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _readerColor.GetStream <ColorStream>(); var colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = colorModes[0]; if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x617) { //for deeyea, set mirror to false to match depth. _colorStream.IsMirroring = false; } #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth, targetColorHeight, targetColorFps; if (_depthStream.usbInfo.Pid == 0x608 || _depthStream.usbInfo.Pid == 0x60f || _depthStream.usbInfo.Pid == 0x617) { targetColorWidth = 640; targetColorHeight = 480; targetColorFps = 30; } else { targetColorWidth = 320; targetColorHeight = 240; targetColorFps = 30; } #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 30; #endif foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); #if ASTRA_UNITY_ANDROID_NATIVE _nv21ColorStream = _readerNV21Color.GetStream <ColorStream>(Astra.Core.StreamSubType.COLOR_NV21_SUBTYPE); if (_nv21ColorStream.IsAvailable) { //COLOR_NV21_SUBTYPE is only available when using astra pro and astra pro plus. colorModes = _nv21ColorStream.AvailableModes; selectedColorMode = colorModes[0]; foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _nv21ColorStream.SetMode(selectedColorMode); if (_depthStream.usbInfo.Pid == 0x60b || _depthStream.usbInfo.Pid == 0x617) { //for deeyea, set mirror to false to match depth. _nv21ColorStream.IsMirroring = false; } } else { _readerNV21Color.Dispose(); _readerNV21Color = null; _nv21ColorStream = null; } #endif _bodyStream = _readerBody.GetStream <BodyStream>(); _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>(); _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>(); _areStreamsInitialized = true; } catch (AstraException e) { Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); } }
public void SetImageMode(ImageMode mode) => _jsRuntime.InvokeVoid( _p5InvokeFunction, "imageMode", ImageModeToString(mode) );
public static string ImageModeToString(ImageMode mode) => mode switch {
public db.TrainingRunInfo CreateTrainingRun (String name, int numDimensions, double threshold, String trainingSet, String detectionSetting, int rows, int cols, ImageMode mode, Model model) { _dimensions = numDimensions; int numFaces = _dbm.CreateTrainingRun (name, _trainingDropZone, numDimensions, threshold, trainingSet, detectionSetting, rows, cols, mode, model); return LoadTrainingRun(name); }
private static extern int NewFromModeSizeBuffer(ImageMode mode, ref ImageSize size, byte[] buffer, out int handle);
public System.Drawing.Image GrayscaleImage(String path, int rows, int cols, ImageMode mode) { return Image.FromFile(GrayscaleImagePath(path,rows,cols,mode)); }
public void SetImageMode(ImageMode mode) { ((IStyle)Style).SetImageMode(mode); }
private void InitializeStreams() { try { AstraUnityContext.Instance.WaitForUpdate(AstraBackgroundUpdater.WaitIndefinitely); _streamSet = Astra.StreamSet.Open(); _readerDepth = _streamSet.CreateReader(); _readerColor = _streamSet.CreateReader(); _readerBody = _streamSet.CreateReader(); _readerMaskedColor = _streamSet.CreateReader(); _readerColorizedBody = _streamSet.CreateReader(); _depthStream = _readerDepth.GetStream <DepthStream>(); _depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = _depthModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetDepthWidth = 160; int targetDepthHeight = 120; int targetDepthFps = 30; #else int targetDepthWidth = 320; int targetDepthHeight = 240; int targetDepthFps = 30; #endif foreach (var m in _depthModes) { Debug.Log("Depth mode: " + m.Width + "x" + m.Height + "@" + m.FramesPerSecond); if (m.Width == targetDepthWidth && m.Height == targetDepthHeight) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _readerColor.GetStream <ColorStream>(); try { _colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = _colorModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth = 320; int targetColorHeight = 240; int targetColorFps = 30; #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 30; #endif foreach (var m in _colorModes) { Debug.Log("Color mode: " + m.Width + "x" + m.Height + "@" + m.FramesPerSecond); if (m.Width == targetColorWidth && m.Height == targetColorHeight) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); } catch (System.Exception e) { Debug.Log("Couldn't initialize color stream: " + e.ToString()); } _bodyStream = _readerBody.GetStream <BodyStream>(); _maskedColorStream = _readerMaskedColor.GetStream <MaskedColorStream>(); _colorizedBodyStream = _readerColorizedBody.GetStream <ColorizedBodyStream>(); _areStreamsInitialized = true; Debug.Log("Stream initialize success"); OnInitializeSuccess.Invoke(); } catch (System.Exception e) { Debug.Log("Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); if (_initializeCount > 0) { _initializeCount--; } else { Debug.Log("Initialize failed"); OnInitializeFailed.Invoke(); } } }
public void SetImageMode(ImageMode mode) { ImageMode = mode; }
private void InitializeStreams() { try { _streamSet = Astra.StreamSet.Open(); _reader1 = _streamSet.CreateReader(); _reader1.FrameReady += FrameReady; _reader2 = _streamSet.CreateReader(); _reader2.FrameReady += FrameReady; _reader3 = _streamSet.CreateReader(); _reader3.FrameReady += FrameReady; _reader4 = _streamSet.CreateReader(); _reader4.FrameReady += FrameReady; _reader5 = _streamSet.CreateReader(); _reader5.FrameReady += FrameReady; _depthStream = _reader1.GetStream <DepthStream>(); var depthModes = _depthStream.AvailableModes; ImageMode selectedDepthMode = depthModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetDepthWidth = 160; int targetDepthHeight = 120; int targetDepthFps = 30; #else int targetDepthWidth = 320; int targetDepthHeight = 240; int targetDepthFps = 60; #endif foreach (var m in depthModes) { if (m.Width == targetDepthWidth && m.Height == targetDepthHeight && m.FramesPerSecond == targetDepthFps) { selectedDepthMode = m; break; } } _depthStream.SetMode(selectedDepthMode); _colorStream = _reader2.GetStream <ColorStream>(); var colorModes = _colorStream.AvailableModes; ImageMode selectedColorMode = colorModes[0]; #if ASTRA_UNITY_ANDROID_NATIVE int targetColorWidth = 320; int targetColorHeight = 240; int targetColorFps = 30; #else int targetColorWidth = 640; int targetColorHeight = 480; int targetColorFps = 60; #endif foreach (var m in colorModes) { if (m.Width == targetColorWidth && m.Height == targetColorHeight && m.FramesPerSecond == targetColorFps) { selectedColorMode = m; break; } } _colorStream.SetMode(selectedColorMode); _bodyStream = _reader3.GetStream <BodyStream>(); _maskedColorStream = _reader4.GetStream <MaskedColorStream>(); _colorizedBodyStream = _reader5.GetStream <ColorizedBodyStream>(); _areStreamsInitialized = true; } catch (AstraException e) { Debug.Log("AstraController: Couldn't initialize streams: " + e.ToString()); UninitializeStreams(); } }
private Task <Stream> ProcessImageAsync(Stream source, int width, int height, int quality, ImageMode mode, ImageFormat?format) { // this represents the EXIF orientation var bitmap = LoadBitmap(source, out var encodedOrigin, out var encodedFormat); // always load as 32bit (to overcome issues with indexed color) // if either w or h is 0, set it based on ratio of original image if (height == 0) { height = (int)Math.Round(bitmap.Height * (float)width / bitmap.Width); } else if (width == 0) { width = (int)Math.Round(bitmap.Width * (float)height / bitmap.Height); } // if we need to crop, crop the original before resizing if (mode == ImageMode.Crop) { bitmap = CropBitmap(bitmap, width, height); } if (mode == ImageMode.Scale) { bitmap = ScaleBitmap(bitmap, width); } if (mode == ImageMode.CropScale) { bitmap = CropScaleBitmap(bitmap, width, height); } // store padded height and width int paddedWidth = width; int paddedHeight = height; // if we need to pad, or max, set the height or width according to ratio if (mode == ImageMode.Pad || mode == ImageMode.Max) { float bitmapRatio = (float)bitmap.Width / bitmap.Height; float resizeRatio = (float)width / height; if (bitmapRatio > resizeRatio) // original is more "landscape" { height = (int)Math.Round(bitmap.Height * ((float)width / bitmap.Width)); } else { width = (int)Math.Round(bitmap.Width * ((float)height / bitmap.Height)); } } if (mode == ImageMode.Pad) { bitmap = ScaleBitmap(bitmap, width); bitmap = PadBitmap(bitmap, paddedWidth, paddedHeight, format != ImageFormat.Png); } var image = SKImage.FromBitmap(bitmap); switch (format) { case ImageFormat.Bmp: encodedFormat = SKEncodedImageFormat.Bmp; break; case ImageFormat.Gif: encodedFormat = SKEncodedImageFormat.Gif; break; case ImageFormat.Ico: encodedFormat = SKEncodedImageFormat.Ico; break; case ImageFormat.Jpg: encodedFormat = SKEncodedImageFormat.Jpeg; break; case ImageFormat.Png: encodedFormat = SKEncodedImageFormat.Png; break; case ImageFormat.Wbmp: encodedFormat = SKEncodedImageFormat.Wbmp; break; case ImageFormat.Webp: encodedFormat = SKEncodedImageFormat.Webp; break; case ImageFormat.Pkm: encodedFormat = SKEncodedImageFormat.Pkm; break; case ImageFormat.Ktx: encodedFormat = SKEncodedImageFormat.Ktx; break; case ImageFormat.Astc: encodedFormat = SKEncodedImageFormat.Astc; break; case ImageFormat.Dng: encodedFormat = SKEncodedImageFormat.Dng; break; case ImageFormat.Heif: encodedFormat = SKEncodedImageFormat.Heif; break; } var imageData = image.Encode(encodedFormat, quality); // cleanup image.Dispose(); bitmap.Dispose(); source.Dispose(); return(Task.FromResult(imageData.AsStream(true))); }