示例#1
0
        /// <summary>
        /// 图片缩小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPicSmaller_Click(object sender, EventArgs e)
        {
            try
            {
                if (picSample.Image == null)
                {
                    return;
                }
                if (saveStandImage == null)
                {
                    saveStandImage = picSample.Image;
                }

                decimal zoonNum = saveZoomNum * 0.1m + 1m;
                if (zoonNum <= 0)
                {
                    return;
                }
                else
                {
                    saveZoomNum--;
                }
                picSample.Image = UCTemplatePic.ZoomImage(saveStandImage, zoonNum);
            }
            catch (Exception E)
            {
                this.ShowMessage(E.Message);
            }
        }
示例#2
0
 private void cmiDownload_Click(object sender, EventArgs e)
 {
     try
     {
         if (picSample.Image != null)
         {
             saveFileDialog1.FileName = "pic.jpg";
             saveFileDialog1.Title    = "图片下载";
             if (saveFileDialog1.FileName != string.Empty && saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 string outpath          = saveFileDialog1.FileName;
                 System.IO.FileStream fs = new System.IO.FileStream(outpath, System.IO.FileMode.Create);
                 byte[] imageByte        = UCTemplatePic.ImageToByte(picSample.Image);
                 for (int i = 0; i < imageByte.Length; i++)
                 {
                     fs.WriteByte(imageByte[i]);
                 }
                 fs.Close();
                 ShowInfoMessage("文件下载成功");
             }
         }
     }
     catch (Exception E)
     {
         this.ShowMessage(E.Message);
     }
 }
示例#3
0
        /// <summary>
        /// 压缩图片
        /// </summary>
        public static Image ZipImage(Image p_Img)
        {
            Image  img = p_Img;
            Bitmap bmp = new Bitmap(p_Img);
            string fn  = UCTemplatePic.GetTempFileName("SP", "1");

            bmp.Save(fn, System.Drawing.Imaging.ImageFormat.Jpeg);
            Image tempimg = Image.FromFile(fn);

            if (((byte[])ImageToByte(p_Img)).Length >= ((byte[])ImageToByte(tempimg)).Length)//确定变小了才替换
            {
                img = tempimg;
            }
            return(img);
        }
示例#4
0
        /// <summary>
        /// 拍照/更多操作按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCam_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckImageBrowse())//校验图片浏览
                {
                    return;
                }

                switch (btnCam.Text)
                {
                case "拍照":
                    UCPictureVideoCamerFrm frmpz = new UCPictureVideoCamerFrm();
                    frmpz.ShowDialog();
                    if (frmpz.pzflag)
                    {
                        picShow.Image  = UCTemplatePic.ZipImage(Image.FromFile(frmpz.pzfileName));
                        txtRemark.Text = "拍照" + DateTime.Now.ToString("yyyy-MM-dd HH");
                    }
                    break;

                case "截图":
                    JTAct();
                    //Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);
                    //Graphics g = Graphics.FromImage(img);
                    //g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size);
                    //UCScreenBody body = new UCScreenBody();
                    //body.BackgroundImage = img;
                    //body.ShowDialog();
                    //if (body.JQImage != null)
                    //{
                    //    picShow.Image = body.JQImage;
                    //    txtRemark.Text = "截图" + DateTime.Now.ToString("yyyy-MM-dd HH");
                    //}
                    break;
                }

                ImageBrowseSave();//图片浏览保存
            }
            catch (Exception E)
            {
                this.ShowMessage(E.Message);
            }
        }
示例#5
0
 /// <summary>
 /// 图片放大
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnPicBigger_Click(object sender, EventArgs e)
 {
     try
     {
         if (picSample.Image == null)
         {
             return;
         }
         if (saveStandImage == null)
         {
             saveStandImage = picSample.Image;
         }
         if (saveZoomNum < 30)//最多放大4倍,限制下,防止溢出
         {
             saveZoomNum++;
         }
         picSample.Image = UCTemplatePic.ZoomImage(saveStandImage, saveZoomNum * 0.1m + 1m);
     }
     catch (Exception E)
     {
         this.ShowMessage(E.Message);
     }
 }
示例#6
0
        /// <summary>
        /// 加载图片
        /// </summary>
        void LoadImage()
        {
            if (UCInputMainType == 1)//数据库交互模式
            {
                m_UCDataLstImage.Clear();
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    m_UCDataLstSmallImage.Clear();
                }
                saveIDs.Clear();
                saveImageIndex = -1;
                picShow.Image  = null;


                string sql = string.Empty;
                switch (UCInputDBSaveType)
                {
                case 1:    //存储在同一张表内

                    sql = "SELECT ID," + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                    }
                    sql += " FROM " + UCDBTableName + " WHERE ID=" + UCDataID;
                    break;

                case 2:    //存储在独立的数据表内
                    sql = "SELECT ID," + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                    }
                    sql += " FROM " + UCDBTableName + " WHERE " + UCDBMainIDFieldName + "=" + UCDataID;

                    break;
                }


                if (sql != string.Empty)
                {
                    DataTable dt = PicFill(sql);
                    foreach (DataRow dr in dt.Rows)
                    {
                        m_UCDataLstImage.Add(UCTemplatePic.ByteToImage(dr[UCDBPicFieldName] as byte[]));
                        if (UCDBSmallPicFieldName != string.Empty)
                        {
                            m_UCDataLstSmallImage.Add(UCTemplatePic.ByteToImage(dr[UCDBSmallPicFieldName] as byte[]));
                        }
                        saveIDs.Add(SysConvert.ToInt32(dr["ID"]));
                    }
                    if (dt.Rows.Count > 0)
                    {
                        saveImageIndex = 0;
                        picShow.Image  = m_UCDataLstImage[saveImageIndex];
                    }
                    else
                    {
                        picShow.Image = null;
                    }
                }
            }
            else if (UCInputMainType == 2)//仅是图片交互模式
            {
                picShow.Image = null;
                //代码待补充
                if (m_UCDataLstImage.Count > 0)
                {
                    saveImageIndex = 0;
                    picShow.Image  = m_UCDataLstImage[saveImageIndex];
                }
            }

            SetButtonStatus();
        }
