Пример #1
0
        private void changeImageToLabware(PictureBox pictodraw)
        {
            pictodraw.Image = Properties.Resources.Panel;
            pictodraw.Refresh();
            Bitmap bitmap = new Bitmap(pictodraw.Width, pictodraw.Height);

            pictodraw.DrawToBitmap(bitmap, pictodraw.ClientRectangle);
            Graphics g = Graphics.FromImage(bitmap);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            string text  = this.selectedLabware;
            int    count = text.Count();

            if (count > 20)
            {
                text = text.Substring(0, 20);
            }
            SizeF textSize = g.MeasureString(text, Font);
            int   d        = 1;
            Font  bestfit  = new Font(SystemFonts.DefaultFont.FontFamily, 8, FontStyle.Regular);

            while (true)
            {
                if (textSize.Width > bitmap.Width)
                {
                    bestfit  = new Font(SystemFonts.DefaultFont.FontFamily, 8 - d, FontStyle.Regular);
                    textSize = g.MeasureString(text, bestfit);
                    d++;
                }
                else
                {
                    break;
                }
            }
            PointF locationToDraw = new PointF();

            locationToDraw.X = (bitmap.Width / 2) - (textSize.Width / 2);
            locationToDraw.Y = (bitmap.Height / 2) - (textSize.Height / 2);

            g.DrawString(text, bestfit, Brushes.Black, locationToDraw);
            pictodraw.Image = bitmap;
            g.Dispose();
            using (var bitmap1 = new Bitmap(pictodraw.Width, pictodraw.Height))
            {
                pictodraw.DrawToBitmap(bitmap1, pictodraw.ClientRectangle);
                string sourceDir = Path.Combine(Directory.GetCurrentDirectory(), "Resources\\" + pictodraw.Name + ".bmp");
                bitmap1.Save(sourceDir, ImageFormat.Bmp);
            }
        }
