public void GetScaledInstance() { using (FreeImageBitmap fib = new FreeImageBitmap(100, 80, PixelFormat.Format32bppArgb)) { Assert.AreEqual(100, fib.Width); Assert.AreEqual(80, fib.Height); using (FreeImageBitmap conv = fib.GetScaledInstance(80, 60, FREE_IMAGE_FILTER.FILTER_BICUBIC)) { Assert.IsNotNull(conv); Assert.AreEqual(80, conv.Width); Assert.AreEqual(60, conv.Height); } } }
/// <summary> /// 旋转图片 /// </summary> /// <param name="vRotate">旋转角度</param> public void RotateImage(double vRotate) { if (isBitmap) { // Create a temporary rescaled bitmap using (FreeImageBitmap temp = bitmap.GetScaledInstance(resultbmp.Width, resultbmp.Height, FREE_IMAGE_FILTER.FILTER_CATMULLROM)) { if (temp != null) { // Rotate the bitmap temp.Rotate(vRotate); if (resultbmp != null) { resultbmp.Dispose(); } // Display the result resultbmp = (Bitmap)temp; } } } }
private void bRotate_Click(object sender, EventArgs e) { if (Bitmap) { // Create a temporary rescaled bitmap using (FreeImageBitmap temp = bitmap.GetScaledInstance( pictureBox.DisplayRectangle.Width, pictureBox.DisplayRectangle.Height, FREE_IMAGE_FILTER.FILTER_CATMULLROM)) { if (temp != null) { // Rotate the bitmap temp.Rotate((double)vRotate.Value); if (pictureBox.Image != null) { pictureBox.Image.Dispose(); } // Display the result pictureBox.Image = (Bitmap)temp; } } } }
/// <summary> /// Gets a new buffer with the specified size. /// </summary> /// <returns>The scaled buffer.</returns> /// <param name="NewSize">New size.</param> public PixelBuffer GetScaledBuffer(Vector2i newSize, FilteringType filtering) { FreeImageBitmap Scaled; using (FreeImageBitmap Bmp = new FreeImageBitmap(BufferSize.Width, BufferSize.Height, BufferSize.Width * 4, PixelFormat.Format32bppArgb, Pixels)) { // Get scaled bitmap Scaled = Bmp.GetScaledInstance(newSize, (FREE_IMAGE_FILTER)filtering); } PixelBuffer buffer = new PixelBuffer(newSize); // Convert from GBRA to RGBA int z = 0; for (int i = newSize.Height - 1; i >= 0; i--, z++) { Marshal.Copy(Scaled.Bits + (z * newSize.Width * 4), buffer.Pixels, i * newSize.Width * 4, newSize.Width * 4); } Scaled.Dispose(); return(buffer); }
private static FreeImageBitmap GetScaledBmp(FreeImageBitmap bitmap) { var bmp = bitmap; if (bitmap.Width > MaxTextureWidth || bitmap.Height > MaxTextureHeight) { bmp = bitmap.GetScaledInstance(Math.Min(MaxTextureWidth, bitmap.Width), Math.Min(MaxTextureHeight, bitmap.Height), FREE_IMAGE_FILTER.FILTER_LANCZOS3); } return bmp; }