public static Image ResizeImage(Image img, ImageScaleType scaleType) { float width = 0, height = 0; switch (scaleType) { case ImageScaleType.Percentage: width = img.Width * (Program.Settings.ImageScalePercentageWidth / 100f); height = img.Height * (Program.Settings.ImageScalePercentageHeight / 100f); break; case ImageScaleType.Width: width = Program.Settings.ImageScaleToWidth; height = Program.Settings.ImageKeepAspectRatio ? img.Height * (width / img.Width) : img.Height; break; case ImageScaleType.Height: height = Program.Settings.ImageScaleToHeight; width = Program.Settings.ImageKeepAspectRatio ? img.Width * (height / img.Height) : img.Width; break; case ImageScaleType.Specific: width = Program.Settings.ImageScaleSpecificWidth; height = Program.Settings.ImageScaleSpecificHeight; break; } if (width > 0 && height > 0) { return CaptureHelpers.ResizeImage(img, (int)width, (int)height, Program.Settings.ImageUseSmoothScaling); } return img; }
public static Image ResizeImage(Image img, ImageScaleType scaleType) { float width = 0, height = 0; switch (scaleType) { case ImageScaleType.Percentage: width = img.Width * (Program.Settings.ImageScalePercentageWidth / 100f); height = img.Height * (Program.Settings.ImageScalePercentageHeight / 100f); break; case ImageScaleType.Width: width = Program.Settings.ImageScaleToWidth; height = Program.Settings.ImageKeepAspectRatio ? img.Height * (width / img.Width) : img.Height; break; case ImageScaleType.Height: height = Program.Settings.ImageScaleToHeight; width = Program.Settings.ImageKeepAspectRatio ? img.Width * (height / img.Height) : img.Width; break; case ImageScaleType.Specific: width = Program.Settings.ImageScaleSpecificWidth; height = Program.Settings.ImageScaleSpecificHeight; break; } if (width > 0 && height > 0) { return(CaptureHelpers.ResizeImage(img, (int)width, (int)height, Program.Settings.ImageUseSmoothScaling)); } return(img); }
public ImageBox() { this.sprt = new UISprite(1); base.RootUIElement.AddChildLast(this.sprt); this.sprt.ShaderType = ShaderType.Texture; this.ninePatchPrim = new UIPrimitive((DrawMode)4, 16, 28); base.RootUIElement.AddChildLast(this.ninePatchPrim); this.ninePatchPrim.ShaderType = ShaderType.Texture; this.ninePatchPrim.Visible = false; this.ninePatchMargin = NinePatchMargin.Zero; this.scale = ImageScaleType.Stretch; this.cropArea = new ImageRect(0, 0, 0, 0); this.clipImageX = 0f; this.clipImageY = 0f; this.clipImageWidth = 0f; this.clipImageHeight = 0f; Dictionary <ImageScaleType, ImageBox.SetupUISpriteImageScale> dictionary = new Dictionary <ImageScaleType, ImageBox.SetupUISpriteImageScale>(); dictionary.Add(ImageScaleType.Stretch, new ImageBox.SetupUISpriteImageScale(this.SetupUISpriteNormal)); dictionary.Add(ImageScaleType.AspectInside, new ImageBox.SetupUISpriteImageScale(this.SetupUISpriteAspectInside)); dictionary.Add(ImageScaleType.AspectOutside, new ImageBox.SetupUISpriteImageScale(this.SetupUISpriteAspectOutside)); dictionary.Add(ImageScaleType.NinePatch, new ImageBox.SetupUISpriteImageScale(this.SetupUIPrimitiveNinePatch)); dictionary.Add(ImageScaleType.Center, new ImageBox.SetupUISpriteImageScale(this.SetupUISpriteNone)); this.setupSpriteImageScale = dictionary; }
/// <summary> /// Constructor of ImageProcessBase. /// New thread will be created when construction. /// </summary> /// <param name="IsAddImageProcessList">The object will be added to a list that stores all objects whose class is devided from ImageProcessBase. Only when this is true, the object will continuously receive new frame.</param> /// <param name="IsCreateNewThread">A new thread will be created for computing. If it is false, then it is necessary to call ImageHandler.</param> public ImageProcessBase(ImageScaleType ImageScale, bool IsAddImageProcessList = true, bool IsCreateNewThread = true) { if (IsAddImageProcessList) { imageProcesses.Add(this); IsImageScaleUsed[(int)ImageScale] = true; } if (IsCreateNewThread) { ThreadPool.QueueUserWorkItem(new WaitCallback(ImageHandler)); } }
public static ImgTex CreateLScapeTexture(byte[] rawData, uint i_width, uint i_height) { var texture = new ImgTex(); // 0x88 / 136 CurrentTextureScale = ImageScaleType.Full; if (!texture.LoadCSI(rawData, i_width, i_height)) { return(null); } CustomTextureTable.Add(texture); return(texture); }
/// <summary> /// Create a Image Processor to receive the frame from CaptureCard/Texture2D. /// </summary> /// <param name="Fraction_Left">The left border to clip incoming image.</param> /// <param name="Fraction_Right">The right border to clip incoming image.</param> /// <param name="Fraction_Top">The top border to clip incoming image.</param> /// <param name="Fraction_Bottom">The bottom border to clip incoming image.</param> /// <param name="ImageScale">The scale of incoming image.</param> /// <param name="FrameRate">The frame rate that application requires. Use negative number to represent infinity.</param> public ImageProcess(double Fraction_Left = 0, double Fraction_Right = 1, double Fraction_Top = 0, double Fraction_Bottom = 1, ImageScaleType ImageScale = ImageScaleType.OriginalSize, int FrameRate = 1) : base(ImageScale) { /*Assertion*/ Trace.Assert(Fraction_Left >= 0 && Fraction_Left <= 1, "Border Fraction should belongs to [0, 1]."); Trace.Assert(Fraction_Right >= 0 && Fraction_Right <= 1, "Border Fraction should belongs to [0, 1]."); Trace.Assert(Fraction_Top >= 0 && Fraction_Top <= 1, "Border Fraction should belongs to [0, 1]."); Trace.Assert(Fraction_Bottom >= 0 && Fraction_Bottom <= 1, "Border Fraction should belongs to [0, 1]."); /*Assertion*/ this.Fraction_Left = Fraction_Left; this.Fraction_Right = Fraction_Right; this.Fraction_Top = Fraction_Top; this.Fraction_Bottom = Fraction_Bottom; IncomingImageScale = ImageScale; PreferFrameRate = FrameRate; // Frame Rate Setup if (FrameRate > 0) { stopwatch = new Stopwatch(); } stopwatch?.Start(); }
/// <summary> /// Create a Image Processor to receive the frame from CaptureCard/Texture2D. /// </summary> /// <param name="Fraction_Left">The left border to clip incoming image.</param> /// <param name="Fraction_Right">The right border to clip incoming image.</param> /// <param name="Fraction_Top">The top border to clip incoming image.</param> /// <param name="Fraction_Bottom">The bottom border to clip incoming image.</param> /// <param name="ImageScale">The scale of incoming image.</param> public ImageProcess(double Fraction_Left, double Fraction_Right, double Fraction_Top, double Fraction_Bottom, ImageScaleType ImageScale) : this(Fraction_Left, Fraction_Right, Fraction_Top, Fraction_Bottom, ImageScale, -1) { }