Пример #2
0
        private Tuple <bool, string> QRCodeSaveToFile(PictureBox pb)
        {
            Tuple <bool, string> tup;

            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName = "QRCode";
                sfd.Filter   = ".png|*.png|.jpg|*.jpg";

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    Bitmap bit = new Bitmap(pb.Width, pb.Height);
                    pb.DrawToBitmap(bit, pb.ClientRectangle);
                    bit.Save(sfd.FileName);
                    string path = sfd.FileName.ToString();
                    tup = new Tuple <bool, string>(true, path);
                    return(tup);
                }
                else
                {
                    tup = new Tuple <bool, string>(false, "");
                    return(tup);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public Bitmap SaveImage(PictureBox pictureBox1)
        {
            Bitmap SavedBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            pictureBox1.DrawToBitmap(SavedBitmap, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
            return(SavedBitmap);
        }
Пример #4
0
        public void ExportImage(string path)
        {
            using (var bitmap = new Bitmap(_pictureBox.Width, _pictureBox.Height))
            {
                _pictureBox.DrawToBitmap(bitmap, _pictureBox.ClientRectangle);
                ImageFormat imageFormat = null;

                var extension = Path.GetExtension(path);
                switch (extension)
                {
                case ".bmp":
                    imageFormat = ImageFormat.Bmp;
                    break;

                case ".png":
                    imageFormat = ImageFormat.Png;
                    break;

                case ".jpg":
                    imageFormat = ImageFormat.Jpeg;
                    break;

                case ".gif":
                    imageFormat = ImageFormat.Gif;
                    break;

                default:
                    break;
                }

                bitmap.Save(path, imageFormat);
            }
        }
Пример #5
0
        /// <summary>
        /// DATAGRIDVIEW跨越滚动截图
        /// </summary>
        /// <param name="_View">DataGridView</param>
        /// <returns>图形</returns>
        public Image DrawViewToImage(int times, float Ftimes)
        {
            Font      font    = this.Font;
            DockStyle ds      = this.Dock;
            bool      addRows = this.AllowUserToAddRows;
            DataGridViewAutoSizeColumnsMode dgvscm = this.AutoSizeColumnsMode;
            Color backcolor = this.DefaultCellStyle.BackColor;

            this.DefaultCellStyle.BackColor = Color.White;
            pictureBox.Paint += new PaintEventHandler(pictureBox_Paint);
            SizeF size = new SizeF(this.Size);

            this.AllowUserToAddRows = false;
            this.Dock           = DockStyle.None;
            pictureBox.Size     = this.Size;
            pictureBox.Location = this.Location;
            Bitmap thisBmp = new Bitmap(pictureBox.Width, pictureBox.Height);

            this.DrawToBitmap(thisBmp, new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
            pictureBox.Image = thisBmp;

            this.Visible = false;
            this.Font    = new Font("宋体", 9 * Ftimes, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
            System.Drawing.Rectangle rc = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            double widthScale           = (double)this.DefaultScaleWidth / (double)rc.Width;

            this.Size = new Size((int)(size.Width * widthScale), (int)(size.Height));
            this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            this.AutoSize            = true;

            int height = 0;

            for (int i = 0; i < this.Rows.Count; i++)
            {
                height += this.Rows[i].Height;
            }
            Bitmap _NewBitmap = new Bitmap((int)((this.Width) - 32), (int)(height + 5));

            this.DrawToBitmap(_NewBitmap, new System.Drawing.Rectangle(0, 0, this.Width, this.Height));
            pictureBox           = new PictureBox();
            pictureBox.Image     = _NewBitmap;
            pictureBox.Size      = new Size(_NewBitmap.Size.Width + 10, _NewBitmap.Size.Height + 5);// new Size((int)(this.Width * times), (int)(this.Height * times));
            pictureBox.SizeMode  = PictureBoxSizeMode.CenterImage;
            pictureBox.BackColor = Color.White;
            Bitmap newbitm = new Bitmap(pictureBox.Width, pictureBox.Height);

            pictureBox.DrawToBitmap(newbitm, new Rectangle(0, 0, pictureBox.Width, pictureBox.Height));

            this.AutoSize = false;
            this.Visible  = true;
            thisBmp.Dispose();
            //_NewBitmap.Dispose();
            //pictureBox.Dispose();
            this.AllowUserToAddRows = addRows;
            this.Font = font;
            this.Dock = ds;
            this.AutoSizeColumnsMode        = dgvscm;
            this.DefaultCellStyle.BackColor = backcolor;
            return(newbitm);
        }
Пример #6
0
 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button != MouseButtons.Left)
     {
         PictureBox _PictureBox = (PictureBox)sender;
         Bitmap     _Bitmap     = new Bitmap(_PictureBox.Width, _PictureBox.Height);
         _PictureBox.DrawToBitmap(_Bitmap, new Rectangle(0, 0, _PictureBox.Width, _PictureBox.Height));
         Color c = _Bitmap.GetPixel(e.X, e.Y);
         _Bitmap.Dispose();
         if (c.ToArgb() == _PictureBox.BackColor.ToArgb() || c.ToArgb() == Color.LightBlue.ToArgb())
         {
             contextMenuStrip1.Enabled = false;
             return;
         }
         contextMenuStrip1.Enabled = true;
         return;
     }
     if (bDrawStart)
     {
         bDrawStart = false;
     }
     else
     {
         bDrawStart = true;
         pointStart = e.Location;
     }
 }
Пример #7
0
        /**
         * @brief 현재 그려져 있는 객체 중에서 해당 그룹에 해당하는 객체만 저장하기 위해 오버로딩된 메서드이다.
         * @details view에 있는 pictureBox를 들고 와서 pictureBox를 Bitmap형식으로 저장한 다음에 객체만 저장하기 위해서 객체의 크기로 자른다. 자른 후에 PNG형식으로 저장한다.
         * @author 김효상
         * @date 2017-07-31
         * @param fileName 저장할 파일 이름
         * @param groupName 저장할 그룹 이름
         */
        public String SavePNG(string fileName, string groupName)
        {
            FigureList copyList = (FigureList)drawnFigures.Clone();

            drawnFigures.Clear();
            foreach (Figure figure in copyList)
            {
                if (figure.groupName.Equals(groupName))
                {
                    drawnFigures.Add(figure);
                }
            }
            UpdateAllViews();

            PictureBox ptemp = ((View)viewList[1]).getPictureBox();

            int W = ptemp.Width;
            int H = ptemp.Height;

            Bitmap temp = new Bitmap(W, H);

            ptemp.DrawToBitmap(temp, new Rectangle(0, 0, W, H));
            temp.MakeTransparent(Color.White);
            temp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            innerNeedSave = false;

            drawnFigures = copyList;
            UpdateAllViews();
            return(fileName);
        }
Пример #8
0
        public void ExportToBmp(PictureBox pictureBox, string path)
        {
            using (var bitmap = new Bitmap(pictureBox.Width, pictureBox.Height))
            {
                pictureBox.DrawToBitmap(bitmap, pictureBox.ClientRectangle);
                ImageFormat imageFormat = null;

                var extension = Path.GetExtension(path);
                switch (extension)
                {
                case ".bmp":
                    imageFormat = ImageFormat.Bmp;
                    break;

                case ".png":
                    imageFormat = ImageFormat.Png;
                    break;

                case ".jpeg":
                case ".jpg":
                    imageFormat = ImageFormat.Jpeg;
                    break;

                case ".gif":
                    imageFormat = ImageFormat.Gif;
                    break;

                default:
                    throw new NotSupportedException("File extension is not supported");
                }

                bitmap.Save(path, imageFormat);
            }
        }
        private void saveChangedImage()
        {
            SaveFileDialog saveImageDialog = new SaveFileDialog();

            saveImageDialog.Filter = "Png Image (.png)|*.png";
            saveImageDialog.Title  = "Save image as...";

            if (saveImageDialog.ShowDialog(this) == DialogResult.OK)
            {
                // gets name for saving
                string imageName = saveImageDialog.FileName;

                if (pb != null)
                {
                    Rectangle rect       = new Rectangle(0, 0, pb.Width, pb.Height);
                    Bitmap    dumpBitmap = new Bitmap(pb.Width, pb.Height);
                    pb.DrawToBitmap(dumpBitmap, rect);
                    dumpBitmap.Save(imageName, ImageFormat.Png);
                    // for testing purposes
                    MessageBox.Show("Saved to file: " + imageName);
                }
            }
            else
            {
                return;
            }
        }
Пример #10
0
        private void Insert()
        {
            int width  = pictureBox1.Size.Width;
            int height = pictureBox1.Size.Height;

            using (Bitmap bmp = new Bitmap(width, height))
            {
                pictureBox1.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));

                ImageConverter converter = new ImageConverter();
                SqlParameter[] param;
                param = new SqlParameter[4];
                int index = 0;

                //  param[index++] = new SqlParameter("@ID", Id);
                param[index++] = new SqlParameter("@Image", (byte[])converter.ConvertTo(bmp, typeof(byte[])));
                param[index++] = new SqlParameter("@NationalityCode", Id);
                param[index++] = new SqlParameter("@DateModified", DateTime.Now);
                param[index++] = new SqlParameter("@DocumentType", tabControl1.SelectedTab.Tag);
                if (Convert.ToInt32(da.ExecuteScalarSP("SetPrescription", param)) == 1)
                {
                    var msg = "ثبت با موفقیت انجام شد"; MessageForm.Show(msg, "ثبت", MessageFormIcons.Info, MessageFormButtons.Ok, Properties.Settings.Default.Color);
                    //  MessageBox.Show("ثبت با موفقیت انجام شد.");
                    FillDocumentsGrid();
                    //cmbDayOfWeek.Enabled = false; cmbShift.Enabled = false;
                }
                else
                {
                    var msg = "در روند ثبت خطایی رخ داده است."; MessageForm.Show(msg, "ثبت", MessageFormIcons.Warning, MessageFormButtons.Ok, Properties.Settings.Default.Color);

                    //  MessageBox.Show("در روند ثبت خطایی رخ داده است.");
                }
            }
        }
