예제 #1
0
파일: gdizi.cs 프로젝트: skyclub66/HMI
        public static zibmtype getzibmtype(Bitmap bm)
        {
            zibmtype zibmtype = default(zibmtype);

            zibmtype.ziwidth  = 0;
            zibmtype.ziheight = 0;
            zibmtype.xfree    = gdizi.getxfree(bm);
            zibmtype result;

            if (zibmtype.xfree == bm.Width)
            {
                result = zibmtype;
            }
            else
            {
                zibmtype.yfree    = gdizi.getyfree(bm);
                zibmtype.x2free   = gdizi.getx2free(bm);
                zibmtype.y2free   = gdizi.gety2free(bm);
                zibmtype.ziwidth  = bm.Width - zibmtype.xfree - zibmtype.x2free;
                zibmtype.ziheight = bm.Height - zibmtype.yfree - zibmtype.y2free;
                if (zibmtype.ziwidth < 0)
                {
                    zibmtype.ziwidth = 0;
                }
                if (zibmtype.ziheight < 0)
                {
                    zibmtype.ziheight = 0;
                }
                result = zibmtype;
            }
            return(result);
        }
예제 #2
0
파일: gdizi.cs 프로젝트: skyclub66/HMI
        public static void bmpprintstr(Bitmap bm, string str, showzitype_ zipos, int maxwidth, int maxheight, bool istiaozheng)
        {
            gdizi.measureStringFormat.LineAlignment = StringAlignment.Near;
            gdizi.measureStringFormat.FormatFlags   = (StringFormatFlags.FitBlackBox | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
            Graphics graphics = Graphics.FromImage(bm);

            graphics.Clear(Color.FromArgb(0, 0, 0));
            if (zipos.zisize < 2f)
            {
                graphics.Dispose();
            }
            else if (istiaozheng)
            {
                Bitmap bitmap = new Bitmap(maxwidth * 3 / 2, maxheight * 3 / 2);
                graphics = Graphics.FromImage(bitmap);
                graphics.Clear(Color.FromArgb(0, 0, 0));
                Font font = new Font(zipos.ziti, zipos.zisize, zipos.fonstyl);
                graphics.DrawString(str, font, Brushes.Red, new Point(zipos.xpianyi, zipos.ypianyi), gdizi.measureStringFormat);
                zibmtype zibmtype = gdizi.getzibmtype(bitmap);
                int      x        = 0;
                int      y        = 0;
                if (zibmtype.ziwidth > 0)
                {
                    if (zibmtype.xfree + zibmtype.ziwidth + zipos.yuliang / 2 > maxwidth + 1)
                    {
                        if (zibmtype.ziwidth + zipos.yuliang / 2 <= maxwidth)
                        {
                            x = zibmtype.xfree + zibmtype.ziwidth - maxwidth + zipos.yuliang / 2;
                        }
                        else
                        {
                            int y2free = zibmtype.y2free;
                            zipos.zisize -= 0.5f;
                            graphics.Clear(Color.FromArgb(0, 0, 0));
                            font = new Font(zipos.ziti, zipos.zisize, zipos.fonstyl);
                            graphics.DrawString(str, font, Brushes.Red, new Point(zipos.xpianyi, zipos.ypianyi), gdizi.measureStringFormat);
                            zibmtype = gdizi.getzibmtype(bitmap);
                            while (zibmtype.ziwidth + zipos.yuliang / 2 > maxwidth)
                            {
                                zipos.zisize -= 0.5f;
                                if (zipos.zisize < (float)(maxheight / 4) || zipos.zisize > (float)(maxheight * 3 / 2))
                                {
                                    graphics.Dispose();
                                    bitmap.Dispose();
                                    return;
                                }
                                graphics.Clear(Color.FromArgb(0, 0, 0));
                                font = new Font(zipos.ziti, zipos.zisize, zipos.fonstyl);
                                graphics.DrawString(str, font, Brushes.Red, new Point(zipos.xpianyi, zipos.ypianyi), gdizi.measureStringFormat);
                                zibmtype = gdizi.getzibmtype(bitmap);
                            }
                            y = (zibmtype.y2free - y2free) * -1;
                            if (zibmtype.xfree + zibmtype.ziwidth + zipos.yuliang / 2 > maxwidth + 1)
                            {
                                x = zibmtype.xfree + zibmtype.ziwidth - maxwidth + zipos.yuliang / 2;
                            }
                        }
                    }
                    if (zibmtype.yfree + zibmtype.ziheight + zipos.yuliang / 2 > maxheight + 1)
                    {
                        if (zibmtype.ziheight + zipos.yuliang / 2 <= maxheight)
                        {
                            y = zibmtype.yfree + zibmtype.ziheight - maxheight + zipos.yuliang / 2;
                        }
                    }
                }
                graphics = Graphics.FromImage(bm);
                graphics.Clear(Color.FromArgb(0, 0, 0));
                graphics.DrawImage(bitmap, new Rectangle(0, 0, maxwidth, maxheight), new Rectangle(x, y, maxwidth, maxheight), GraphicsUnit.Pixel);
                graphics.Dispose();
                bitmap.Dispose();
            }
            else
            {
                graphics = Graphics.FromImage(bm);
                graphics.Clear(Color.FromArgb(0, 0, 0));
                Font font = new Font(zipos.ziti, zipos.zisize, zipos.fonstyl);
                graphics.DrawString(str, font, Brushes.Red, new Point(zipos.xpianyi, zipos.ypianyi), gdizi.measureStringFormat);
                graphics.Dispose();
            }
        }
예제 #3
0
파일: gdizi.cs 프로젝트: skyclub66/HMI
        public static showzitype_ Getzipos(string str, showzitype_ zipos, int width, int height, PictureBox pic)
        {
            gdizi.measureStringFormat.LineAlignment = StringAlignment.Near;
            gdizi.measureStringFormat.FormatFlags   = (StringFormatFlags.FitBlackBox | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
            showzitype_ showzitype_ = zipos;
            int         num         = width - showzitype_.yuliang;
            int         num2        = height - showzitype_.yuliang;
            showzitype_ result;

            if (str == "" || num < 2 || num2 < 2)
            {
                showzitype_.zisize = 1f;
                result             = showzitype_;
            }
            else
            {
                if (showzitype_.zisize < (float)(height / 4) || showzitype_.zisize > (float)(height * 3 / 2))
                {
                    showzitype_.zisize = (float)height;
                }
                showzitype_ = gdizi.GetGraphicszipos(str, showzitype_, num, num2);
                if (showzitype_.zisize < 2f)
                {
                    result = showzitype_;
                }
                else
                {
                    Bitmap bitmap;
                    if (height > width)
                    {
                        bitmap = new Bitmap(height * 2, height * 2);
                    }
                    else
                    {
                        bitmap = new Bitmap(width * 2, width * 2);
                    }
                    gdizi.gc = Graphics.FromImage(bitmap);
                    float num3 = 0.5f;
                    if (height > 56)
                    {
                        num3 = 1f;
                    }
                    gdizi.gc.Clear(Color.FromArgb(0, 0, 0));
                    gdizi.font1 = new Font(showzitype_.ziti, showzitype_.zisize, showzitype_.fonstyl);
                    gdizi.gc.DrawString(str, gdizi.font1, Brushes.Red, new Point(1, 1), gdizi.measureStringFormat);
                    zibmtype zibmtype = gdizi.getzibmtype(bitmap);
                    if (zibmtype.ziwidth == 0)
                    {
                        result = showzitype_;
                    }
                    else
                    {
                        while (num - zibmtype.ziwidth > 1 && num2 - zibmtype.ziheight > 1)
                        {
                            if (num - zibmtype.ziwidth < num2 - zibmtype.ziheight)
                            {
                                if (num - zibmtype.ziwidth > 4)
                                {
                                    showzitype_.zisize += (float)((num - zibmtype.ziwidth) / 2);
                                }
                                else
                                {
                                    showzitype_.zisize += num3;
                                }
                            }
                            else if (num2 - zibmtype.ziheight > 4)
                            {
                                showzitype_.zisize += (float)((num2 - zibmtype.ziheight) / 2);
                            }
                            else
                            {
                                showzitype_.zisize += num3;
                            }
                            gdizi.gc.Clear(Color.FromArgb(0, 0, 0));
                            gdizi.font1 = new Font(showzitype_.ziti, showzitype_.zisize, showzitype_.fonstyl);
                            gdizi.gc.DrawString(str, gdizi.font1, Brushes.Red, new Point(1, 1), gdizi.measureStringFormat);
                            zibmtype = gdizi.getzibmtype(bitmap);
                            if (pic != null)
                            {
                                pic.Image = bitmap;
                                Application.DoEvents();
                            }
                        }
                        while (zibmtype.ziwidth > num || zibmtype.ziheight > num2)
                        {
                            showzitype_.zisize -= num3;
                            gdizi.gc.Clear(Color.FromArgb(0, 0, 0));
                            gdizi.font1 = new Font(showzitype_.ziti, showzitype_.zisize, showzitype_.fonstyl);
                            gdizi.gc.DrawString(str, gdizi.font1, Brushes.Red, new Point(1, 1), gdizi.measureStringFormat);
                            zibmtype = gdizi.getzibmtype(bitmap);
                        }
                        showzitype_.zhanyongwidth  = zibmtype.ziwidth;
                        showzitype_.zhanyongheight = zibmtype.ziheight;
                        showzitype_.xpianyi        = 1 + (width - showzitype_.zhanyongwidth - zibmtype.xfree - zibmtype.xfree) / 2;
                        showzitype_.ypianyi        = 1 + (height - showzitype_.zhanyongheight - zibmtype.yfree - zibmtype.yfree) / 2;
                        gdizi.gc.Dispose();
                        bitmap.Dispose();
                        result = showzitype_;
                    }
                }
            }
            return(result);
        }