public void CanFill_to_Bigger() { var maxSize = new Dimention(width: 1500, height: 1500); var resizeSettings = new ResizeOption(ResizeOperationType.Fill, ImageType.Preview_M, maxSize); var result = Resize(sourceFileName: "Lama.jpg", targetDimention: resizeSettings, dstFileName: "Lama fill Big.jpg"); Assert.True(result.Success); }
void ctlPOD_MouseMove(object sender, MouseEventArgs e) { try { double x = e.GetPosition(this).X; x = Math.Round(x); double y = e.GetPosition(this).Y; y = Math.Round(y); if ((int.Parse(x.ToString()) == int.Parse((this.Width).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 1).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.RightEdge; } else if ((int.Parse(x.ToString()) == 0 || int.Parse(x.ToString()) == 1 || int.Parse(x.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.LeftEdge; } else if ((int.Parse(y.ToString()) == int.Parse((this.Height).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 1).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.DownEdge; } else if ((int.Parse(y.ToString()) == 0 || int.Parse(y.ToString()) == 1 || int.Parse(y.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.UpEdge; } else if (e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.Arrow; //this.current = ResizeOption.None; } forward :; } catch (Exception exp) { exp.Data.Add("My Key", "ctlPOD_MouseMove()--:--ctlPOD.xaml.cs--:--" + exp.Message + " :--:--"); //ClsException.LogError(ex); //ClsException.WriteToErrorLogFile(ex); System.Text.StringBuilder sb = new StringBuilder(); sb.AppendLine(exp.Message); sb.AppendLine(); sb.AppendLine("StackTrace : " + exp.StackTrace); sb.AppendLine(); sb.AppendLine("Location : " + exp.Data["My Key"].ToString()); sb.AppendLine(); sb1 = CreateTressInfo(); sb.Append(sb1.ToString()); VMuktiAPI.ClsLogging.WriteToTresslog(sb); } }
private void CreateImageOnServer(FileResponse res, ResizeOption opt, string resizedPath) { var image = new Bitmap(AppDir + res.Model.Path); var newSize = new Size(opt.Width, opt.Height); var resized = new Bitmap(image, newSize); resized.Save(resizedPath, ImageFormat.Jpeg); image.Dispose(); resized.Dispose(); }
void ctlPOD_MouseLeave(object sender, MouseEventArgs e) { try { current = ResizeOption.None; } catch (Exception exp) { VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "ctlPOD_MouseLeave()", "ctlPOD.xaml.cs"); } }
void DrawResizeHandle(ResizeOption targetOption) { GUILayout.Box(EUIResourceManager.Instance.GetTexture("Blockout_Icon_Spacer"), EUIResourceManager.Instance.Skin.GetStyle("Texture"), GUILayout.MaxHeight(25), GUILayout.Width(10)); EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.ResizeHorizontal); if (Event.current.type == EventType.MouseDown && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) { resize = true; resizeOption = targetOption; previousMosePos = Event.current.mousePosition; } }
//public void SetImage(Bitmap image, ResizeOption resizeOption) //{ // Image = image; // if (resizeOption == ResizeOption.FitToFrame) Zoom = CalculateZoomFit(); // else if (resizeOption == ResizeOption.Maximize) Zoom = 1.0f; //} public void StartDraw(double imageWidth, double imageHeight, ResizeOption resizeOption) { imageWidth_ = imageWidth; imageHeight_ = imageHeight; if (resizeOption == ResizeOption.FitToFrame) { Zoom = CalculateZoomFit(); } else if (resizeOption == ResizeOption.Maximize) { Zoom = 1.0f; } }
private string CreateFileName(FileDataViewModelWithMeta fileData, ResizeOption opt) { var commpressedPath = Path.GetDirectoryName(AppDir + fileData.Path) + "\\" + fileData.Name + $"-min-{opt.Width}X{opt.Height}"; var tempPath = commpressedPath; var counter = 0; while (File.Exists(tempPath + ".jpeg")) { tempPath = commpressedPath + $"({counter})"; counter++; } return(tempPath + ".jpeg"); }
void ctlPOD_MouseMove(object sender, MouseEventArgs e) { try { double x = e.GetPosition(this).X; x = Math.Round(x); double y = e.GetPosition(this).Y; y = Math.Round(y); if ((int.Parse(x.ToString()) == int.Parse((this.Width).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 1).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.RightEdge; } else if ((int.Parse(x.ToString()) == 0 || int.Parse(x.ToString()) == 1 || int.Parse(x.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.LeftEdge; } else if ((int.Parse(y.ToString()) == int.Parse((this.Height).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 1).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.DownEdge; } else if ((int.Parse(y.ToString()) == 0 || int.Parse(y.ToString()) == 1 || int.Parse(y.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.UpEdge; } else if (e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.Arrow; //this.current = ResizeOption.None; } forward :; } catch (Exception exp) { VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "ctlPOD_MouseMove()", "ctlPOD.xaml.cs"); } }
/// <summary> /// Resizes the given image to 'newSize' with the given resize option (interpolation method). /// </summary> /// <param name="image"></param> /// <param name="origSize"></param> /// <param name="newSize"></param> /// <param name="option"></param> /// <returns></returns> public static byte[] Resize(byte[] image, Size origSize, Size newSize, ResizeOption option) { byte[] resizeImage = new byte[newSize.Width * newSize.Height]; float percentW = (float)newSize.Width / origSize.Width; float percentH = (float)newSize.Height / origSize.Height; //if (percent >= 1) // throw new ArgumentException("Enlarging operation not supported yet"); float invPercentW = 1 / percentW; float invPercentH = 1 / percentH; switch (option) { case ResizeOption.NearestNeighbor: int ri = 0, rj = 0; for (int i = 0; i < newSize.Height; i++) { for (int j = 0; j < newSize.Width; j++) { ri = (int)(i * invPercentH); rj = (int)(j * invPercentW); if (ri >= origSize.Height) { ri = origSize.Height - 1; } if (rj >= origSize.Width) { rj = origSize.Width - 1; } resizeImage[i * newSize.Width + j] = image[ri * origSize.Width + rj]; } } break; case ResizeOption.Linear: case ResizeOption.Bicubic: throw new ArgumentException("Linear and Bicubic options not supported yet"); break; } return(resizeImage); }
void ctlPOD_MouseMove(object sender, MouseEventArgs e) { double x = e.GetPosition(this).X; x = Math.Round(x); double y = e.GetPosition(this).Y; y = Math.Round(y); if ((int.Parse(x.ToString()) == int.Parse((this.Width).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 1).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.RightEdge; } else if ((int.Parse(x.ToString()) == 0 || int.Parse(x.ToString()) == 1 || int.Parse(x.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.LeftEdge; } else if ((int.Parse(y.ToString()) == int.Parse((this.Height).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 1).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.DownEdge; } else if ((int.Parse(y.ToString()) == 0 || int.Parse(y.ToString()) == 1 || int.Parse(y.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.UpEdge; } else if (e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.Arrow; //this.current = ResizeOption.None; } // forward: ; }
private Result <SizedImageData> Resize(string sourceFileName, ResizeOption targetDimention, string dstFileName) { var lamaPath = Path.Combine(Environment.CurrentDirectory, "Files", "Pics", sourceFileName); var lamaBytes = File.ReadAllBytes(lamaPath); var converter = new ImagesConversionUtil(); var scaledBytes = converter.GetScaledJpegBytes(lamaBytes, targetDimention); if (!scaledBytes.Success) { Assert.False(true); } var tmpPath = $@"C:\Users\Andrey\Desktop\{dstFileName}"; using (var imageReadStream = new MemoryStream(scaledBytes.Value.Bytes)) using (var img = Image.FromStream(imageReadStream)) { img.Save(tmpPath); } return(scaledBytes); }
void ctlPOD_MouseLeave(object sender, MouseEventArgs e) { try { current = ResizeOption.None; } catch (Exception exp) { exp.Data.Add("My Key", "ctlPOD_MouseLeave()--:--ctlPOD.xaml.cs--:--" + exp.Message + " :--:--"); //ClsException.LogError(ex); //ClsException.WriteToErrorLogFile(ex); System.Text.StringBuilder sb = new StringBuilder(); sb.AppendLine(exp.Message); sb.AppendLine(); sb.AppendLine("StackTrace : " + exp.StackTrace); sb.AppendLine(); sb.AppendLine("Location : " + exp.Data["My Key"].ToString()); sb.AppendLine(); sb1 = CreateTressInfo(); sb.Append(sb1.ToString()); VMuktiAPI.ClsLogging.WriteToTresslog(sb); } }
void ctlPOD_MouseMove(object sender, MouseEventArgs e) { try { double x = e.GetPosition(this).X; x = Math.Round(x); double y = e.GetPosition(this).Y; y = Math.Round(y); if ((int.Parse(x.ToString()) == int.Parse((this.Width).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 1).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.RightEdge; } else if ((int.Parse(x.ToString()) == 0 || int.Parse(x.ToString()) == 1 || int.Parse(x.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.LeftEdge; } else if ((int.Parse(y.ToString()) == int.Parse((this.Height).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 1).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.DownEdge; } else if ((int.Parse(y.ToString()) == 0 || int.Parse(y.ToString()) == 1 || int.Parse(y.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.UpEdge; } else if (e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.Arrow; //this.current = ResizeOption.None; } forward: ; } catch (Exception exp) { VMuktiAPI.VMuktiHelper.ExceptionHandler(exp, "ctlPOD_MouseMove()", "ctlPOD.xaml.cs"); } }
void ctlPOD_MouseMove(object sender, MouseEventArgs e) { try { double x = e.GetPosition(this).X; x = Math.Round(x); double y = e.GetPosition(this).Y; y = Math.Round(y); if ((int.Parse(x.ToString()) == int.Parse((this.Width).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 1).ToString()) || int.Parse(x.ToString()) == int.Parse((this.Width - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.RightEdge; } else if ((int.Parse(x.ToString()) == 0 || int.Parse(x.ToString()) == 1 || int.Parse(x.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeWE; current = ResizeOption.LeftEdge; } else if ((int.Parse(y.ToString()) == int.Parse((this.Height).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 1).ToString()) || int.Parse(y.ToString()) == int.Parse((this.Height - 2).ToString())) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.DownEdge; } else if ((int.Parse(y.ToString()) == 0 || int.Parse(y.ToString()) == 1 || int.Parse(y.ToString()) == 2) && e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.SizeNS; current = ResizeOption.UpEdge; } else if (e.LeftButton == MouseButtonState.Released) { this.Cursor = Cursors.Arrow; //this.current = ResizeOption.None; } forward: ; } catch (Exception exp) { exp.Data.Add("My Key", "ctlPOD_MouseMove()--:--ctlPOD.xaml.cs--:--" + exp.Message + " :--:--"); //ClsException.LogError(ex); //ClsException.WriteToErrorLogFile(ex); System.Text.StringBuilder sb = new StringBuilder(); sb.AppendLine(exp.Message); sb.AppendLine(); sb.AppendLine("StackTrace : " + exp.StackTrace); sb.AppendLine(); sb.AppendLine("Location : " + exp.Data["My Key"].ToString()); sb.AppendLine(); sb1 = CreateTressInfo(); sb.Append(sb1.ToString()); VMuktiAPI.ClsLogging.WriteToTresslog(sb); } }
public Result <SizedImageData> GetScaledJpegBytes(byte[] data, ResizeOption resizeOption) { if (resizeOption.ImgType == ImageType.Unknown) { return(Result <SizedImageData> .NewFailure($"{nameof(resizeOption.ImgType)} {resizeOption.ImgType} is not supported.")); } if (resizeOption.OperationType == ResizeOperationType.Unknown) { return(Result <SizedImageData> .NewFailure($"{nameof(resizeOption.OperationType)} {resizeOption.OperationType} is not supported.")); } byte[] resizedBytes; Dimention newSize; try { using (var imageReadStream = new MemoryStream(data)) using (var sourceImg = Image.FromStream(imageReadStream)) { var sourceSize = new Dimention(height: sourceImg.Height, width: sourceImg.Width); switch (resizeOption.OperationType) { case ResizeOperationType.Raw: return(Result <SizedImageData> .NewSuccess(new SizedImageData(resizeOption.ImgType, sourceSize, data))); case ResizeOperationType.Fit: newSize = sourceSize.GetSizeToFitInto(resizeOption.Size); // Resize using (var outputMs = new MemoryStream()) { using (var canvas = new Bitmap(width: newSize.Width, height: newSize.Height)) using (var graphics = Graphics.FromImage(canvas)) { graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; graphics.CompositingMode = CompositingMode.SourceCopy; graphics.DrawImage(sourceImg, 0, 0, width: newSize.Width, height: newSize.Height); canvas.Save(outputMs, ImageFormat.Jpeg); } resizedBytes = outputMs.ToArray(); } break; case ResizeOperationType.Fill: newSize = resizeOption.Size; var rectDst = new Rectangle(0, 0, width: resizeOption.Size.Width, height: resizeOption.Size.Height); var souceSize = new Dimention(width: sourceImg.Width, height: sourceImg.Height); var rectSrc = sourceSize.GetCenterRectangleToFill(resizeOption.Size); // Resize using (var outputMs = new MemoryStream()) { using (var canvas = new Bitmap(width: resizeOption.Size.Width, height: resizeOption.Size.Height)) using (var graphics = Graphics.FromImage(canvas)) { graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; graphics.CompositingMode = CompositingMode.SourceCopy; graphics.DrawImage(image: sourceImg, destRect: rectDst, srcRect: rectSrc, srcUnit: GraphicsUnit.Pixel); canvas.Save(outputMs, ImageFormat.Jpeg); } resizedBytes = outputMs.ToArray(); } break; default: return(Result <SizedImageData> .NewFailure($"{nameof(resizeOption.OperationType)}: '{resizeOption.OperationType}' is not supported.")); } } var result = new SizedImageData(imgType: resizeOption.ImgType, size: newSize, bytes: resizedBytes); return(Result <SizedImageData> .NewSuccess(result)); } catch (Exception ex) { return(Result <SizedImageData> .NewFailure(ex.ToString())); } }
void ctlPOD_MouseLeave(object sender, MouseEventArgs e) { current = ResizeOption.None; }
protected void HandleResize() { ResizeOption pref = ResizingPreference; if (FullScreen) { pref = ResizingFullScreenPreference; } if (AllowScaling && pref != ResizeOption.StretchToFit) { int height_multiple = ClientRectangle.Height / SnapHeight; int width_multiple = ClientRectangle.Width / SnapWidth; int multiple = Math.Min(height_multiple, width_multiple); if (multiple < 1) { multiple = 1; } current_scale = multiple; } float previous_mult_h = screen_multiplier_h; float previous_mult_w = screen_multiplier_w; switch (pref) { case ResizeOption.StretchToFit: screen_multiplier_h = 1.0f; screen_multiplier_w = 1.0f; break; case ResizeOption.AddBorder: screen_multiplier_h = (float)(SnapHeight * current_scale) / (float)ClientRectangle.Height; screen_multiplier_w = (float)(SnapWidth * current_scale) / (float)ClientRectangle.Width; break; case ResizeOption.ExactFitOnly: //you probably don't want to use exact fit for fullscreen. screen_multiplier_h = 1.0f; screen_multiplier_w = 1.0f; Height = SnapHeight * current_scale; Width = SnapWidth * current_scale; break; } float ratio_h = screen_multiplier_h / previous_mult_h; float ratio_w = screen_multiplier_w / previous_mult_w; foreach (SpriteSurface s in SpriteSurfaces) { if (s.NumElements > 0) { GL.BindBuffer(BufferTarget.ArrayBuffer, s.ArrayBufferID); IntPtr vbo = GL.MapBuffer(BufferTarget.ArrayBuffer, BufferAccess.ReadWrite); int max = s.Rows * s.Cols * 4 * s.TotalVertexAttribSize; for (int i = 0; i < max; i += s.TotalVertexAttribSize) { int offset = i * 4; //4 bytes per float byte[] bytes = BitConverter.GetBytes(ratio_w * BitConverter.ToSingle(new byte[] { Marshal.ReadByte(vbo, offset), Marshal.ReadByte(vbo, offset + 1), Marshal.ReadByte(vbo, offset + 2), Marshal.ReadByte(vbo, offset + 3) }, 0)); for (int j = 0; j < 4; ++j) { Marshal.WriteByte(vbo, offset + j, bytes[j]); } offset += 4; //move to the next float bytes = BitConverter.GetBytes(ratio_h * BitConverter.ToSingle(new byte[] { Marshal.ReadByte(vbo, offset), Marshal.ReadByte(vbo, offset + 1), Marshal.ReadByte(vbo, offset + 2), Marshal.ReadByte(vbo, offset + 3) }, 0)); for (int j = 0; j < 4; ++j) { Marshal.WriteByte(vbo, offset + j, bytes[j]); } } GL.UnmapBuffer(BufferTarget.ArrayBuffer); } } GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height); Resizing = false; }
/// <summary> /// Resizes the given image to 'newSize' with the given resize option (interpolation method). /// </summary> /// <param name="image"></param> /// <param name="origSize"></param> /// <param name="newSize"></param> /// <param name="option"></param> /// <returns></returns> public static byte[] Resize(byte[] image, Size origSize, Size newSize, ResizeOption option) { byte[] resizeImage = new byte[newSize.Width * newSize.Height]; float percentW = (float)newSize.Width / origSize.Width; float percentH = (float)newSize.Height / origSize.Height; //if (percent >= 1) // throw new ArgumentException("Enlarging operation not supported yet"); float invPercentW = 1 / percentW; float invPercentH = 1 / percentH; switch (option) { case ResizeOption.NearestNeighbor: int ri = 0, rj = 0; for (int i = 0; i < newSize.Height; i++) { for (int j = 0; j < newSize.Width; j++) { ri = (int)(i * invPercentH); rj = (int)(j * invPercentW); if (ri >= origSize.Height) ri = origSize.Height - 1; if (rj >= origSize.Width) rj = origSize.Width - 1; resizeImage[i * newSize.Width + j] = image[ri * origSize.Width + rj]; } } break; case ResizeOption.Linear: case ResizeOption.Bicubic: throw new ArgumentException("Linear and Bicubic options not supported yet"); break; } return resizeImage; }
public void StartDraw(double imageWidth, double imageHeight, ResizeOption resizeOption) { WF_ImagePanel.StartDraw(imageWidth, imageHeight, resizeOption); }