Пример #11
0
 private void сохранитьToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     if (FlowerPictureBox.Image != null)
     {
         sfd.OverwritePrompt = true;
         sfd.CheckPathExists = true;
         sfd.ShowHelp        = true;
         sfd.Filter          = "Image Files(*.BMP)|*.BMP|Image Files(*.JPG)|*.JPG";
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 FileInfo   fi    = new FileInfo(sfd.FileName);
                 string     text  = String.Format("Имя файла: {0}; Сторона квадрата: {1};", fi.Name, FlowerSideNumericUpDown.Value);
                 Brush      b     = new SolidBrush(Color.Gray);
                 PictureBox pbtmp = FlowerPictureBox;
                 Bitmap     bmp   = new Bitmap(pbtmp.Width, pbtmp.Height + 30);
                 pbtmp.DrawToBitmap(bmp, new Rectangle(0, 0, pbtmp.Width, pbtmp.Height));
                 Graphics G = Graphics.FromImage(bmp);
                 G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                 G.DrawString(text, Font, b, 20, bmp.Height - 30);
                 bmp.Save(sfd.FileName, ImageFormat.Jpeg);
             }
             catch
             {
                 MessageBox.Show("Невозможно сохранить изображение", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
        // Draws a grid on the map to visual show how the tiles will be cut up.
        private void DrawGrid()
        {
            pictureBox.DrawToBitmap(drawArea, pictureBox.Bounds);

            Graphics g;

            g = Graphics.FromImage(drawArea);

            g.Clear(Color.White);

            if (Spritesheet == null)
            {
                return;
            }

            g.DrawImage(Spritesheet.Image, 0, 0);

            Pen pen = new Pen(Brushes.Black);

            int height = pictureBox.Height;
            int width  = pictureBox.Width;

            for (int y = 0; y < height; y += Spritesheet.GridHeight + Spritesheet.Spacing)
            {
                g.DrawLine(pen, 0, y, width, y);
            }

            for (int x = 0; x < width; x += Spritesheet.GridWidth + Spritesheet.Spacing)
            {
                g.DrawLine(pen, x, 0, x, height);
            }
            g.Dispose();

            pictureBox.Image = drawArea;
        }
Пример #13
0
        private void printDocument1s_PrintPage(object sender, PrintPageEventArgs e)
        {
            pb1.Size     = new System.Drawing.Size(100, 100);
            pb1.SizeMode = PictureBoxSizeMode.StretchImage;
            Bitmap myBitmap1 = new Bitmap(100, 100);

            pb1.DrawToBitmap(myBitmap1, new Rectangle(0, 0, 100, 100));
            e.Graphics.DrawImage(myBitmap1, 75, 0);
        }
Пример #14
0
Файл: Form1.cs Проект: FtMan/ES
        void em_save_image_tree_button_click(object sender, EventArgs e)
        {
            var bitmap = new Bitmap(1500, 3000);

            editor_workspace.DrawToBitmap(bitmap, new Rectangle(0, 0, 1500, 3000));
            var imageFormat = System.Drawing.Imaging.ImageFormat.Png;

            bitmap.Save("TreeVisualization." + imageFormat.ToString(), imageFormat);
        }
Пример #15
0
        /// <summary>
        /// 获取pictureBox1指定的图像
        /// </summary>
        /// <param name="pictureBox1">需要获取的图像</param>
        /// <returns></returns>
        public Bitmap Capturegraph(PictureBox pictureBox1)
        {
            bitmap = new Bitmap(Width, Height);
            Bitmap bitmap1 = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            pictureBox1.DrawToBitmap(bitmap1, pictureBox1.ClientRectangle);
            Graphics g = Graphics.FromImage(bitmap);

            g.DrawImage(bitmap1, GetDestReg, GetOrigReg, GraphicsUnit.Pixel);
            return(bitmap);
        }
Пример #16
0
 private void toolStripButton13_Click(object sender, EventArgs e)
 {
     if (saveFileDialog2.ShowDialog() == DialogResult.OK)
     {
         Form       activeChild = this.ActiveMdiChild;
         PictureBox theBox      = (PictureBox)activeChild.Controls["pictureBox1"];
         Bitmap     drawing     = new Bitmap(theBox.Width, theBox.Height);
         theBox.DrawToBitmap(drawing, theBox.ClientRectangle);
         drawing.Save(openFileDialog2.FileName);
         //theBox.
     }
 }
Пример #17
0
 /* Draw content of picturebox to bitmap, and convert it to byte array. Later I use that list of byte arrays to generate animated GIF file. */
 public static void SaveFrame(ref List <byte[]> frames, PictureBox pictureBox)
 {
     using (var stream = new MemoryStream())
     {
         using (var bitmap = new Bitmap(pictureBox.Width, pictureBox.Height))
         {
             pictureBox.DrawToBitmap(bitmap, pictureBox.ClientRectangle);
             bitmap.Save(stream, ImageFormat.Gif);
             frames.Add(stream.ToArray());
         }
     }
 }
        public RadBitmapData Decode(Stream stream)
        {
            Metafile metaFile = new Metafile(stream);

            int   width       = metaFile.Width;
            int   height      = metaFile.Height;
            float scaleFactor = 1f;

            if (metaFile.Width > maxPixelSize ||
                metaFile.Height > maxPixelSize)
            {
                scaleFactor = Math.Max((float)metaFile.Width / (float)maxPixelSize, (float)metaFile.Height / (float)maxPixelSize);
                width       = (int)(width / scaleFactor);
                height      = (int)(height / scaleFactor);
            }

            // Create a PictureBox control and load the metafile
            PictureBox box = new PictureBox();

            box.Width     = width;
            box.Height    = height;
            box.BackColor = Color.White;
            box.SizeMode  = PictureBoxSizeMode.StretchImage;
            box.Image     = metaFile;

            // Create snapshot of the PictureBox and save it as a bitmap
            Bitmap bmp = new Bitmap(width, height);

            box.DrawToBitmap(bmp, new Rectangle(0, 0, width, height));

            //load the image in WPF
            RadBitmap     result = null;
            RadBitmapData data   = null;

            using (MemoryStream output = new MemoryStream())
            {
                BitmapImage image = new BitmapImage();

                image.BeginInit();
                bmp.Save(output, this.encoder, null);
                output.Seek(0, SeekOrigin.Begin);
                image.StreamSource = output;
                image.EndInit();

                result = new RadBitmap(image);
                data   = new RadBitmapData(result.Width, result.Height, result.GetPixels());
            }

            return(data);
        }
Пример #19
0
        private void CreatePicture(Sheet data)
        {
            PictureBox picture = new PictureBox();

            picture.Size = new Size((int)data.Width, (int)data.Height);
            foreach (var item in data.DrawingInDBs)
            {
                PictureBox pic = new PictureBox();
                pic.Location = new Point((int)item.PositionX, (int)item.PositionY);
                pic.Size     = new Size((int)item.Width, (int)item.Height);
                foreach (var line in item.LINESQLs)
                {
                    picture.Paint += (toSend, ev) =>
                    {
                        Point start = new Point(pic.Location.X * 2 + (int)line.StartX, pic.Location.Y * 2 + (int)line.StartY);
                        Point end   = new Point(pic.Location.X * 2 + (int)line.EndX, pic.Location.Y * 2 + (int)line.EndY);
                        Pen   p     = new Pen(Color.Black);
                        ev.Graphics.DrawLine(p, start, end);
                    };
                    //picture.Controls.Add(pic);
                }
            }
            Bitmap bitmap = new Bitmap(picture.Width, picture.Height);

            picture.DrawToBitmap(bitmap, picture.ClientRectangle);
            PictureBox addPic = new PictureBox();

            addPic.Size                  = new Size(300, 200);
            addPic.BackgroundImage       = bitmap;
            addPic.BackgroundImageLayout = ImageLayout.Stretch;
            if (PictureBoxContainer.Count == 0)
            {
                addPic.Location = new Point(10, 10);
            }
            else
            {
                if (PictureBoxContainer.Last().Location.X + PictureBoxContainer.Last().Width > MainPanel.Width)
                {
                    addPic.Location = new Point(10, PictureBoxContainer.Last().Location.Y + 200 + 10);
                }
                else
                {
                    addPic.Location = new Point(PictureBoxContainer.Last().Location.X
                                                + PictureBoxContainer.Last().Width + 10,
                                                PictureBoxContainer.Last().Location.Y);
                }
            }
            MainPanel.Controls.Add(addPic);
            PictureBoxContainer.Add(addPic);
        }
Пример #20
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            //Logo
            PictureBox picture = new PictureBox();

            picture.Image     = pictureBox1.Image;
            picture.SizeMode  = PictureBoxSizeMode.Zoom;
            picture.Width     = 270;
            picture.Height    = 150;
            picture.BackColor = Color.White;
            Bitmap bitmap = new Bitmap(picture.Width, picture.Height);

            picture.DrawToBitmap(bitmap, new Rectangle(0, 0, picture.Width, picture.Height));
            e.Graphics.DrawImage(bitmap, 0, 0);
            bitmap.Dispose();

            //Header
            e.Graphics.DrawString("LetEatB", new Font("Ariel", 36, FontStyle.Bold), Brushes.DarkRed, new Point(320, 100));
            e.Graphics.DrawString("Receipt", new Font("Ariel", 18, FontStyle.Bold), Brushes.DarkBlue, new Point(370, 160));

            //Date and Time
            String Time = DateTime.Now.ToLongTimeString();
            String Date = DateTime.Now.ToLongDateString();

            e.Graphics.DrawString(Time, new Font("Ariel", 14, FontStyle.Bold), Brushes.Black, new Point(635, 60));
            e.Graphics.DrawString(Date, new Font("Ariel", 14, FontStyle.Bold), Brushes.Black, new Point(580, 30));


            //Columns Names
            e.Graphics.DrawString("Product", new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(165, 205));
            e.Graphics.DrawString("Quantity", new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(380, 205));
            e.Graphics.DrawString("Price", new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(495, 205));
            e.Graphics.DrawString("Total", new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(615, 205));
            e.Graphics.DrawLine(new Pen(Color.Black), new Point(130, 235), new Point(695, 235));

            int y = 15;

            foreach (ListViewItem item in listView1.Items)
            {
                e.Graphics.DrawString(item.SubItems[0].Text + ".", new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(130, 220 + y));
                e.Graphics.DrawString(item.SubItems[1].Text, new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(180, 220 + y));
                e.Graphics.DrawString(item.SubItems[2].Text, new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(410, 220 + y));
                e.Graphics.DrawString(item.SubItems[3].Text, new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(510, 220 + y));
                e.Graphics.DrawString(item.SubItems[4].Text, new Font("Ariel", 16, FontStyle.Bold), Brushes.Black, new Point(610, 220 + y));
                y += 30;
            }
            e.Graphics.DrawString("Total: " + txtTotal.Text, new Font("Ariel", 16, FontStyle.Bold), Brushes.DarkBlue, new Point(330, 240 + y));
            e.Graphics.DrawString("Thank You!", new Font("Ariel", 22, FontStyle.Bold), Brushes.DarkRed, new Point(323, 270 + y));
        }
Пример #21
0
        /**
         * @brief 현재 그린 객체를 PNG 형식 이미지 파일로 저장하기 위해서 사용한다.
         * @details view에 있는 pictureBox를 들고 와서 pictureBox를 Bitmap형식으로 저장한 다음에 객체만 저장하기 위해서 객체의 크기로 자른다. 자른 후에 PNG형식으로 저장한다.
         * @return 저장된 png파일 경로를 반환한다.
         * @param fileName 저장할 파일 이름
         */
        public String SavePNG(string fileName)
        {
            PictureBox ptemp = ((View)viewList[1]).getPictureBox();

            int W = ptemp.Width;
            int H = ptemp.Height;

            Bitmap temp = new Bitmap(W, H);

            ptemp.DrawToBitmap(temp, new Rectangle(0, 0, W, H));
            temp.MakeTransparent(Color.White);
            temp.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            innerNeedSave = false;

            return(fileName);
        }
        /// <summary>
        /// Generate a bitmap of the Canvas
        /// </summary>
        /// <param name="canvasPane"></param>
        public Bitmap CaptureCanvas()
        {
            PictureBox Canvas = Document.GetCanvas();

            if (Canvas == null)
            {
                return(null);
            }

            int width  = Document.Scaling.CanvasSize.Width;
            int height = Document.Scaling.CanvasSize.Height;

            Bitmap bm = new Bitmap(width, height, Document.GetCanvasGraphics());

            Canvas.DrawToBitmap(bm, new Rectangle(0, 0, width, height));

            return(bm);
        }
Пример #23
0
        public void Functions()
        {
            PictureBox.BorderStyle = BorderStyle.None;
            Bitmap = new Bitmap(PictureBox.Width, PictureBox.Height);
            PictureBox.DrawToBitmap(Bitmap, PictureBox.ClientRectangle);
            if (Bitmap == null)
            {
                return;
            }
            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.Title           = "保存为";
            saveDlg.OverwritePrompt = true;
            saveDlg.Filter          = "BMP文件(*.bmp)|*.bmp|" +
                                      "JPEG文件(*.jpg)|*.jpg|" + "PNG文件(*.png)|*.png";
            saveDlg.ShowHelp = true;
            if (saveDlg.ShowDialog() == DialogResult.OK)
            {
                string fileName   = saveDlg.FileName;
                string strFilExtn = fileName.Remove(0, fileName.Length - 3);
                switch (strFilExtn)
                {
                case "bmp":
                    Bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
                    break;

                case "jpg":
                    Bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;

                case "tif":
                    Bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff);
                    break;

                case "png":
                    Bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                    break;

                default:
                    break;
                }
            }
        }
        // face efectiv exportul ca poza
        public static void ExportAsPicture(string fileName, PictureBox box)
        {
            Rectangle r = GasesteGranita(box);

            // cream un Bitmap si scriem in el ceea ce este desenat pe PictureBox
            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(box.Width, box.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
            {
                box.DrawToBitmap(bmp, box.ClientRectangle);

                // cream un nou bitmap ce reprezinta dreptunghiul care
                // incadreaza automatul
                bmpCrop = new Bitmap(r.Width, r.Height);
                Graphics g = Graphics.FromImage(bmpCrop);
                // fixam calitatea si continutul ca fiind automatul nostru
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                g.CompositingQuality = CompositingQuality.HighSpeed;
                g.DrawImage(bmp, 0, 0, r, GraphicsUnit.Pixel);

                ImageFormat imgFormat = null;                        // alegem formatul imginii in functie de extensie
                string      extension = Path.GetExtension(fileName); // asa preluam extensia
                switch (extension)
                {
                case ".bmp":
                case ".BMP":
                    imgFormat = ImageFormat.Bmp;
                    break;

                case ".png":
                case ".PNG":
                    imgFormat = ImageFormat.Png;
                    break;

                case ".jpg":
                case ".JPG":
                    imgFormat = ImageFormat.Jpeg;
                    break;
                }
                // salvam automatul, fara zone libere, fara nicio componenta
                bmpCrop.Save(fileName, imgFormat); // in formatul corespunzator
                bmpCrop.Dispose();                 // eliberam bmpCrop din memorie
            }
        }
Пример #25
0
        public void ExportToPNG(object sender, System.EventArgs e)
        {
            string formula = "";

            if (startNode != null)
            {
                formula = "_" + PathValidator.ValidatePath(startNode.ToString());
            }
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Filter     = "Images| *.png";
                sfd.DefaultExt = "png";
                sfd.FileName   = "graph" + formula;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    Bitmap bitmap = new Bitmap(pictureBoxGraph.ClientSize.Width, pictureBoxGraph.ClientSize.Height);
                    pictureBoxGraph.DrawToBitmap(bitmap, pictureBoxGraph.ClientRectangle);
                    bitmap.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }
Пример #26
0
        private void button2_Click(object sender, EventArgs e)
        {
            //label2.Text = "Dimensions :" + rectW + "," + rectH;
            Cursor = Cursors.Default;
            //Now we will draw the cropped image into pictureBox2
            Bitmap bmp2 = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            pictureBox1.DrawToBitmap(bmp2, pictureBox1.ClientRectangle);

            Bitmap crpImg = new Bitmap(rectW, rectH);

            for (int i = 0; i < rectW; i++)
            {
                for (int y = 0; y < rectH; y++)
                {
                    Color pxlclr = bmp2.GetPixel(crpX + i, crpY + y);
                    crpImg.SetPixel(i, y, pxlclr);
                }
            }

            pictureBox2.Image    = (Image)crpImg;
            pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
        }
Пример #27
0
        /*------------------------------------------------------------------------------------
        * Date : 2016.02.26
        * Author : HSLEE
        * Function : SaveImage(string strBMP)
        * Description : Bitmap Type Iamge 저장
        * Parameter : strBMP - Image 생성 하고자 하는 파일 이름
        *  ------------------------------------------------------------------------------------*/
        public void SaveImage(string strBMP)
        {
            string strFile = "";

            strFile = string.Format("{0:s}{1:s}.bmp", m_DBInfo.ScannerLogDir, strBMP);

            Bitmap bmp = new Bitmap(PicWafer.Width, PicWafer.Height);

            PicWafer.DrawToBitmap(bmp, new Rectangle(0, 0, PicWafer.Width, PicWafer.Height));

            // 흑백색으로 구성된 단색 Bitmap 형식으로 변환해야함 [Scanner에서 단색 비트맵 인식]
            // BMP 파일 비트 수준 : 1
            // 1. 단색 비트맵을 저장을 위한 Bitmap 생성
            Bitmap SaveImage = new Bitmap(PicWafer.Width, PicWafer.Height, PixelFormat.Format1bppIndexed);

            // 2. 사용자가 입력한 Image Size에 해당하는 복사본을 만들위한 Rectangle 생성
            Rectangle rectangle = new Rectangle(0, 0, PicWafer.Width, PicWafer.Height);

            // 3. 원본 이미지에 단색 Bitmap 속성을 바꾼 복사본을 만든다.
            SaveImage = bmp.Clone(rectangle, PixelFormat.Format1bppIndexed);

            SaveImage.Save(strFile);
        }
Пример #28
0
 public Bitmap GetBackImage(Control parent, int x, int y, int w, int h)
 {
     if (parent.BackgroundImage != null)
     {
         Bitmap     bt = new Bitmap(parent.Width, parent.Height);
         PictureBox pb = new PictureBox();
         pb.Size                  = parent.Size;
         pb.BackgroundImage       = parent.BackgroundImage;
         pb.BackgroundImageLayout = parent.BackgroundImageLayout;
         pb.DrawToBitmap(bt, pb.DisplayRectangle);
         pb.Dispose();
         Bitmap   destBitmap = new Bitmap(w, h);
         Graphics g          = Graphics.FromImage(destBitmap);
         g.DrawImage(bt, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
         bt.Dispose();
         g.Dispose();
         return(destBitmap);
     }
     else
     {
         return(null);
     }
 }
Пример #29
0
        public Drawer(PictureBox pBox)
        {
            this.pBox = pBox;

            img = pBox.Image.GetThumbnailImage(pBox.Width, pBox.Height, new Image.GetThumbnailImageAbort(abortImage), System.IntPtr.Zero);

            pBox.Image = img;

            graphics = Graphics.FromImage(img);

            pen          = new Pen(Color.Black, 10);
            pen.StartCap = LineCap.Round;
            pen.EndCap   = LineCap.Round;

            isDrawing = false;

            bitmap = new Bitmap(img.GetThumbnailImage(16, 16, new Image.GetThumbnailImageAbort(abortImage), System.IntPtr.Zero));

            pBox.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));

            pBox.MouseDown += new MouseEventHandler(startDrawing);
            pBox.MouseUp   += new MouseEventHandler(stopDrawing);
            pBox.MouseMove += new MouseEventHandler(onDraw);
        }
Пример #30
0
 public void CreateImage(PictureBox pictureBox, Image newImage)
 {
     pictureBox.DrawToBitmap((Bitmap)newImage, new Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
     image = pictureBox.Image;
 }