/// <summary> /// Resizes proportionally and crops an image to fill the desired Size /// </summary> /// <param name="imgPhoto"></param> /// <param name="outputSize"></param> /// <param name="alignment"></param> /// <param name="quality"></param> /// <param name="format"></param> /// <returns></returns> public static Image ScaleToFill(this Image imgPhoto, Size outputSize, ContentAlignment alignment = ContentAlignment.MiddleCenter, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { return(ScaleToFill(imgPhoto, outputSize.Width, outputSize.Height, alignment, quality, format)); }
private void Awake() { m_ligthIntensityDefault = RenderPipelineInfo.Type == RPType.Standard ? 1 : 2; m_shadowStrengthDefault = RenderPipelineInfo.Type == RPType.Standard ? 1 : 0.75f; //simplified user's hardware configuration evaluation if (SystemInfo.graphicsMemorySize > 4096) { m_graphicsQualityDefault = GraphicsQuality.High; } else if (SystemInfo.graphicsMemorySize > 2048) { m_graphicsQualityDefault = GraphicsQuality.Medium; } else { m_graphicsQualityDefault = GraphicsQuality.Low; } IOC.RegisterFallback <ISettingsComponent>(this); m_wm = IOC.Resolve <IWindowManager>(); m_wm.AfterLayout += OnAfterLayout; m_wm.WindowCreated += OnWindowCreated; m_wm.WindowDestroyed += OnWindowDestoryed; }
private void Awake() { s_instance = this; this.m_DisableLowQualityObjects = new List <GameObject>(); if (!Options.Get().HasOption(Option.GFX_QUALITY)) { string intelDeviceName = W8Touch.Get().GetIntelDeviceName(); object[] args = new object[] { intelDeviceName }; Log.Yim.Print("Intel Device Name = {0}", args); if (((intelDeviceName != null) && intelDeviceName.Contains("Haswell")) && intelDeviceName.Contains("U28W")) { if (Screen.currentResolution.height > 0x438) { Options.Get().SetInt(Option.GFX_QUALITY, 0); } } else if ((intelDeviceName != null) && intelDeviceName.Contains("Crystal-Well")) { Options.Get().SetInt(Option.GFX_QUALITY, 2); } else if ((intelDeviceName != null) && intelDeviceName.Contains("BayTrail")) { Options.Get().SetInt(Option.GFX_QUALITY, 0); } } this.m_GraphicsQuality = (GraphicsQuality)Options.Get().GetInt(Option.GFX_QUALITY); this.InitializeScreen(); this.UpdateQualitySettings(); this.m_lastWidth = Screen.width; this.m_lastHeight = Screen.height; }
/// <summary> /// Enlarge the image background using the specified color /// </summary> /// <param name="img"></param> /// <param name="size"></param> /// <param name="backColor"></param> /// <param name="imgAlignment"></param> /// <param name="quality"></param> /// <param name="format"></param> /// <returns></returns> public static Image EnlargeCanvas(this Image img, Size size, Color backColor, ContentAlignment imgAlignment = ContentAlignment.MiddleCenter, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { return(EnlargeCanvas(img, size.Width, size.Height, backColor, imgAlignment, quality, format)); }
///// <summary> ///// Converts an <see cref="Image" /> into <see cref="Bitmap" />. ///// If original image cannot be directy casted than it will be converted into a new format ///// </summary> ///// <param name="img"></param> ///// <param name="quality"></param> ///// <param name="format"></param> ///// <returns></returns> //public static Bitmap ToBitmap(this Image img, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) //{ // // If Can cast then cast // var bmp = img as Bitmap; // if (bmp != null) // { // return bmp; // } // // else create a new bitmap obhect // var result = new Bitmap(img.Width, img.Height, format); // result.SetResolution(img.HorizontalResolution, img.VerticalResolution); // using (var graphics = GetGraphics(result, quality)) // { // graphics.DrawImage(img, 0, 0, result.Width, result.Height); // } // return result; //} /// <summary> /// Creates a graphics object from image /// </summary> /// <param name="img"></param> /// <param name="quality"></param> /// <returns></returns> public static Graphics GetGraphics(this Image img, GraphicsQuality quality) { var g = Graphics.FromImage(img); switch (quality) { case GraphicsQuality.Highest: g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; break; case GraphicsQuality.Fastest: g.CompositingQuality = CompositingQuality.HighSpeed; g.InterpolationMode = InterpolationMode.Low; g.SmoothingMode = SmoothingMode.HighSpeed; break; default: g.CompositingQuality = CompositingQuality.Default; g.InterpolationMode = InterpolationMode.Default; g.SmoothingMode = SmoothingMode.Default; break; } return(g); }
/// <summary> /// Sets all properties of a <see cref="Graphics"/> object to the corresponding <paramref name="quality"/> parameter. /// </summary> /// <param name="graphics">The <see cref="Graphics"/> to be changed</param> /// <param name="quality">The <see cref="GraphicsQuality"/> that should it be set to</param> public static void SetQuality(this Graphics graphics, GraphicsQuality quality = GraphicsQuality.High) { switch (quality) { case GraphicsQuality.High: graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.TextRenderingHint = TextRenderingHint.AntiAlias; break; case GraphicsQuality.Normal: graphics.SmoothingMode = SmoothingMode.Default; graphics.CompositingQuality = CompositingQuality.Default; graphics.InterpolationMode = InterpolationMode.Default; graphics.PixelOffsetMode = PixelOffsetMode.Default; graphics.TextRenderingHint = TextRenderingHint.SystemDefault; break; case GraphicsQuality.Low: graphics.SmoothingMode = SmoothingMode.HighSpeed; graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.Low; graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed; graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel; break; } }
/// <summary> /// <para>Returns a resized Image.</para> /// </summary> /// <param name="image">The Image to resize.</param> /// <param name="maxWidth">The maximum width for the resulting Image. Set to 0 if there's no maximum width.</param> /// <param name="maxHeight">The maximum height for the resulting Image. Set to 0 if there's no maximum height.</param> /// <param name="graphicsQuality">The graphics quality for the resulting Image.</param> /// <param name="maintainPalette">If set to <c>true</c> the(if any) palette will be maintained. Transparency will be saved.</param> /// <returns>The resized Image</returns> /// <exception cref="System.ArgumentNullException">Thrown when the image parameter is null</exception> public static Image Resize(this Image image, int maxWidth, int maxHeight, GraphicsQuality graphicsQuality, bool maintainPalette) { if (image == null) { throw new ArgumentNullException("image"); } Image retVal = image; Size thumbnailSize = image.CalculateThumbSize(maxWidth, maxHeight); if (thumbnailSize.Width < image.Width || thumbnailSize.Height < image.Height || (image.HasIndexedPixelFormat() && !maintainPalette)) { Bitmap bitmap = new Bitmap(thumbnailSize.Width, thumbnailSize.Height); using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.ApplyGraphicsQualitySetting(graphicsQuality); graphics.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); graphics.Save(); } retVal = bitmap; if (maintainPalette && image.HasIndexedPixelFormat()) { retVal = bitmap.PaletteQuantize(image.Palette.Entries); bitmap.Dispose(); } } return(retVal); }
/// <summary> /// Adds a Border to the image /// </summary> /// <param name="img"></param> /// <param name="borderThickness">Width of the border (px)</param> /// <param name="borderColor">Color of the border</param> /// <param name="quality"></param> /// <param name="format"></param> /// <returns></returns> public static Image EnlargeCanvas(this Image img, int borderThickness, Color borderColor, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { var width = img.Width + 2 * borderThickness; var height = img.Height + 2 * borderThickness; return(img.EnlargeCanvas(width, height, borderColor, ContentAlignment.MiddleCenter, quality, format)); }
/// <summary> /// Resizes an image to fit into the desired Size without preserving aspect ratio /// </summary> /// <param name="image"></param> /// <param name="quality"></param> /// <param name="format"></param> /// <param name="outputSize"></param> public static Image Resize(this Image image, Size outputSize, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { var result = new Bitmap(outputSize.Width, outputSize.Height, format); //set the resolutions the same to avoid cropping due to resolution differences result.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (var graphics = GetGraphics(result, quality)) { graphics.DrawImage(image, 0, 0, result.Width, result.Height); } return(result); }
/// <summary> /// Resizes an image proportionally adding borders to fit into the desired Size /// </summary> /// <param name="img">Image to resize</param> /// <param name="width">Output width</param> /// <param name="height">Output height</param> /// <param name="backColor">Background color for the output image</param> /// <param name="quality"></param> /// <param name="format"></param> /// <returns></returns> public static Image ScaleToSize(this Image img, int width, int height, Color backColor, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { var sourceWidth = img.Width; var sourceHeight = img.Height; const int sourceX = 0; const int sourceY = 0; var destX = 0; var destY = 0; float nPercent; var nPercentW = (float)width / sourceWidth; var nPercentH = (float)height / sourceHeight; if (nPercentH < nPercentW) { nPercent = nPercentH; destX = Convert.ToInt16((width - sourceWidth * nPercent) / 2); } else { nPercent = nPercentW; destY = Convert.ToInt16((height - sourceHeight * nPercent) / 2); } var destWidth = (int)Math.Min(Math.Ceiling(sourceWidth * nPercent), width); var destHeight = (int)Math.Min(Math.Ceiling(sourceHeight * nPercent), height); var bmPhoto = new Bitmap(width, height, format); bmPhoto.SetResolution(img.HorizontalResolution, img.VerticalResolution); using (var grPhoto = GetGraphics(bmPhoto, quality)) { grPhoto.Clear(backColor); grPhoto.DrawImage(img, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); } return(bmPhoto); }
/// <summary> /// Resizes an image proportionally to fit into the desired Size /// </summary> /// <param name="img">Image to resize</param> /// <param name="maxWidth">Output maximum width</param> /// <param name="maxHeight">Output maximum height</param> /// <param name="format"></param> /// <param name="quality"></param> /// <returns></returns> public static Image ScaleToFit(this Image img, int maxWidth, int maxHeight, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { var ratioX = (double)maxWidth / img.Width; var ratioY = (double)maxHeight / img.Height; var ratio = Math.Min(ratioX, ratioY); var newWidth = (int)(img.Width * ratio); var newHeight = (int)(img.Height * ratio); var newImage = new Bitmap(newWidth, newHeight, format); using (var g = GetGraphics(newImage, quality)) { g.DrawImage(img, 0, 0, newWidth, newHeight); } return(newImage); }
private void EnableDashBoard() { //Debug.Log(CategoryTitle); dashboard.GetComponent <Image>().CrossFadeAlpha(1f, 0.3f, false); CategoryTitle.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Overview.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Inventory.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Config.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Save.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Load.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Exit.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); Language.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); GraphicsQuality.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); TextureQuality.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); FoV.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); QualityValue.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); GQ_LeftArrow.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); GQ_RightArrow.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); LDD_Label.GetComponent <Text>().CrossFadeAlpha(1f, 0.3f, false); DashboardStatus = true; }
public override void Init() { base.Init(); if (string.IsNullOrEmpty(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].GamingResolutionCOD) || string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].GamingResolutionCOD, "720", StringComparison.InvariantCultureIgnoreCase)) { this.InGameResolution = InGameResolution.HD_720p; } else if (string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].GamingResolutionCOD, "1080", StringComparison.InvariantCultureIgnoreCase)) { this.InGameResolution = InGameResolution.FHD_1080p; } else if (string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].GamingResolutionCOD, "1440", StringComparison.InvariantCultureIgnoreCase)) { this.InGameResolution = InGameResolution.QHD_1440p; } else if (string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].GamingResolutionCOD, "2160", StringComparison.InvariantCultureIgnoreCase)) { this.InGameResolution = InGameResolution.UHD_2160p; } if (string.IsNullOrEmpty(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].DisplayQualityCOD) || string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].DisplayQualityCOD, "-1", StringComparison.InvariantCultureIgnoreCase)) { this.GraphicsQuality = GraphicsQuality.Auto; } else if (string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].DisplayQualityCOD, "0", StringComparison.InvariantCultureIgnoreCase)) { this.GraphicsQuality = GraphicsQuality.Smooth; } else if (string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].DisplayQualityCOD, "1", StringComparison.InvariantCultureIgnoreCase)) { this.GraphicsQuality = GraphicsQuality.Balanced; } else { if (!string.Equals(RegistryManager.Instance.Guest[this.ParentWindow.mVmName].DisplayQualityCOD, "2", StringComparison.InvariantCultureIgnoreCase)) { return; } this.GraphicsQuality = GraphicsQuality.HD; } }
private void Awake() { if (RenderPipelineInfo.Type == RPType.HDRP) { m_ligthIntensityDefault = 10000; m_shadowStrengthDefault = 1; } else if (RenderPipelineInfo.Type == RPType.URP) { m_ligthIntensityDefault = 2; m_shadowStrengthDefault = 0.75f; } else { m_ligthIntensityDefault = 1; m_shadowStrengthDefault = 1; } //simplified user's hardware configuration evaluation if (SystemInfo.graphicsMemorySize > 4096) { m_graphicsQualityDefault = GraphicsQuality.High; } else if (SystemInfo.graphicsMemorySize > 2048) { m_graphicsQualityDefault = GraphicsQuality.Medium; } else { m_graphicsQualityDefault = GraphicsQuality.Low; } Themes = Resources.LoadAll("Themes", typeof(ThemeAsset)).OfType <ThemeAsset>().OrderBy(a => a.name != "Dark").ToArray(); IOC.RegisterFallback <ISettingsComponent>(this); m_wm = IOC.Resolve <IWindowManager>(); m_wm.AfterLayout += OnAfterLayout; m_wm.WindowCreated += OnWindowCreated; m_wm.WindowDestroyed += OnWindowDestoryed; }
/// <summary> /// <para>Returns a redrawn Image.</para> /// </summary> /// <param name="image">The Image to redraw.</param> /// <param name="graphicsQuality">The graphics quality for the resulting Image.</param> /// <param name="pixelFormat">The pixel format for the resulting Image.</param> /// <returns>The redrawn Image</returns> /// <exception cref="System.ArgumentNullException">Thrown when the image parameter is null</exception> /// <exception cref="System.ArgumentException">Thrown when the pixel format of the image parameter is indexed</exception> public static Image Redraw(this Image image, GraphicsQuality graphicsQuality, PixelFormat pixelFormat) { if (image == null) { throw new ArgumentNullException("image"); } if ((pixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { throw new ArgumentException("Images can only be redrawn to NON-Indexed pixel formats", "pixelFormat"); } Image retVal = new Bitmap(image.Width, image.Height, pixelFormat); using (Graphics graphics = Graphics.FromImage(retVal)) { graphics.ApplyGraphicsQualitySetting(graphicsQuality); graphics.DrawImage(image, new Rectangle(0, 0, retVal.Width, retVal.Height)); graphics.Save(); } return(retVal); }
public static GraphicsQuality SetQuality(this Graphics g, GraphicsQuality quality) { var result = new GraphicsQuality { InterpolationMode = g.InterpolationMode, CompositingMode = g.CompositingMode, CompositingQuality = g.CompositingQuality, SmoothingMode = g.SmoothingMode, TextRenderingHint = g.TextRenderingHint, PixelOffsetMode = g.PixelOffsetMode }; if (true) { g.InterpolationMode = quality.InterpolationMode; g.CompositingMode = quality.CompositingMode; g.CompositingQuality = quality.CompositingQuality; g.SmoothingMode = quality.SmoothingMode; g.TextRenderingHint = quality.TextRenderingHint; g.PixelOffsetMode = quality.PixelOffsetMode; } return(result); }
/// <summary> /// Applies the graphics quality setting. /// </summary> /// <param name="graphics">The Graphics object which to apply the GraphicsQuality settings to.</param> /// <param name="graphicsQuality">The GraphicsQuality to apply.</param> /// <exception cref="System.ArgumentNullException">Thrown when the graphics parameter is null</exception> public static void ApplyGraphicsQualitySetting(this Graphics graphics, GraphicsQuality graphicsQuality) { if (graphics == null) { throw new ArgumentNullException("graphics"); } switch (graphicsQuality) { case GraphicsQuality.Low: graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed; graphics.SmoothingMode = SmoothingMode.HighSpeed; graphics.InterpolationMode = InterpolationMode.Low; graphics.CompositingQuality = CompositingQuality.HighSpeed; break; case GraphicsQuality.Medium: graphics.PixelOffsetMode = PixelOffsetMode.Half; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.InterpolationMode = InterpolationMode.High; graphics.CompositingQuality = CompositingQuality.Default; break; case GraphicsQuality.High: graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; break; default: graphics.PixelOffsetMode = PixelOffsetMode.Default; graphics.SmoothingMode = SmoothingMode.None; graphics.InterpolationMode = InterpolationMode.Bilinear; graphics.CompositingQuality = CompositingQuality.Default; break; } }
private void DisableDashBoard() { dashboard.GetComponent <Image>().CrossFadeAlpha(0.01f, 0.3f, false); CategoryTitle.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Overview.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Inventory.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Config.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Save.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Load.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Exit.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); PlayedTime.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Reputation.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); Language.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); GraphicsQuality.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); TextureQuality.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); FoV.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); QualityValue.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); GQ_LeftArrow.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); GQ_RightArrow.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); LDD_Label.GetComponent <Text>().CrossFadeAlpha(0.01f, 0.3f, false); LDD_Arrow.GetComponent <Image>().CrossFadeAlpha(0.01f, 0.3f, false); SetUICategoryContent(44); DashboardStatus = false; }
/// <summary> /// <para>Clips the specified image.</para> /// </summary> /// <param name="image">The image to clip.</param> /// <param name="maxWidth">The maximum width for the resulting Image. Set to 0 if there's no maximum width.</param> /// <param name="maxHeight">The maximum height for the resulting Image. Set to 0 if there's no maximum height.</param> /// <param name="graphicsQuality">The graphics quality for the resulting Image.</param> /// <param name="maintainPalette">If set to <c>true</c> the(if any) palette will be maintained. Transparency will be saved.</param> /// <returns>The clipped Image</returns> /// <exception cref="System.ArgumentNullException">Thrown when the image parameter is null</exception> public static Image Clip(this Image image, int maxWidth, int maxHeight, GraphicsQuality graphicsQuality, bool maintainPalette) { if (image == null) { throw new ArgumentNullException("image"); } if (maxWidth <= 0) { maxWidth = image.Width; } if (maxHeight <= 0) { maxHeight = image.Height; } Image retVal = image; Bitmap bitmap = new Bitmap(maxWidth, maxHeight); using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.ApplyGraphicsQualitySetting(graphicsQuality); graphics.DrawImage(image, image.CalculateClipRectangle(maxWidth, maxHeight)); graphics.Save(); } retVal = bitmap; if (maintainPalette && image.HasIndexedPixelFormat()) { retVal = bitmap.PaletteQuantize(image.Palette.Entries); bitmap.Dispose(); } return(retVal); }
/// <summary> /// Resizes proportionally and crops an image to fill the desired Size /// </summary> /// <param name="imgPhoto"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="alignment"></param> /// <param name="quality"></param> /// <param name="format"></param> /// <returns></returns> public static Image ScaleToFill(this Image imgPhoto, int width, int height, ContentAlignment alignment = ContentAlignment.MiddleCenter, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { var sourceWidth = imgPhoto.Width; var sourceHeight = imgPhoto.Height; const int sourceX = 0; const int sourceY = 0; var destX = 0; var destY = 0; float nPercent; var nPercentW = (float)width / sourceWidth; var nPercentH = (float)height / sourceHeight; if (nPercentH < nPercentW) { nPercent = nPercentW; switch (alignment) { case ContentAlignment.TopCenter: case ContentAlignment.TopLeft: case ContentAlignment.TopRight: destY = 0; break; case ContentAlignment.BottomCenter: case ContentAlignment.BottomLeft: case ContentAlignment.BottomRight: destY = (int) (height - sourceHeight * nPercent); break; default: destY = (int) ((height - sourceHeight * nPercent) / 2); break; } } else { nPercent = nPercentH; switch (alignment) { case ContentAlignment.BottomLeft: case ContentAlignment.MiddleLeft: case ContentAlignment.TopLeft: destX = 0; break; case ContentAlignment.BottomRight: case ContentAlignment.MiddleRight: case ContentAlignment.TopRight: destX = (int) (width - sourceWidth * nPercent); break; default: destX = (int) ((width - sourceWidth * nPercent) / 2); break; } } var destWidth = (int)(sourceWidth * nPercent); var destHeight = (int)(sourceHeight * nPercent); var bmPhoto = new Bitmap(width, height, format); bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); using (var grPhoto = GetGraphics(bmPhoto, quality)) { grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); } return(bmPhoto); }
public void SetQualityLevel(GraphicsQuality quality) { //QualitySettings.SetQualityLevel((int)quality, false); }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> public void ProcessRequest(HttpContext context) { context.Response.Clear(); context.Response.Cache.SetCacheability(HttpCacheability.Public); context.Response.Cache.SetAllowResponseInBrowserHistory(true); context.Response.Cache.SetValidUntilExpires(true); context.Response.BufferOutput = false; try { HttpRequest request = context.Request; HttpResponse response = context.Response; bool leechProtect = request.GetQueryStringValue <bool>("lp", false); //validate the request if (!request.IsValid(true, leechProtect)) { throw new HttpException((int)HttpStatusCode.BadRequest, "The request did not pass validation."); } //retrieve the filepath of the image we would like to retrieve string imageSrc = GetImageSourceQueryStringValue(context); //create an image retriever and get the file extension ImageRetriever imageRetriever = ImageRetrieverFactory.CreateImageRetriever(imageSrc); string filename = imageRetriever.GetFileNameWithoutExtension(); string extension = imageRetriever.GetExtension().ToUpperInvariant(); //set the content type of the response response.ContentType = GetContentType(extension); //set the content-disposition header to the given SaveName or the filename string saveName = request.GetQueryStringValue <string>("sn", filename); response.AppendHeader("Content-Disposition", string.Concat("inline; filename=\"", saveName, "\"")); using (MemoryStream memoryStream = new MemoryStream()) { string hash = request.GetQueryStringValue <string>("ha", null); bool cacheOutput = request.GetQueryStringValue <bool>("co", false); bool fromCache = false; if (cacheOutput) { object cache = context.Cache[hash]; if (cache != null) { fromCache = true; byte[] buffer = (byte[])cache; memoryStream.Write(buffer, 0, buffer.Length); } } if (!fromCache) { int width = request.GetQueryStringValue <int>("w", 0); int height = request.GetQueryStringValue <int>("h", 0); GraphicsQuality graphicsQuality = (GraphicsQuality)request.GetQueryStringValue <int>("rq", 2); bool maintainPalette = request.GetQueryStringValue <bool>("mp", false); bool clip = request.GetQueryStringValue <bool>("cl", false); using (Image originalImage = imageRetriever.GetImage()) using (Image resizedBitmap = (clip) ? originalImage.Clip(width, height, graphicsQuality, maintainPalette) : originalImage.Resize(width, height, graphicsQuality, maintainPalette)) { if (!resizedBitmap.HasIndexedPixelFormat()) { string copyrightText = request.GetQueryStringValue <string>("ct", null); if (!string.IsNullOrEmpty(copyrightText)) { int copyrightFontSize = request.GetQueryStringValue <int>("cts", 0); resizedBitmap.AddCopyrightText(copyrightText, copyrightFontSize); } if (request.GetQueryStringValue("g", false)) { resizedBitmap.ApplyGrayscaleColorMatrix(); } if (request.GetQueryStringValue("n", false)) { resizedBitmap.ApplyNegativeColorMatrix(); } if (request.GetQueryStringValue("s", false)) { resizedBitmap.ApplySepiaColorMatrix(); } float brightness = request.GetQueryStringValue <float>("b", 0F); if (brightness != 0) { resizedBitmap.SetBrightness(brightness); } float contrast = request.GetQueryStringValue <float>("c", 0F); if (contrast != 0) { resizedBitmap.SetContrast(contrast); } } ImageFormat imageFormat = GetImageFormatByExtension(extension); long outputQuality = request.GetQueryStringValue <long>("oq", 75L); if (QuantizeableExtension(extension) && request.GetQueryStringValue <bool>("q", false)) { using (Image quantizedBitmap = resizedBitmap.OctreeQuantize()) { quantizedBitmap.SaveToMemoryStream(memoryStream, imageFormat, outputQuality); } } else { resizedBitmap.SaveToMemoryStream(memoryStream, imageFormat, outputQuality); } } } memoryStream.Capacity = (int)memoryStream.Position; if (memoryStream.Capacity > 0) { response.Cache.SetExpires(DateTime.Now.AddMinutes(browserCacheExpirationMinutes)); response.Cache.SetLastModified(imageRetriever.GetLastModifiedDate()); memoryStream.WriteTo(context.Response.OutputStream); if (cacheOutput && !fromCache) { context.Cache[hash] = memoryStream.ToArray(); } } } } catch (FileNotFoundException) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; } catch (HttpException httpException) { context.Response.StatusCode = httpException.GetHttpCode(); } finally { context.Response.Flush(); context.Response.End(); } }
/// <summary> /// <para>Gets a resized Image from a Stream.</para> /// </summary> /// <param name="stream">The Stream containing an image</param> /// <param name="maxWidth">The maximum width for the resulting Image. Set to 0 if there's no maximum width.</param> /// <param name="maxHeight">The maximum height for the resulting Image. Set to 0 if there's no maximum height.</param> /// <param name="graphicsQuality">The GraphicsQuality for the resulting Image.</param> /// <param name="maintainPalette">If set to <c>true</c> the(if any) palette will be maintained. Transparency will be saved.</param> /// <returns>The resized Image</returns> /// <exception cref="System.ArgumentNullException">Thrown when the stream parameter is null</exception> public static Image GetResizedImagedFromStream(Stream stream, int maxWidth, int maxHeight, GraphicsQuality graphicsQuality, bool maintainPalette) { if (stream == null) { throw new ArgumentNullException("stream"); } Image retVal = null; using (Bitmap sourceBitmap = new Bitmap(stream)) { retVal = Resize(sourceBitmap, maxWidth, maxHeight, graphicsQuality, maintainPalette); } return(retVal); }
private void SetUICategoryContent(int Category) { switch (Category) { default: PlayedTime.SetActive(true); Reputation.SetActive(true); Language.SetActive(false); GraphicsQuality.SetActive(false); TextureQuality.SetActive(false); FoV.SetActive(false); GQ_LeftArrow.SetActive(false); GQ_RightArrow.SetActive(false); LDD.SetActive(false); FoVSliderValue.SetActive(false); break; case 1: PlayedTime.SetActive(true); Reputation.SetActive(true); Language.SetActive(false); GraphicsQuality.SetActive(false); TextureQuality.SetActive(false); FoV.SetActive(false); GQ_LeftArrow.SetActive(false); GQ_RightArrow.SetActive(false); LDD.SetActive(false); FoVSliderValue.SetActive(false); break; case 2: PlayedTime.SetActive(false); Reputation.SetActive(false); Language.SetActive(true); GraphicsQuality.SetActive(true); TextureQuality.SetActive(true); FoV.SetActive(true); GQ_LeftArrow.SetActive(true); GQ_RightArrow.SetActive(true); LDD.SetActive(true); FoVSliderValue.SetActive(true); break; case 3: PlayedTime.SetActive(false); Reputation.SetActive(false); Language.SetActive(false); GraphicsQuality.SetActive(false); TextureQuality.SetActive(false); FoV.SetActive(false); GQ_LeftArrow.SetActive(false); GQ_RightArrow.SetActive(false); LDD.SetActive(false); FoVSliderValue.SetActive(false); break; case 4: PlayedTime.SetActive(false); Reputation.SetActive(false); Language.SetActive(false); GraphicsQuality.SetActive(false); TextureQuality.SetActive(false); FoV.SetActive(false); GQ_LeftArrow.SetActive(false); GQ_RightArrow.SetActive(false); LDD.SetActive(false); FoVSliderValue.SetActive(false); break; case 5: PlayedTime.SetActive(false); Reputation.SetActive(false); Language.SetActive(false); GraphicsQuality.SetActive(false); TextureQuality.SetActive(false); FoV.SetActive(false); GQ_LeftArrow.SetActive(false); GQ_RightArrow.SetActive(false); LDD.SetActive(false); break; case 44: PlayedTime.SetActive(false); Reputation.SetActive(false); Language.SetActive(false); GraphicsQuality.SetActive(false); TextureQuality.SetActive(false); FoV.SetActive(false); GQ_LeftArrow.SetActive(false); GQ_RightArrow.SetActive(false); LDD.SetActive(false); FoVSliderValue.SetActive(false); break; } }
public virtual void LoadUserConfig() { //string fullPath = ResourceModule.GetFullPath("config/user/useroptionscfg.xml", false); string fullPath = ""; if (File.Exists(fullPath)) { using (XmlReader xmlReader = XmlReader.Create(fullPath)) { if (null != xmlReader) { this.m_bHasSet = true; while (xmlReader.Read()) { if (xmlReader.Name == "element" && xmlReader.NodeType == XmlNodeType.Element) { string text = xmlReader.GetAttribute("id").ToLower(); string attribute = xmlReader.GetAttribute("value"); string text2 = text; switch (text2) { //case "resolution": // { // string[] array = attribute.Split(new char[] //{ // ',' //}); // if (array.Length == 2) // { // int nWidth = Convert.ToInt32(array[0]); // int nHeight = Convert.ToInt32(array[1]); // this.m_IGraphicsResolution = GraphicsManager.CreateResolution(nWidth, nHeight); // } // break; // } case "mutesound": this.m_bMuteSound = (Convert.ToInt32(attribute) != 0); break; case "bgsoundvalue": this.m_fBGSoundValue = (float)Convert.ToDouble(attribute); break; case "uisoundvalue": this.m_fUISoundValue = (float)Convert.ToDouble(attribute); break; case "soundvalue": this.m_fSoundValue = (float)Convert.ToDouble(attribute); break; case "voicevalue": this.m_fVoiceValue = (float)Convert.ToDouble(attribute); break; case "qualitysetting": this.m_eGraphicsQuality = (GraphicsQuality)Convert.ToInt32(attribute); break; } } } } } } }
/// <summary> /// <para>Clips the specified image.</para> /// </summary> /// <param name="image">The image to clip.</param> /// <param name="maxWidth">The maximum width for the resulting Image. Set to 0 if there's no maximum width.</param> /// <param name="maxHeight">The maximum height for the resulting Image. Set to 0 if there's no maximum height.</param> /// <param name="graphicsQuality">The graphics quality for the resulting Image.</param> /// <returns>The clipped Image</returns> /// <exception cref="System.ArgumentNullException">Thrown when the image parameter is null</exception> public static Image Clip(this Image image, int maxWidth, int maxHeight, GraphicsQuality graphicsQuality) { return(Clip(image, maxWidth, maxHeight, graphicsQuality, false)); }
/// <summary> /// Enlarge the image background using the specified color /// </summary> /// <param name="img"></param> /// <param name="backColor"></param> /// <param name="imgAlignment"></param> /// <param name="quality"></param> /// <param name="format"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static Image EnlargeCanvas(this Image img, int width, int height, Color backColor, ContentAlignment imgAlignment = ContentAlignment.MiddleCenter, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { if (img.Width > width || img.Height > height) { throw new InvalidOperationException("Image size is bigger than canvas target size"); } var bmPhoto = new Bitmap(width, height, format); bmPhoto.SetResolution(img.HorizontalResolution, img.VerticalResolution); using (var grPhoto = GetGraphics(bmPhoto, quality)) { grPhoto.Clear(backColor); int destX, destY; switch (imgAlignment) { case ContentAlignment.BottomCenter: destX = (width - img.Width) / 2; destY = height - img.Height; break; case ContentAlignment.BottomLeft: destX = 0; destY = height - img.Height; break; case ContentAlignment.BottomRight: destX = width - img.Width; destY = height - img.Height; break; case ContentAlignment.MiddleCenter: destX = (width - img.Width) / 2; destY = (height - img.Height) / 2; break; case ContentAlignment.MiddleLeft: destX = 0; destY = (height - img.Height) / 2; break; case ContentAlignment.MiddleRight: destX = width - img.Width; destY = (height - img.Height) / 2; break; case ContentAlignment.TopCenter: destX = (width - img.Width) / 2; destY = 0; break; case ContentAlignment.TopLeft: destX = 0; destY = 0; break; case ContentAlignment.TopRight: destX = width - img.Width; destY = 0; break; default: destX = 0; destY = 0; break; } grPhoto.DrawImage(img, new Rectangle(destX, destY, img.Width, img.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); } return(bmPhoto); }
/// <summary> /// Resizes an image proportionally to fit into the desired Size /// </summary> /// <param name="img"></param> /// <param name="format"></param> /// <param name="maxSize"></param> /// <param name="quality"></param> /// <returns></returns> public static Image ScaleToFit(this Image img, Size maxSize, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { return(ScaleToFit(img, maxSize.Width, maxSize.Height, quality, format)); }
/// <summary> /// <para>Gets a resized Image from a Stream. Not maintaining the(if any) palette.</para> /// </summary> /// <param name="stream">The Stream containing an Image</param> /// <param name="maxWidth">The maximum width for the resulting Image. Set to 0 if there's no maximum width.</param> /// <param name="maxHeight">The maximum height for the resulting Image. Set to 0 if there's no maximum height.</param> /// <param name="graphicsQuality">The GraphicsQuality for the resulting Image.</param> /// <returns>Image</returns> public static Image GetResizedImageFromStream(Stream stream, int maxWidth, int maxHeight, GraphicsQuality graphicsQuality) { return(GetResizedImagedFromStream(stream, maxWidth, maxHeight, graphicsQuality, false)); }
/// <summary> /// Resizes an image proportionally adding borders to fit into the desired Size /// </summary> /// <param name="img">Image to resize</param> /// <param name="outputSize">Output size</param> /// <param name="backColor">Background color for the output image</param> /// <param name="quality"></param> /// <param name="format"></param> /// <returns></returns> public static Image ScaleToSize(this Image img, Size outputSize, Color backColor, GraphicsQuality quality = GraphicsQuality.Default, PixelFormat format = PixelFormat.Format32bppArgb) { return(ScaleToSize(img, outputSize.Width, outputSize.Height, backColor, quality, format)); }