Example #1
0
        public void LoadImage(string imageFilename, int Id, int width, int height)
        {
            Common.CommonMethods c = Common.CommonMethods.CreateInstance();
            Bitmap bm = new Bitmap(10, 10);

            System.IO.FileInfo finf = new System.IO.FileInfo(imageFilename);
            isValidImage = false;// to reset image valid to false
            if (finf.Exists)
            {
                string[] strArr        = finf.Name.Split('.');
                string   thumbnailName = finf.DirectoryName + System.IO.Path.DirectorySeparatorChar + strArr[0] + "_tb." + strArr[1];
                if (System.IO.File.Exists(thumbnailName))
                {
                    isValidImage = LoadSaveImage.LoadImage(thumbnailName, ref bm);
                }
                if (!isValidImage)
                {
                    isValidImage = LoadSaveImage.LoadImage(imageFilename, ref bm);
                    if (isValidImage)
                    {
                        int mulfactor = width / 4;

                        Bitmap   tempBM   = new Bitmap(width, 3 * mulfactor);
                        Graphics graphics = Graphics.FromImage(tempBM);
                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.DrawImage(bm, 0, 0, width, 3 * mulfactor);
                        graphics.Dispose();
                        tempBM.Save(thumbnailName);
                        bm.Dispose();
                        bm = new Bitmap(tempBM);
                        tempBM.Dispose();
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                return;// To fix defect 0001696 if the file doesn't exists then make the image invalid or corrupted.
            }
            Image tempImage = bm;

            m_ImageLocation = imageFilename;
            ImageID         = Id;
            int    dw = tempImage.Width;
            int    dh = tempImage.Height;
            int    tw = width;
            int    th = height;
            double zw = (tw / (double)dw);
            double zh = (th / (double)dh);
            double z  = (zw <= zh) ? zw : zh;

            dw = (int)(dw * z);
            dh = (int)(dh * z);

            m_Image = new Bitmap(dw, dh);
            Graphics g = Graphics.FromImage(m_Image);

            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(tempImage, 0, 0, dw, dh);
            g.Dispose();
            m_ImageName          = new Label();
            m_ImageName.Location = new Point(0, dh);
            tempImage.Dispose();
        }
Example #2
0
        private void createTable()
        {
            //switch case has been removed and for loop is added in order accomodate as many images as possible by sriram on september 9th 2015
            //switch (images.Length)
            //{
            //    case 2:
            //        if (isPortrait)
            //        {
            //            this.RowCount = 2;
            //            this.ColumnCount = 1;
            //        }
            //        else
            //        {
            //            this.RowCount = 1;
            //            this.ColumnCount = 2;
            //        }
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        break;
            //    case 3:
            //        this.RowCount = 2;
            //        this.ColumnCount = 2;
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        break;

            //    case 4:
            //        this.RowCount = 2;
            //        this.ColumnCount = 2;
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        break;

            //    case 5:
            //        if (isPortrait)
            //        {
            //            this.RowCount = 3;
            //            this.ColumnCount = 2;
            //        }
            //        else
            //        {
            //            this.RowCount = 2;
            //            this.ColumnCount = 3;
            //        }
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        break;

            //    case 6:
            //        if (isPortrait)
            //        {
            //            this.RowCount = 3;
            //            this.ColumnCount = 2;
            //        }
            //        else
            //        {
            //            this.RowCount = 2;
            //            this.ColumnCount = 3;
            //        }
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //        this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //        break;

            //    default:
            ////if (images.Length == 1)
            ////{
            //this.RowCount = 1;
            //this.ColumnCount = 1;
            //this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            //this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
            //break;
            //}
            //else if(images.Length  > 1)
            //{
            //    //if(images.Length % 2 == 0 )

            //}
            if (images.Length > 2)
            {
                if (images.Length % 2 == 0)
                {
                    if (isPortrait)
                    {
                        this.ColumnCount = 2;
                        this.RowCount    = images.Length / 2;
                        //this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                        //this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
                    }
                    else
                    {
                        this.RowCount    = 2;
                        this.ColumnCount = images.Length / 2;
                        //this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                        //this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
                    }
                }
                else
                {
                    int temp = images.Length + 1;
                    if (isPortrait)
                    {
                        this.ColumnCount = 2;
                        this.RowCount    = temp / 2;
                        //this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                        //this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
                    }
                    else
                    {
                        this.RowCount    = 2;
                        this.ColumnCount = temp / 2;
                        //this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
                        //this.RowStyles.Add(new RowStyle(SizeType.Percent, 50));
                    }
                }
            }
            else if (images.Length == 1 || images.Length == 0)//The additional condition images.Length == 0 has been added to enable the click on imagetable when image count is zero;
            {
                this.RowCount    = 1;
                this.ColumnCount = 1;
                //this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            }
            else if (images.Length == 2)
            {
                {
                    this.RowCount    = 1;
                    this.ColumnCount = 2;
                }
            }
            int imgCnt = 0;

            //_dataModel.ImageFileNamesFromTable = new string[this.RowCount, this.ColumnCount];
            //_dataModel.ImageNamesFromTable = new string[this.RowCount, this.ColumnCount];
            for (int i = 0; i < this.RowCount; i++)
            {
                this.RowStyles.Add(new RowStyle(SizeType.Percent, 20));
            }
            for (int i = 0; i < this.ColumnCount; i++)
            {
                this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 20));
            }
            for (int i = 0; i < this.RowCount; i++)
            {
                for (int j = 0; j < this.ColumnCount; j++)
                {
                    {
                        Label lbl = new Label();
                        pb          = new PictureBox();
                        pb.SizeMode = PictureBoxSizeMode.Zoom;
                        pb.Dock     = DockStyle.Fill;
                        pb.Margin   = new System.Windows.Forms.Padding(0);
                        //if (!Report.isFromCDR)//This if statement has been added for the purpose of not showing the tool tip when Report is opened from CDR.
                        {
                            ToolTip tt = new ToolTip();
                            tt.AutoPopDelay = 500;
                            tt.InitialDelay = 1000;
                            tt.ReshowDelay  = 500;
                            tt.SetToolTip(pb, "Select Images");
                        }
                        if (Report.isNew)
                        {
                            pb.Cursor = Cursors.Hand;
                        }
                        else
                        {
                            pb.Cursor = Cursors.Default;
                        }
                        pb.DoubleClick += pb_DoubleClick;
                        pb.Click       += pb_Click;
                        {
                            if (imgCnt < images.Length)
                            {
                                Common.CommonMethods common_methods = Common.CommonMethods.CreateInstance();
                                Bitmap bm = new Bitmap(10, 10);
//                            common_methods.LoadImage(images[imgCnt], ref bm);
                                LoadSaveImage.LoadImage(images[imgCnt], ref bm);
                                pb.Image      = bm;
                                lbl.BackColor = Color.Transparent;
                                lbl.Text      = this.imageNames[imgCnt];// "Image " + (1 + imgCnt).ToString();
                                lbl.Margin    = new System.Windows.Forms.Padding(0);
                                lbl.Dock      = DockStyle.Top;
                                if (images.Length == 2)
                                {
                                    lbl.Dock      = DockStyle.Top;
                                    lbl.TextAlign = ContentAlignment.BottomCenter;
                                }
                                else
                                {
                                    lbl.Dock      = DockStyle.Top;
                                    lbl.TextAlign = ContentAlignment.MiddleCenter;
                                }
                                //_dataModel.ImageFileNamesFromTable[i, j] = images[imgCnt];
                                //_dataModel.ImageNamesFromTable[i, j] = this.imageNames[imgCnt];
                            }
                        }
                        Panel pnl = new Panel();
                        pnl.Dock = DockStyle.Fill;
                        pnl.Controls.Add(pb);
                        pnl.Controls.Add(lbl);
                        this.Controls.Add(pnl, j, i);
                        imgCnt++;
                    }
                }
            }
        }
        public void createPanel(int row, int col, string name)
        {
            int imageWidthinPanel = (this.Size.Width / col) - paddingValue;
            int imageHeightPanel  = (this.Size.Height / row) - paddingValue;
            int pictureBox_X      = 5;
            int pictureBox_Y      = 0;

            imgCount = 0;
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    PictureBoxExtended pb = new PictureBoxExtended();
                    pb.SizeMode = PictureBoxSizeMode.Zoom;
                    pb.Margin   = new System.Windows.Forms.Padding(0);

                    {
                        ToolTip tt = new ToolTip();
                        tt.AutoPopDelay = 500;
                        tt.InitialDelay = 1000;
                        tt.ReshowDelay  = 500;
                        tt.SetToolTip(pb, "Select Images");
                    }
                    if (imgCount < Images && Images > 0)
                    {
                        if (File.Exists(imagePaths[imgCount]))
                        {
                            Common.CommonMethods common_methods = Common.CommonMethods.CreateInstance();
                            Bitmap bm = new Bitmap(10, 10);
                            LoadSaveImage.LoadImage(imagePaths[imgCount], ref bm);
                            pb.Image = bm;
                        }
                        else
                        {
                            pb.Image = new Bitmap(2048, 1536);
                        }
                    }
                    else
                    {
                        pb.Image = new Bitmap(2048, 1536);
                    }
                    if (imgCount < Images && Images > 0 && imageNames.Length == Images)
                    {
                        pb.Tag = imageNames[imgCount];
                    }
                    pb.Index       = ++imgCount;
                    pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    pb.Location    = new Point(pictureBox_X, pictureBox_Y);
                    pb.Size        = new Size(imageWidthinPanel, imageHeightPanel - paddingValue);
                    pb.Click      += pb_Click;
                    pb.Paint      += pbPaint;

                    this.Controls.Add(pb);
                    pictureBox_X += imageWidthinPanel + paddingValue;
                }
                pictureBox_Y += imageHeightPanel + paddingValue;
                pictureBox_X  = 5;
            }

            this.Refresh();
        }