示例#7
0
        /// <summary>
        /// 修改图片
        /// </summary>
        void UpdateImage()
        {
            if (UCInputMainType == 1)//数据库交互模式
            {
                string sql = "";

                switch (UCInputDBSaveType)
                {
                case 1:    //存储在同一张表内
                    sql = "UPDATE " + UCDBTableName + " SET " + UCDBPicFieldName + "=@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName + "=@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                        sql += "=" + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    if (UCDBMainIDFieldName != string.Empty)
                    {
                        sql += "," + UCDBMainIDFieldName + "=" + UCDataID;
                    }
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName + "=" + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += " WHERE ID=" + UCDataID;

                    break;

                case 2:    //存储在独立的数据表内
                    sql = "UPDATE " + UCDBTableName + " SET " + UCDBPicFieldName + "=@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName + "=@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                        sql += "=" + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    if (UCDBMainIDFieldName != string.Empty)
                    {
                        sql += "," + UCDBMainIDFieldName + "=" + UCDataID;
                    }
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName + "=" + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += " WHERE ID=" + saveIDs[saveImageIndex];

                    break;
                }

                int len = 1;
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    len = 2;
                }
                object[,] obja = new object[2, len];
                obja[0, 0]     = "@" + UCDBPicFieldName;
                obja[1, 0]     = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight));
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    obja[0, 1] = "@" + UCDBSmallPicFieldName;
                    obja[1, 1] = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight));
                }
                PicExecuteNonQuery(sql, obja); //SysUtils.ExecuteNonQuery
            }
            else if (UCInputMainType == 2)     //仅是图片交互模式
            {
                //代码待补充
                if (m_UCDataLstImage.Count > 0)
                {
                    if (m_UCDataLstImage.Count > saveImageIndex)
                    {
                        m_UCDataLstImage[saveImageIndex] = UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight);
                    }
                    if (m_UCDataLstSmallImage.Count > saveImageIndex)
                    {
                        m_UCDataLstSmallImage[saveImageIndex] = UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight);
                    }
                }
                else
                {
                    InsertImage();
                }
            }
        }
示例#8
0
        /// <summary>
        /// 插入图片
        /// </summary>
        /// <returns>返回ID</returns>
        int  InsertImage()
        {
            int outI = 0;

            if (UCInputMainType == 1)//数据库交互模式
            {
                string sql = "";
                switch (UCInputDBSaveType)
                {
                case 1:    //存储在同一张表内,依旧使用Update方法
                    sql = "UPDATE " + UCDBTableName + " SET " + UCDBPicFieldName + "=@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != string.Empty)
                    {
                        sql += "," + UCDBSmallPicFieldName + "=@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                        sql += "=" + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    if (UCDBMainIDFieldName != string.Empty)
                    {
                        sql += "," + UCDBMainIDFieldName + "=" + UCDataID;
                    }
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName + "=" + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += " WHERE ID=" + UCDataID;
                    outI = UCDataID;
                    break;

                case 2:    //存储在独立的数据表内

                    sql = "SELECT MAX(ID) ID FROM " + UCDBTableName;
                    DataTable dt = PicFill(sql);
                    if (dt.Rows.Count != 0)
                    {
                        outI = SysConvert.ToInt32(dt.Rows[0]["ID"]) + 1;
                    }


                    sql = "INSERT INTO " + UCDBTableName + " (ID," + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != "")
                    {
                        sql += "," + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + UCDBRemarkFieldName;
                    }
                    sql += "," + UCDBMainIDFieldName;
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + UCDBStyleNoFieldName;
                    }
                    sql += ") VALUES(";
                    sql += outI.ToString() + ",";  //ID
                    sql += @"@" + UCDBPicFieldName;
                    if (UCDBSmallPicFieldName != "")
                    {
                        sql += "," + @"@" + UCDBSmallPicFieldName;
                    }
                    if (UCDBRemarkFieldName != string.Empty)
                    {
                        sql += "," + SysString.ToDBString(txtRemark.Text.Trim());
                    }
                    sql += "," + SysString.ToDBString(UCDataID.ToString());
                    if (UCDBStyleNoFieldName != string.Empty)
                    {
                        sql += "," + SysString.ToDBString(UCDataStyleNo);
                    }
                    sql += ")";
                    break;
                }

                int len = 1;
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    len = 2;
                }
                object[,] obja = new object[2, len];
                obja[0, 0]     = "@" + UCDBPicFieldName;
                obja[1, 0]     = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight));
                if (UCDBSmallPicFieldName != string.Empty)
                {
                    obja[0, 1] = "@" + UCDBSmallPicFieldName;
                    obja[1, 1] = UCTemplatePic.ImageToByte(UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight));
                }
                PicExecuteNonQuery(sql, obja); //SysUtils.ExecuteNonQuery
            }
            else if (UCInputMainType == 2)     //仅是图片交互模式
            {
                //代码待补充
                m_UCDataLstImage.Add(UCTemplatePic.ZoomImage(picShow.Image, UCUIPicWidth, UCUIPicHeight));

                m_UCDataLstSmallImage.Add(UCTemplatePic.ZoomImage(picShow.Image, UCUISmallPicWidth, UCUISmallPicHeight));
            }

            return(outI);
        }