Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After some more research and testing, I've found that the problem occurs only if the <code>Bitmap.RotateFlip</code> method has been called on the source bitmap, before it is drawn onto a target bitmap for cropping and resizing.</p> <p>I ended up having to re-write the code using plain old <code>System.Drawing</code> myself, because there is no way to change the behavior of the ImageResizer library. Specifically, I wrote my own rotation function, which uses a transformation matrix to do the same thing.</p> <pre><code> private Bitmap RotateImage(Bitmap source, float angle) { if (angle == 0) return (Bitmap)source.Clone(); Bitmap target; using (GraphicsPath path = new GraphicsPath()) using (Matrix matrix = new Matrix()) { path.AddRectangle(new RectangleF(0.0f, 0.0f, source.Width, source.Height)); matrix.Rotate(angle); RectangleF rect = path.GetBounds(matrix); target = new Bitmap((int)Math.Round(rect.Width), (int)Math.Round(rect.Height)); target.SetResolution(source.HorizontalResolution, source.VerticalResolution); using (Graphics g = Graphics.FromImage(target)) { g.TranslateTransform(-rect.X, -rect.Y); g.RotateTransform(angle); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImageUnscaled(source, 0, 0); } } return target; } </code></pre> <p>I would have wanted to set the <code>PixelFormat</code> of the new <code>Bitmap</code> to the one from the source - but doing so throws weird GDI+ "Out of memory" errors on encountering the CMYK JPEG files in question. This makes me wonder if this odd behavior is linked to <a href="https://stackoverflow.com/q/4315335/1292105">this</a> GDI+ bug/quirk that returns different <code>ImageFlags</code> and <code>PixelFormat</code> values on Windows 7/Server 2008 R2 and Windows Vista/Server 2008.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload