Exemplo n.º 1
0
        static public void ConvertToImage(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.OpenDocFromStringPath(Parent);
            }

            IIXC_Inst  ixcInst = Parent.m_pxcInst.GetExtension("IXC");
            IAUX_Inst  auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_Pages pages   = Parent.m_CurDoc.Pages;
            IPXC_Page  Page    = pages[Parent.CurrentPage];
            double     nHeight = 0.0;
            double     nWidth  = 0.0;

            Page.GetDimension(out nWidth, out nHeight);
            uint                  cx      = (uint)(nWidth * 150 / 72.0);
            uint                  cy      = (uint)(nHeight * 150 / 72.0);
            IIXC_Page             ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8ARGB, 0);
            IPXC_PageRenderParams param   = Parent.m_pxcInst.CreateRenderParams();

            if (param != null)
            {
                param.RenderFlags |= ((uint)PXC_RenderFlags.RF_SmoothImages | (uint)PXC_RenderFlags.RF_SmoothLineArts);
                param.SetColor(PXC_RenderColor.RC_PageColor1, 255, 255, 255, 0);
                param.TextSmoothMode |= PXC_TextSmoothMode.TSM_Antialias;
            }
            tagRECT rc = new tagRECT();

            rc.right  = (int)cx;
            rc.bottom = (int)cy;
            PXC_Matrix matrix = Page.GetMatrix(PXC_BoxType.PBox_PageBox);

            matrix = auxInst.MathHelper.Matrix_Scale(ref matrix, cx / nWidth, -cy / nHeight);
            matrix = auxInst.MathHelper.Matrix_Translate(ref matrix, 0, cy);
            Page.DrawToIXCPage(ixcPage, ref rc, ref matrix, param);
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_XDPI]       = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YDPI]       = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_INTERLACE]  = 1;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FILTER]     = 5;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_COMP_LEVEL] = 5;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FORMAT]     = (uint)IXC_ImageFileFormatIDs.FMT_PNG_ID;
            IIXC_Image ixcImg = ixcInst.CreateEmptyImage();

            ixcImg.InsertPage(ixcPage, 0);
            string sPath = Path.GetTempFileName();

            sPath = sPath.Replace(".tmp", ".png");
            ixcImg.Save(sPath, IXC_CreationDisposition.CreationDisposition_Overwrite);
            Process.Start(sPath);

            ixcImg.RemovePageByIndex(0);
            ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8Gray, 0);
            if (param != null)
            {
                param.SetColor(PXC_RenderColor.RC_PageColor1, 255, 255, 255, 255);
            }
            Page.DrawToIXCPage(ixcPage, ref rc, ref matrix, param);
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_XDPI]         = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YDPI]         = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YSUBSAMPLING] = 20;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FORMAT]       = (uint)IXC_ImageFileFormatIDs.FMT_JPEG_ID;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_JPEG_QUALITY] = 100;
            ixcImg.InsertPage(ixcPage, 0);
            sPath = sPath.Replace(".png", ".jpg");
            ixcImg.Save(sPath, IXC_CreationDisposition.CreationDisposition_Overwrite);
            Process.Start(sPath);
            Marshal.ReleaseComObject(Page);

            ixcImg.RemovePageByIndex(0);
            ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8RGB, 0);
            for (int i = 0; i < pages.Count; i++)
            {
                Page = pages[(uint)i];
                Page.DrawToIXCPage(ixcPage, ref rc, ref matrix, param);
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_XDPI]   = 150;
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YDPI]   = 150;
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_ITYPE]  = 1;
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FORMAT] = (uint)IXC_ImageFileFormatIDs.FMT_TIFF_ID;
                ixcImg.InsertPage(ixcPage);
                ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8Gray, 0);
                Marshal.ReleaseComObject(Page);
            }
            sPath = sPath.Replace(".jpg", ".tiff");
            ixcImg.Save(sPath, IXC_CreationDisposition.CreationDisposition_Overwrite);
            Process.Start(sPath);


            Marshal.ReleaseComObject(pages);
        }