public static string writePadding(BoxPadding p) { if (!double.IsNaN(p.All)) { return(p.All.ToString(NumberFormatInfo.InvariantInfo)); //Easy } return("(" + p.Left.ToString(NumberFormatInfo.InvariantInfo) + "," + p.Top.ToString(NumberFormatInfo.InvariantInfo) + "," + p.Right.ToString(NumberFormatInfo.InvariantInfo) + "," + p.Bottom.ToString(NumberFormatInfo.InvariantInfo) + ")"); }
/// <summary> /// Builds an FIBitmap from the stream and job.Settings /// </summary> /// <param name="original"></param> /// <param name="supportsTransparency"></param> /// <param name="mayUnloadOriginal"></param> /// <param name="job"></param> /// <returns></returns> protected FIBITMAP buildFiBitmap(ref FIBITMAP original, ImageJob job, bool supportsTransparency, bool mayUnloadOriginal) { ResizeSettings settings = job.Settings; if (original.IsNull) { return(FIBITMAP.Zero); } FIBITMAP final = FIBITMAP.Zero; //Find the image size Size orig = new Size((int)FreeImage.GetWidth(original), (int)FreeImage.GetHeight(original)); //Calculate the new size of the image and the canvas. ImageState state = new ImageState(settings, orig, true); state.Job = job; c.CurrentImageBuilder.Process(state); RectangleF imageDest = PolygonMath.GetBoundingBox(state.layout["image"]); if (imageDest.Width != orig.Width || imageDest.Height != orig.Height) { //Rescale bool temp; final = FreeImage.Rescale(original, (int)imageDest.Width, (int)imageDest.Height, FreeImageScalingPlugin.ParseResizeAlgorithm(settings["fi.scale"], FREE_IMAGE_FILTER.FILTER_BOX, out temp)); if (mayUnloadOriginal) { FreeImage.UnloadEx(ref original); } if (final.IsNull) { return(FIBITMAP.Zero); } } else { final = original; } RGBQUAD bgcolor = default(RGBQUAD); bgcolor.Color = settings.BackgroundColor; if (settings.BackgroundColor == Color.Transparent && !supportsTransparency) { bgcolor.Color = Color.White; } //If we need to leave padding, do so. BoxPadding outsideImage = new BoxPadding(imageDest.Left, imageDest.Top, state.destSize.Width - imageDest.Right, state.destSize.Height - imageDest.Bottom); if (outsideImage.All != 0) { var old = final; //Extend canvas final = FreeImage.EnlargeCanvas <RGBQUAD>(old, (int)outsideImage.Left, (int)outsideImage.Top, (int)outsideImage.Right, (int)outsideImage.Bottom, bgcolor.Color != Color.Transparent ? new Nullable <RGBQUAD>(bgcolor) : null, FREE_IMAGE_COLOR_OPTIONS.FICO_RGBA); if (old == original) { if (mayUnloadOriginal) { FreeImage.UnloadEx(ref original); old = original; } } else { FreeImage.UnloadEx(ref old); //'old' has the original value of 'final', which we allocated. } if (final.IsNull) { return(FIBITMAP.Zero); } } if (!final.IsNull) { job.ResultInfo["final.width"] = (int)FreeImage.GetWidth(final); job.ResultInfo["final.height"] = (int)FreeImage.GetHeight(final); } return(final); }