Beispiel #1
0
        public Image GetThumbNail(string fileName, int imgWidth, int imgHeight, Color penColor)
        {
            bool   hasError        = false;
            string previewFileName = m_LastPreviewForlder + Path.GetFileNameWithoutExtension(fileName) + ".bmp";
            Bitmap bmp             = null;

            try
            {
                if (File.Exists(previewFileName))
                {
                    bmp = new Bitmap(previewFileName);
                }
                else
                {
                    if (File.Exists(fileName))
                    {
                        SPrtFileInfo jobInfo     = new SPrtFileInfo();
                        IntPtr       imgadataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SPrtImagePreview)));
                        jobInfo.sImageInfo.nImageData = imgadataPtr;
                        int bret = CoreInterface.Printer_GetFileInfo(fileName, ref jobInfo, 1);
                        if (bret == 1)
                        {
                            bmp = SerialFunction.CreateImageWithImageInfo(jobInfo.sImageInfo);
                            if (!Directory.Exists(m_LastPreviewForlder))
                            {
                                Directory.CreateDirectory(m_LastPreviewForlder);
                            }
                            bmp.Save(previewFileName);
                        }
                        else
                        {
                            hasError = true;
                        }
                        Marshal.FreeHGlobal(imgadataPtr);
                    }
                }
            }
            catch (Exception ex)
            {
                hasError = true;
                System.Diagnostics.Debug.Assert(true, ex.Message + ex.StackTrace);
            }
            if (bmp == null || hasError)
            {
                bmp = this.CreatDefaultBmp("¼ÓÔØʧ°Ü!!", Color.Wheat, Color.Red);
            }

            Bitmap retBmp = this.CreatDefaultBmp(bmp, penColor, Color.Black);

            return(retBmp);
        }
