/// <summary> /// Resizes the image to the new dimensions /// </summary> /// <param name="srcImage"></param> /// <param name="newWidth"></param> /// <param name="newHeight"></param> /// <returns></returns> public static System.Drawing.Bitmap ResizeImage(System.Drawing.Bitmap srcImage, int newWidth, int newHeight) { if (srcImage == null) { throw new DjvuArgumentNullException(nameof(srcImage)); } // Check if the image needs resizing if (srcImage.Width == newWidth && srcImage.Height == newHeight) { return(srcImage); } if (newWidth <= 0 || newHeight <= 0) { throw new DjvuArgumentException( $"Invalid new image dimensions width: {newWidth}, height: {newHeight}", nameof(newWidth) + " " + nameof(newHeight)); } // Resize the image System.Drawing.Bitmap newImage = new System.Drawing.Bitmap(newWidth, newHeight, srcImage.PixelFormat); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.HighQuality; gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(srcImage, new System.Drawing.Rectangle(0, 0, newWidth, newHeight)); } srcImage.Dispose(); return(newImage); }
/// <summary> /// Clears the stored image from memory /// </summary> public void ClearImage() { IsPageImageCached = false; if (_image != null) { _image.Dispose(); _image = null; } }
public void Disposer() { _device.Dispose(); _output1.Dispose(); _texture2D.Dispose(); _outputDuplication.Dispose(); //_textureDescription.Dispose(); _bitmap.Dispose(); _bitmapPlayerRect.Dispose(); _screenResource.Dispose(); //_frameCaptureData.Dispose(); GC.Collect(); }
internal static void LoadTextureInternal(Texture t, System.Drawing.Bitmap bmp) { System.Drawing.Imaging.PixelFormat lock_format; switch (bmp.PixelFormat) { case System.Drawing.Imaging.PixelFormat.Format32bppArgb: lock_format = System.Drawing.Imaging.PixelFormat.Format32bppArgb; break; case System.Drawing.Imaging.PixelFormat.Format24bppRgb: lock_format = System.Drawing.Imaging.PixelFormat.Format32bppArgb; break; default: t.Failed = true; return; } int glTex; // Create the opengl texture GL.GenTextures(1, out glTex); GL.BindTexture(TextureTarget.Texture2D, glTex); lastTextureID = glTex; GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); // Sort out our GWEN texture t.RendererData = glTex; t.Width = bmp.Width; t.Height = bmp.Height; var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, lock_format); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, t.Width, t.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); bmp.UnlockBits(data); bmp.Dispose(); }
protected virtual void Dispose(bool disposing) { if (Disposed) { return; } if (disposing) { } _Image?.Dispose(); _Image = null; _ThumbnailImage?.Dispose(); _ThumbnailImage = null; _Disposed = true; }
/// <summary> /// Resizes the image to the new dimensions /// </summary> /// <param name="srcImage"></param> /// <param name="newWidth"></param> /// <param name="newHeight"></param> /// <returns></returns> public System.Drawing.Bitmap ResizeImage(System.Drawing.Bitmap srcImage, int newWidth, int newHeight) { // Check if the image needs resizing if (srcImage.Width == newWidth && srcImage.Height == newHeight) { return(srcImage); } // Resize the image System.Drawing.Bitmap newImage = new System.Drawing.Bitmap(newWidth, newHeight); using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(newImage)) { gr.SmoothingMode = SmoothingMode.HighQuality; gr.InterpolationMode = InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = PixelOffsetMode.HighQuality; gr.DrawImage(srcImage, new System.Drawing.Rectangle(0, 0, newWidth, newHeight)); } srcImage.Dispose(); return(newImage); }
internal PageImage GetPageImage(Report rpt, Row row) { string mtype = null; Stream strm = null; System.Drawing.Bitmap im = null; PageImage pi = null; WorkClass wc = GetWC(rpt); if (wc.PgImage != null) { // have we already generated this one // reuse most of the work; only position will likely change pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.ImageData, wc.PgImage.SamplesW, wc.PgImage.SamplesH); pi.Name = wc.PgImage.Name; // this is name it will be shared under return(pi); } try { strm = GetImageStream(rpt, row, out mtype); if (strm == null) { rpt.rl.LogError(4, string.Format("Unable to load image {0}.", this._Value == null?"": this._Value.EvaluateString(rpt, row))); return(null); } im = Bitmap.FromStream(strm); int height = im.Height; int width = im.Width; MemoryStream ostrm = new MemoryStream(); ImageFormat imf; // if (mtype.ToLower() == "image/jpeg") //TODO: how do we get png to work // imf = ImageFormatType.Jpeg; // else imf = ImageFormat.Jpeg; System.Drawing.Imaging.ImageCodecInfo[] info; info = ImageCodecInfo.GetImageEncoders(); EncoderParameters encoderParameters; encoderParameters = new EncoderParameters(1); encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality); System.Drawing.Imaging.ImageCodecInfo codec = null; for (int i = 0; i < info.Length; i++) { if (info[i].FormatDescription == "JPEG") { codec = info[i]; break; } } im.Save(ostrm, codec, encoderParameters); byte[] ba = ostrm.ToArray(); ostrm.Close(); pi = new PageImage(imf, ba, width, height); pi.SI = new StyleInfo(); // this will just default everything if (_BackgroundRepeat != null) { string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower(); switch (r) { case "repeat": pi.Repeat = ImageRepeat.Repeat; break; case "repeatx": pi.Repeat = ImageRepeat.RepeatX; break; case "repeaty": pi.Repeat = ImageRepeat.RepeatY; break; case "norepeat": default: pi.Repeat = ImageRepeat.NoRepeat; break; } } else { pi.Repeat = ImageRepeat.Repeat; } if (_ConstantImage) { wc.PgImage = pi; // create unique name; PDF generation uses this to optimize the saving of the image only once pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString(); // create unique name } } finally { if (strm != null) { strm.Close(); } if (im != null) { im.Dispose(); } } return(pi); }