/// <summary> /// Creates a new Page image list from a file on disk. Pages /// will be extracted into the Page image list if the source is multipage. /// </summary> /// <param name="imageFileName">The source file.</param> /// <param name="quality">Quality Conversion</param> /// <returns>A new Page Image List</returns> public static List <PageImage> LoadImage(string imageFileName, FaxQuality quality) { Image img = Image.FromFile(imageFileName); List <PageImage> ret = ImageUtility.LoadImage(img, true); img.Dispose(); return(ret); }
/// <summary> /// Creates a new PageImageList containing pages that have a fax geometry. /// </summary> /// <param name="pages">The PageImageList to alter.</param> /// <param name="quality">The Fax Quality. Default is Low.</param> /// <param name="paperSize">The Paper size. Default is Auto.</param> /// <param name="interpolationMode">The Interpolation mode. Default is High, but will use the current value in Image Utility, unless defined here. size.</param> /// <returns>The new PageImageList (always with 32bpp pixel format)</returns> private static List <PageImage> ConvertToFaxGeometry(List <PageImage> pages, FaxQuality quality, PaperSize paperSize, InterpolationMode interpolationMode) { List <PageImage> ret = ImageConverter.CreateEmptyPageImageList(pages.Count, PixelFormat.Format32bppArgb, pages[0].Bitmap.Palette, quality, paperSize); for (int i = 0; i < pages.Count; i++) { ImageConverter.ConvertToFaxGeometry(pages[i], ret[i], interpolationMode); } return(ret); }
/// <summary> /// Creates a Bitmap that will have the indicated pixel format, size and resolution /// </summary> /// <param name="paperSize">The required paper size</param> /// <param name="faxQuality">The required fax quality</param> /// <param name="pixelFormat">The needed pixel format</param> /// <returns>The new image with the correct settings.</returns> internal static Bitmap CreateBitMap(PaperSize paperSize, FaxQuality faxQuality, ColorPalette palette, PixelFormat pixelFormat) { Bitmap ret = null; switch (paperSize) { case PaperSize.Legal: { switch (faxQuality) { case FaxQuality.Fine: { ret = palette == null?CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LGL_HI, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_HI, pixelFormat) : CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LGL_HI, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_HI, palette, pixelFormat); break; } default: { ret = palette == null?CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LGL_LOW, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_LOW, pixelFormat) : CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LGL_LOW, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_LOW, palette, pixelFormat); break; } } break; } default: { switch (faxQuality) { case FaxQuality.Fine: { ret = palette == null?BitmapHelper.CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LTR_HI, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_HI, pixelFormat) : CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LTR_HI, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_HI, palette, pixelFormat); break; } default: { ret = palette == null?BitmapHelper.CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LTR_LOW, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_LOW, pixelFormat) : CreateBitMap(ImageUtility.FAX_TIF_HOR_PX, ImageUtility.FAX_TIF_VER_PX_LTR_LOW, ImageUtility.FAX_TIF_HOR_RES, ImageUtility.FAX_TIF_VER_RES_LOW, palette, pixelFormat); break; } } break; } } return(ret); }
/// <summary> /// Creates a padded Fax page. Source must be 1bpp. Returned bitmap is 1bpp. /// </summary> /// <param name="bmp"></param> /// <param name="quality"></param> /// <param name="paperSize"></param> /// <returns></returns> public static Bitmap CreateCopyFaxGeometryPadding(Bitmap bmp, FaxQuality quality, PaperSize paperSize) { PageInfo inf = new PageInfo(bmp); if (!(inf.GetStandardFaxQuality == quality)) { throw new Exception("Fax quality must match source."); } if (!(inf.PixelFormat != PixelFormat.Format1bppIndexed)) { throw new Exception("Source bitmap must have 1bppIndexed format."); } if (!(inf.GetStandardPaperSize == paperSize)) { return(BitmapHelper.CreateCopyExact(bmp)); } if (inf.GetStandardPaperSize == PaperSize.Legal && paperSize == PaperSize.Letter) { throw new Exception("Method cannnot reduce Paper size."); } Bitmap ret = BitmapHelper.CreateBitMap(paperSize, quality, PixelFormat.Format1bppIndexed); // Lock source bitmap in memory BitmapData sourceData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); // Copy image data to binary array int imageSize = sourceData.Stride * sourceData.Height; byte[] sourceBuffer = new byte[imageSize]; Marshal.Copy(sourceData.Scan0, sourceBuffer, 0, imageSize); // Unlock source bitmap bmp.UnlockBits(sourceData); // Lock destination bitmap in memory BitmapData destinationData = ret.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed); // Copy binary image data to destination bitmap Marshal.Copy(sourceBuffer, 0, destinationData.Scan0, imageSize); // Unlock destination bitmap ret.UnlockBits(destinationData); return(ret); }
private static PageImage CreateFaxTiff(PageImage page, PaperSize paperSize, FaxQuality faxQuality, ImageOperationResult result, bool fastTrack) { PageImage ret = new PageImage(); //FastTrack //if(page.PageInfo.IsStandardFaxTiff) if (fastTrack) { Trace.WriteLine("FastTracking tiff creation", MODNAME); return(CreateFaxTiffFastTrack(page, paperSize, faxQuality, result)); } else { Trace.WriteLine("SlowTracking tiff creation", MODNAME); return(CreateFaxTiffSlowTrack(page, paperSize, faxQuality, result)); } }
/// <summary> /// Creates a new Page image list from the given image object. Pages /// will be extracted into the Page image list if the source is multipage. /// </summary> /// <param name="image">The given image object.</param> /// <param name="quality"></param> /// <returns>A new Page Image List</returns> public static List <PageImage> LoadImage(Image image, FaxQuality quality) { List <PageImage> ret = new List <PageImage>(); FrameDimensionType frameDimTypeFlags = ImageHelper.GetFrameDimensionTypes(image.FrameDimensionsList); int pages = 0; //Get the Frame Dimensions if they exist if (FlagHelper.IsSet((int)frameDimTypeFlags, (int)FrameDimensionType.Page)) { pages = image.GetFrameCount(ImageHelper.FrameDimensionPage); } //Foreach frame make a PageInfo for (int i = 0; i < pages; i++) { image.SelectActiveFrame(ImageHelper.FrameDimensionPage, i); ret.Add(new PageImage((Bitmap)image)); } return(ret); }
/// <summary> /// Draws the given Bitmap into a new Bitmap that has the indicated fax geometry. Always returns /// 32bpp pixel format. /// </summary> /// <param name="bmp">The source bitmap.</param> /// <param name="quality">The Fax Quality. Default is Low.</param> /// <param name="paperSize">The Paper size. Default is Auto.</param> /// <param name="interpolationMode">The Interpolation mode. Default is High, but will use the current value in Image Utility, unless defined here. size.</param> /// <returns>The new PageImageList (always with 32bpp pixel format)</returns> internal static Bitmap CreateCopyFaxGeometry(Bitmap bmp, FaxQuality quality, PaperSize paperSize, InterpolationMode interpolationMode) { bool destroytemp = false; Bitmap tmp = null; Bitmap ret = null; if (bmp.PixelFormat == PixelFormat.Format8bppIndexed) { tmp = Convert8BppTo32Bpp(bmp); destroytemp = true; } else if (bmp.PixelFormat == PixelFormat.Format32bppArgb) { tmp = bmp; } else { tmp = BitmapHelper.CreateCopy32Bit(bmp); destroytemp = true; } //else if (bmp.PixelFormat != PixelFormat.Format32bppArgb) { tmp = bmp; } //else { tmp = BitmapHelper.CreateCopy32Bit(bmp); destroytemp = true; } ret = BitmapHelper.CreateBitMap(paperSize, quality, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(ret); g.InterpolationMode = interpolationMode; GraphicsUnit gu = GraphicsUnit.Pixel; g.DrawImage(tmp, ret.GetBounds(ref gu), tmp.GetBounds(ref gu), GraphicsUnit.Pixel); g.Dispose(); if (destroytemp) { tmp.Dispose(); } return(ret); }
internal static List <PageImage> ConvertToFaxablePageImageList(List <PageImage> pages, FaxQuality quality, PaperSize paperSize, ImageOperationResult result) { if (pages.Count == 0) { return(new List <PageImage>()); } FaxQuality targetquality = quality; PaperSize targetsize = ImageConverter.GetBestFitPaperSizeForList(pages, PaperSize.Auto); List <PageImage> ret = new List <PageImage>(); for (int i = 0; i < pages.Count; i++) { ret.Add(new PageImage()); } for (int i = 0; i < ret.Count; i++) { ret[i] = CreateFaxTiffSlowTrack(pages[i], targetsize, targetquality, result); } return(ret); }
/// <summary> /// Creates a Bitmap that will have the indicated pixel format, size and resolution /// </summary> /// <param name="paperSize">The required paper size</param> /// <param name="faxQuality">The required fax quality</param> /// <param name="pixelFormat">The needed pixel format</param> /// <returns>The new image with the correct settings.</returns> internal static Bitmap CreateBitMap(PaperSize paperSize, FaxQuality faxQuality, PixelFormat pixelFormat) { return(CreateBitMap(paperSize, faxQuality, null, pixelFormat)); }
private static PageImage CreateFaxTiffFastTrack(PageImage page, PaperSize paperSize, FaxQuality faxQuality, ImageOperationResult result) { PageInfo inf = null; PageImage ret = new PageImage(); Bitmap src = null; Bitmap destroy = null; src = BitmapHelper.CreateCopy1BppIndexed(page._sourceBmp); inf = new PageInfo(src); //If the size is not right copy to other size (padding or reducing) if (inf.GetStandardPaperSize != paperSize) { if (inf.GetStandardPaperSize == PaperSize.Legal && paperSize == PaperSize.Letter) { destroy = src; src = BitmapHelper.CreateCopyFaxGeometry(src, faxQuality, paperSize, ImageUtility.InterpolationMode); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); } if (inf.GetStandardPaperSize == PaperSize.Letter && paperSize == PaperSize.Legal) { destroy = src; src = BitmapHelper.CreateCopyFaxGeometryPadding(src, faxQuality, paperSize); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); } } //Make sure its 1bpp if (inf.PixelFormat != PixelFormat.Format1bppIndexed) { destroy = src; src = BitmapHelper.CreateCopy1BppIndexed(src); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); } //Reduce or increase quality as needed if (inf.GetStandardFaxQuality != faxQuality) { if (inf.GetStandardFaxQuality == FaxQuality.Fine && faxQuality == FaxQuality.Normal) { destroy = src; src = BitmapHelper.ConvertTiffHiToTiffLow(src, ImageUtility.HighToLowScaleMethod); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); } if (inf.GetStandardFaxQuality == FaxQuality.Normal && faxQuality == FaxQuality.Fine) { destroy = src; src = BitmapHelper.ConvertTiffLowToTiffHi(src); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); } } ret._pageInfo = null; ret._sourceBmp = src; return(ret); }
/// <summary> /// Creates a new PageImageList that contains empty images (no pixel data) with the /// appropriate PixelFormat, Size and Resolution. /// </summary> /// <param name="pageCount">Page count to get.</param> /// <param name="pixelFormat">The new pixel format.</param> /// <param name="quality">The fax quality to use (sets resolution)</param> /// <param name="paperSize">The page size to use (width and height)</param> /// <returns>The new page image list.</returns> private static List <PageImage> CreateEmptyPageImageList(int pageCount, PixelFormat pixelFormat, ColorPalette palette, FaxQuality quality, PaperSize paperSize) { List <PageImage> ret = new List <PageImage>(); //Get out if not pages in list. if (pageCount <= 0) { return(ret); } int width = ImageUtility.FAX_TIF_HOR_PX; float hres = ImageUtility.FAX_TIF_HOR_RES; int height = 0; float vres = 0.0F; if (quality == FaxQuality.Fine) { vres = ImageUtility.FAX_TIF_VER_RES_HI; if (paperSize == PaperSize.Legal) { height = ImageUtility.FAX_TIF_VER_PX_LGL_HI; } else { height = ImageUtility.FAX_TIF_VER_PX_LTR_HI; } } else { vres = ImageUtility.FAX_TIF_VER_RES_LOW; if (paperSize == PaperSize.Legal) { height = ImageUtility.FAX_TIF_VER_PX_LGL_LOW; } else { height = ImageUtility.FAX_TIF_VER_PX_LTR_LOW; } } for (int i = 0; i < pageCount; i++) { PageImage newpage = new PageImage(); newpage._sourceBmp = BitmapHelper.CreateBitMap(width, height, hres, vres, palette, pixelFormat); ret.Add(newpage); } return(ret); }
/// <summary> /// Saves the indicated Image object as a fax tiff at the outputFilePath location using the quality option specified with AutoPageSize /// </summary> /// <param name="img">The Image object to save.</param> /// <param name="quality">Tiff Normal or Fine</param> /// <param name="paperSize">Letter, Legal or Auto</param> /// <param name="outputFilePath">Fully qualified file name and path.</param> /// <returns></returns> public static ImageOperationResult SaveAsFaxTiff(Image img, string outputFilePath, FaxQuality quality = FaxQuality.Normal, PaperSize paperSize = PaperSize.Auto) { ImageOperationResult ret = new ImageOperationResult(); List <PageImage> pages = ImageUtility.LoadImage(img); ret = ImageUtility.InternalSaveAsFaxTiff(pages, quality, paperSize, outputFilePath); ImageUtility.Dispose(pages); return(ret); }
/// <summary> /// Saves the indicated Page Image List as a fax tiff at the outputFilePath location using the quality option specified with AutoPageSize /// </summary> /// <param name="pages">The Images to save.</param> /// <param name="quality">Tiff Normal or Fine</param> /// <param name="paperSize">Letter, Legal or Auto</param> /// <param name="outputFilePath">Fully qualified file name and path.</param> /// <returns></returns> internal static ImageOperationResult InternalSaveAsFaxTiff(List <PageImage> pages, FaxQuality quality, PaperSize paperSize, string outputFilePath) { ImageOperationResult result = new ImageOperationResult(); List <PageImage> newPages = ImageConverter.ConvertToFaxablePageImageList(pages, quality, paperSize, result); ImageUtility.SavePagesAsFaxTiffFile(newPages, outputFilePath); result.Pages = newPages.Count; ImageUtility.Dispose(newPages); return(result); }
/// <summary> /// Creates a new PageImageList containing pages that have a fax geometry. /// </summary> /// <param name="pages">The PageImageList to alter.</param> /// <param name="quality">The Fax Quality. Default is Low.</param> /// <returns>The new PageImageList (always with 32bpp pixel format)</returns> private static List <PageImage> ConvertToFaxGeometry(List <PageImage> pages, FaxQuality quality = FaxQuality.Normal) { return(ImageConverter.ConvertToFaxGeometry(pages, quality, ImageConverter.GetBestFitPaperSizeForList(pages, PaperSize.Auto))); }
/// <summary> /// Creates a new Page image list from the given Bitmap object. Pages /// will be extracted into the Page image list if the source is multipage. /// </summary> /// <param name="bmp">The given Bitmap object.</param> /// <param name="quality"></param> /// <returns>A new Page Image List</returns> public static List <PageImage> LoadImage(Bitmap bmp, FaxQuality quality) { return(ImageUtility.LoadImage((Image)bmp)); }
private static PageImage CreateFaxTiffSlowTrack(PageImage page, PaperSize paperSize, FaxQuality faxQuality, ImageOperationResult result) { PageInfo inf = null; PageImage ret = new PageImage(); Bitmap src = null; Bitmap destroy = null; Trace.WriteLine("SlowTrack: CreateCopyExact...", MODNAME); src = BitmapHelper.CreateCopyExact(page._sourceBmp); Trace.WriteLine("SlowTrack: CreateCopyExact done.", MODNAME); inf = new PageInfo(src); if (inf.GetBestFitRotation != 0) { Trace.WriteLine("SlowTrack: Rotating...", MODNAME); destroy = src; src = BitmapHelper.CreateCopyRotate(src, 90); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); Trace.WriteLine("SlowTrack: Rotating done.", MODNAME); } destroy = src; Trace.WriteLine("SlowTrack: CreateCopyFaxGeometry...", MODNAME); src = BitmapHelper.CreateCopyFaxGeometry(src, faxQuality, paperSize, ImageUtility.InterpolationMode); Trace.WriteLine("SlowTrack: CreateCopyFaxGeometry done.", MODNAME); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); destroy = src; Trace.WriteLine("SlowTrack: CreateCopy1BppIndexed: " + ImageUtility.ConvertTo1BppMethod.ToString() + "...", MODNAME); src = BitmapHelper.CreateCopy1BppIndexed(src); Trace.WriteLine("SlowTrack: CreateCopy1BppIndexed done.", MODNAME); if (destroy != null) { destroy.Dispose(); destroy = null; } inf = new PageInfo(src); ret._pageInfo = null; ret._sourceBmp = src; return(ret); }
public static List <PageImage> ConvertToFaxPageImageList(List <PageImage> pages, FaxQuality quality, PaperSize paperSize) { ImageOperationResult result = new ImageOperationResult(); return(ImageConverter.ConvertToFaxablePageImageList(pages, quality, paperSize, result)); }
public static ImageOperationResult VerifyAllTiffFilesAndWriteFaxTiff(string[] inputFilePaths, string outputFilePath, PaperSize paperSize, FaxQuality faxQuality) { ImageOperationResult ret = new ImageOperationResult(); List <PageImage> pages = ImageUtility.LoadImage(inputFilePaths, false); List <PageImage> newpages = ImageConverter.CreateFaxTiff(pages, paperSize, faxQuality, ret); ImageUtility.Dispose(pages); ImageUtility.SavePagesAsFaxTiffFile(newpages, outputFilePath); ret.Pages = newpages.Count; ImageUtility.Dispose(newpages); return(ret); }
public static ImageOperationResult VerifyAllTiffFilesAndWriteFaxTiff(string inputFilePath, string outputFilePath, PaperSize paperSize, FaxQuality faxQuality) { return(ImageUtility.VerifyAllTiffFilesAndWriteFaxTiff(new string[] { inputFilePath }, outputFilePath, paperSize, faxQuality)); }
/// <summary> /// Creates a new PageImageList containing pages that have a fax geometry. /// </summary> /// <param name="pages">The PageImageList to alter.</param> /// <param name="quality">The Fax Quality. Default is Low.</param> /// <param name="paperSize">The Paper size. Default is Auto.</param> /// <returns>The new PageImageList (always with 32bpp pixel format)</returns> private static List <PageImage> ConvertToFaxGeometry(List <PageImage> pages, FaxQuality quality, PaperSize paperSize) { return(ImageConverter.ConvertToFaxGeometry(pages, quality, paperSize, ImageUtility.InterpolationMode)); }
/// <summary> /// Receives a page image list and returns a faxable page image list. /// </summary> /// <param name="pages"></param> /// <param name="paperSize"></param> /// <param name="faxQuality"></param> /// <param name="result"></param> /// <returns></returns> internal static List <PageImage> CreateFaxTiff(List <PageImage> pages, PaperSize paperSize, FaxQuality faxQuality, ImageOperationResult result) { paperSize = ImageConverter.GetBestFitPaperSizeForList(pages, paperSize); if (faxQuality == FaxQuality.Default) { faxQuality = FaxQuality.Normal; } if (faxQuality == FaxQuality.Undefined) { faxQuality = FaxQuality.Normal; } bool fastTrack = CanFastTrackPageImageList(pages, paperSize); List <PageImage> ret = new List <PageImage>(); for (int i = 0; i < pages.Count; i++) { ret.Add(CreateFaxTiff(pages[i], paperSize, faxQuality, result, fastTrack)); } return(ret); }
/// <summary> /// Saves the indicated Page Image as a fax tiff at the outputFilePath location using the quality option specified with AutoPageSize /// </summary> /// <param name="page">The Image to save.</param> /// <param name="quality">Tiff Normal or Fine</param> /// <param name="paperSize">Letter, Legal or Auto</param> /// <param name="outputFilePath">Fully qualified file name and path.</param> /// <returns></returns> public static ImageOperationResult SaveAsFaxTiff(PageImage page, string outputFilePath, FaxQuality quality = FaxQuality.Normal, PaperSize paperSize = PaperSize.Auto) { ImageOperationResult ret = new ImageOperationResult(); ret = ImageUtility.InternalSaveAsFaxTiff(new List <PageImage>() { page }, quality, paperSize, outputFilePath); return(ret); }