Beispiel #2
0
        public Image GetThumbNail(string fileName, int imgWidth, int imgHeight, Color penColor)
        {
            bool   hasError        = false;
            string previewFileName = m_LastPreviewForlder + Path.GetFileNameWithoutExtension(fileName) + ".bmp";
            Bitmap bmp             = null;

            try
            {
                if (File.Exists(previewFileName))
                {
                    bmp = new Bitmap(previewFileName);
                }
                else
                {
                    if (File.Exists(fileName))
                    {
                        SPrtFileInfo jobInfo = new SPrtFileInfo();
                        Int32        bret    = 0;
                        bret = CoreInterface.Printer_GetFileInfo(fileName, ref jobInfo, 1);
                        if (bret == 1)
                        {
                            bmp = SerialFunction.CreateImageWithImageInfo(jobInfo.sImageInfo);
                        }
                        else
                        {
                            hasError = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                hasError = true;
                System.Diagnostics.Debug.Assert(true, ex.Message + ex.StackTrace);
            }
            if (bmp == null || hasError)
            {
                bmp = this.CreatDefaultBmp("¼ÓÔØʧ°Ü!!", Color.Wheat, Color.Red);
            }
            else if (!File.Exists(previewFileName))
            {
                bmp.Save(previewFileName);
            }

            Bitmap retBmp = this.CreatDefaultBmp(bmp, penColor, Color.Black);

            return(retBmp);
        }
Beispiel #3
0
        public Bitmap CreateClipsMiniature()
        {
            string text = GetRealNoteText(this);

            float CoefficientX, CoefficientY;
            int   marginl, marginr, margint, marginb;
            int   xdis, xdis2, ydis;
            int   left, top, notemargin;

            string fpath = this.src;

            if (string.IsNullOrEmpty(fpath))
            {
                fpath = this.TopSrc;
            }

            Image srcMiniature = null;

            if (File.Exists(SrcMiniature))
            {
                srcMiniature = new Bitmap(SrcMiniature);
            }
            if (srcMiniature == null)
            {
                SPrtFileInfo jobInfo     = new SPrtFileInfo();
                IntPtr       imgadataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SPrtImagePreview)));
                jobInfo.sImageInfo.nImageData = imgadataPtr;
                int bret = CoreInterface.Printer_GetFileInfo(fpath, ref this.PrtFileInfo, 1);
                srcMiniature = SerialFunction.CreateImageWithImageInfo(this.PrtFileInfo.sImageInfo);
                Marshal.FreeHGlobal(imgadataPtr);
            }

            CoefficientX = (float)PrtFileInfo.sImageInfo.nImageWidth / srcMiniature.Width;
            CoefficientY = (float)PrtFileInfo.sImageInfo.nImageHeight / srcMiniature.Height;
            Rectangle scaledclip = new Rectangle();

            if (noClip)
            {
                scaledclip = new Rectangle(0, 0, srcMiniature.Width, srcMiniature.Height);
            }
            else
            {
                scaledclip = new Rectangle(Convert.ToInt32(this.ClipRect.Left / CoefficientX), Convert.ToInt32(this.ClipRect.Top / CoefficientY),
                                           Convert.ToInt32(this.ClipRect.Width / CoefficientX), Convert.ToInt32(this.ClipRect.Height / CoefficientY));
            }
            marginl = Convert.ToInt32(Margin_L / CoefficientX);
            marginr = Convert.ToInt32(Margin_R / CoefficientX);
            margint = Convert.ToInt32(Margin_T / CoefficientY);
            marginb = Convert.ToInt32(Margin_B / CoefficientY);
            xdis    = Convert.ToInt32(XDis / CoefficientX);
            xdis2   = Convert.ToInt32(XDis2 / CoefficientX);
            ydis    = Convert.ToInt32(YDis / CoefficientY);
            left    = Convert.ToInt32(Left / CoefficientX);
            top     = Convert.ToInt32(Top / CoefficientY);
            if (this.NotePosition == 0 || this.NotePosition == 2)
            {
                notemargin = Convert.ToInt32(NoteMargin / CoefficientX);
            }
            else
            {
                notemargin = Convert.ToInt32(NoteMargin / CoefficientY);
            }
            Rectangle size = GetBound(this);

            int   maxSize        = 600 * 800 * 3;// 单个预览图最大尺寸
            float dstCoefficient = 1;

            if (size.Width / CoefficientX * size.Height / CoefficientY > maxSize)
            {
                dstCoefficient = (float)Math.Sqrt((size.Width / CoefficientX * size.Height / CoefficientY) / maxSize);
                dstCoefficient = Math.Min(20, dstCoefficient); // dstCoefficient最大不超过20
            }
            size.Width  = (int)Math.Max(1, (float)size.Width / dstCoefficient);
            size.Height = (int)Math.Max(1, (float)size.Height / dstCoefficient);
            Bitmap   ret = null;
            Graphics g;

            try
            {
                ret = new Bitmap(Math.Max(1, Convert.ToInt32(size.Width / CoefficientX)), Math.Max(1, Convert.ToInt32(size.Height / CoefficientY)));
                g   = Graphics.FromImage(ret);

                if (isSimpleMode)
                {
                    int w          = (int)(scaledclip.Width / dstCoefficient);
                    int h          = (int)(scaledclip.Height / dstCoefficient);
                    int marginlInt = (int)(marginl / dstCoefficient);
                    int margintInt = (int)(margint / dstCoefficient);
                    int xdisInt    = (int)(xdis / dstCoefficient);
                    int xdis2Int   = (int)(xdis2 / dstCoefficient);
                    int ydisInt    = (int)(ydis / dstCoefficient);
                    for (int i = 0; i < this.XCnt; i++)
                    {
                        int left1 = marginlInt + i * (w + xdisInt);
                        if (IsNktTreeTileMode && i == 2)
                        {
                            left1 = marginlInt + (w + xdisInt) + (w + xdis2Int);
                        }
                        int top1 = 0;
                        for (int j = 0; j < this.YCnt; j++)
                        {
                            top1 = margintInt + j * (h + ydisInt);
                            Rectangle dstrect = new Rectangle(left1, top1, w, h);
                            g.DrawImage(srcMiniature, dstrect, scaledclip, GraphicsUnit.Pixel);
                            Debug.WriteLine("====CreateClipsMiniature===" + dstrect.ToString());
                        }
                        if (YAddtion > 0)
                        {
                            top1 += this.YCnt > 0 ?(h + ydisInt):0;
                            Rectangle scaledclip1 = new Rectangle();
                            if (noClip)
                            {
                                scaledclip1 = new Rectangle(0, 0, srcMiniature.Width, srcMiniature.Height);
                            }
                            else
                            {
                                scaledclip1 = new Rectangle(Convert.ToInt32(this.ClipRect.Left / CoefficientX), Convert.ToInt32(this.ClipRect.Top / CoefficientY),
                                                            Convert.ToInt32(this.ClipRect.Width / CoefficientX), Convert.ToInt32(this.YAddtion / CoefficientY));
                            }
                            Rectangle dstrect = new Rectangle(left1, top1, w, h);
                            g.DrawImage(srcMiniature, dstrect, scaledclip1, GraphicsUnit.Pixel);
                        }
                    }
                    if (text != null && text != string.Empty)
                    {
                        int notetop = margint + YCnt * (scaledclip.Height + ydis) + this.YAddtion - ydis + notemargin;
                        notetop = (int)(notetop / dstCoefficient);
                        Rectangle nrect = new Rectangle(marginl, 0, ret.Width - marginl - marginr, ret.Height - marginb - notetop);
                        if (nrect.Size.Width != 0 && nrect.Size.Height != 0)
                        {
                            Font      prevewFont = this.GetNoteFont();
                            Bitmap    bmp        = GetPreviewNoteImage(nrect, size.Width, text, prevewFont, this.NotePosition == 0 || this.NotePosition == 2);
                            Rectangle dstrect    = new Rectangle(marginlInt, (int)(ret.Height - marginb - bmp.Height), (int)(bmp.Width / dstCoefficient), (int)(bmp.Height / dstCoefficient));
                            g.DrawImage(bmp, dstrect, new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                        }
                        else
                        {
                            this.CreatNoteImage(size.Width, text, this.GetNoteFont(), this.NotePosition == 0 || this.NotePosition == 2);
                        }
                    }
                }
                else
                {
                    if (IsParent)
                    {
                        for (int i = 0; i < this.Childs.Length; i++)
                        {
                            Bitmap     bmp     = this.Childs[i].CreateClipsMiniature();
                            RectangleF dstrect = new RectangleF(left / dstCoefficient, top / dstCoefficient, bmp.Width / dstCoefficient, bmp.Height / dstCoefficient);
                            g.DrawImage(bmp, dstrect, new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                        }
                    }
                    else
                    {
                        RectangleF dstrect = new RectangleF(marginl / dstCoefficient, margint / dstCoefficient, scaledclip.Width / dstCoefficient, scaledclip.Height / dstCoefficient);
                        g.DrawImage(srcMiniature, dstrect, scaledclip, GraphicsUnit.Pixel);
                        if (text != null && text != string.Empty)
                        {
                            int       notetop = margint + YCnt * (scaledclip.Height + ydis) - ydis + notemargin;
                            Rectangle nrect   = new Rectangle(marginl, notetop, ret.Width - marginl - marginr, ret.Height - marginb - notetop);
                            Bitmap    bmp     = GetPreviewNoteImage(nrect, size.Width, text, this.GetNoteFont(), this.NotePosition == 0 || this.NotePosition == 2);
                            dstrect = new RectangleF(marginl / dstCoefficient, (margint + scaledclip.Height + notemargin) / dstCoefficient, bmp.Width / dstCoefficient, bmp.Height / dstCoefficient);
                            g.DrawImage(bmp, dstrect, new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                        }
                    }
                }
                g.Dispose();
                srcMiniature.Dispose();
                //GC.Collect();
            }
            catch (Exception ex)
            {
                ret = null;
                Debug.Assert(false, ex.Message + ex.StackTrace);
            }
            return(ret);
        }