Exemple #1
0
        static void Main(string[] args)
        {
            BeiAnImageUtil util   = new BeiAnImageUtil();
            String         folder = "E:\\";
            //Bitmap bitMapImage = new System.Drawing.Bitmap(folder + "sj001_R.jpg");
            Bitmap bitMapImage = new System.Drawing.Bitmap(folder + "test.jpg");

            byte[] imageBytes = util.imageToByteArray(bitMapImage);
            //util.createImage(folder + "test.jpg", "SN-XQ-S-201311250025", folder + "test2.jpg");
            Bitmap b = util.ByteArraytoBitmap(imageBytes);

            byte[] output = util.createImage(b, "SN-XQ-S-201311250025", folder + "test2.jpg");
            Bitmap bm     = util.ByteArraytoBitmap(output);

            bm.Save(folder + util.getTimeStamp() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            BeiAnImageUtil util = new BeiAnImageUtil();
            String folder = "E:\\";
            //Bitmap bitMapImage = new System.Drawing.Bitmap(folder + "sj001_R.jpg");
            Bitmap bitMapImage = new System.Drawing.Bitmap(folder + "test.jpg");
            byte[] imageBytes = util.imageToByteArray(bitMapImage);
            //util.createImage(folder + "test.jpg", "SN-XQ-S-201311250025", folder + "test2.jpg");
            Bitmap b = util.ByteArraytoBitmap(imageBytes);

            byte[] output = util.createImage(b, "SN-XQ-S-201311250025", folder + "test2.jpg");
            Bitmap bm = util.ByteArraytoBitmap(output);
            bm.Save(folder + util.getTimeStamp() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
        /// <summary>
        /// ��������ͼ�����ˮӡ
        /// </summary>
        /// <param name="originalImagePath">ԭʼͼ</param>
        /// <param name="width">���Ժ�Ŀ��</param>
        /// <param name="height">���Ժ�ĸ߶�</param>     
        private void MakeThumbnail_And_AddWaterMark(string originalImagePath)
        {
            string strFileExt = originalImagePath.Substring(originalImagePath.LastIndexOf(".") + 1).ToUpper();
            string strPath = originalImagePath.Substring(0, originalImagePath.LastIndexOf("\\"));
            string sFileName = originalImagePath.Substring(originalImagePath.LastIndexOf("\\") + 1).Replace("." + strFileExt.ToLower(), "");
            string sRawImagePath = strPath + "\\" + sFileName + "_Raw." + strFileExt;

            System.IO.File.Copy(originalImagePath, sRawImagePath, true);

            string smallImagePath = originalImagePath;//ֱ�Ӹ���ԭ���Ĵ�ͼƬ

            System.Drawing.Image originalImage = System.Drawing.Image.FromFile(sRawImagePath);

            int towidth = originalImage.Width;
            int toheight = originalImage.Height;

            int x = 0;
            int y = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;

            //�½�һ��bmpͼƬ
            System.Drawing.Image bitmap = new Bitmap(towidth, toheight);

            //�½�һ������
            Graphics g = Graphics.FromImage(bitmap);

            //���ø�������ֵ��
            g.InterpolationMode = InterpolationMode.High;

            //���ø�����,���ٶȳ���ƽ���̶�
            g.SmoothingMode = SmoothingMode.HighQuality;

            ////��ջ�������͸������ɫ���
            g.Clear(Color.Transparent);

            //��ָ��λ�ò��Ұ�ָ����С����ԭͼƬ��ָ������
            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
                        new Rectangle(x, y, ow, oh),
                        GraphicsUnit.Pixel);

            if (this.WatermarkImageUrl != "")
            {
                System.Drawing.Image watermark = new Bitmap(this.Page.MapPath(StampImageUrl));
                if (String.IsNullOrEmpty(Request["BeiAnGuid"]))
                {
                    this.addWatermarkImage(g, towidth, toheight, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.TOP_LEFT);
                }
                else
                {
                    //��Ҫ�����Ƿ�Ӧ�ü������Ĺ��£�
                    bool IsND = false;
                    string strSql = "SELECT IsNDBA,RegistAddress,* FROM RG_OUInfo WHERE ROWGUID=(select DWGuid from RG_XMBeiAn where RowGuid='" + Request["BeiAnGuid"] + "')";
                    string qyzcd = "";
                    DataView dvQY = Epoint.MisBizLogic2.DB.ExecuteDataView(strSql);
                    if (dvQY.Count > 0)
                    {
                        qyzcd = dvQY[0]["RegistAddressCode"].ToString().Substring(0, 2);
                        if (dvQY[0]["IsNDBA"].ToString() == "1")
                        {
                            IsND = true;
                        }
                        else if (qyzcd == "32")
                        {
                            IsND = true;
                        }

                    }

                    //�ٿ��ǼӸ����������˵���
                    //��ͬ�������¼���Ч��
                    string BeiAnGuid = Request["BeiAnGuid"];
                    //ͨ���������ȡ��Ϣ
                    Epoint.MisBizLogic2.Data.MisGuidRow oRow = new Epoint.MisBizLogic2.Data.MisGuidRow("RG_XMBeiAn", Request["BeiAnGuid"]);
                    string address = oRow["XMAdd"].ToString();
                    if (address == "320282")
                    {
                        addWatermarkImage3(g, watermark.Width, watermark.Height, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.TOP_LEFT, StampImageUrl_YX);
                        if (!IsND)
                        {
                            //�������
                            this.addWatermarkImage2(g, watermark.Width, watermark.Height, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.TOP_LEFT, StampImageUrl);
                        }
                    }
                    else if (address == "320281")
                    {
                        addWatermarkImage3(g, watermark.Width, watermark.Height, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.TOP_LEFT, StampImageUrl_JY);
                        if (!IsND)
                        {
                            //�������
                            this.addWatermarkImage2(g, watermark.Width, watermark.Height, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.TOP_LEFT, StampImageUrl);
                        }
                    }
                    else
                    {
                        //�������
                        this.addWatermarkImage2(g, watermark.Width, watermark.Height, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.TOP_LEFT, StampImageUrl);
                    }
                    string strMessage = "��Ŀ������:";
                    strMessage += oRow["XMBH"];
                    //strMessage += ";��������:";
                    //strMessage += DateTime.Parse(oRow["TGDate"].ToString()).ToString("yyyy��MM��dd��");
                    strMessage += "\n������:";
                    strMessage += DateTime.Parse(oRow["TGDate"].ToString()).AddYears(2).ToString("yyyy��MM��dd��");
                    BeiAnImageUtil util = new BeiAnImageUtil();
                    util.addStampAndDate(bitmap, g, strMessage, this.Page.MapPath(this.StampImageUrl), watermark.Width+5);
                }
            }
            //if (this.WatermarkText != "")
            //{

            //    this.addWatermarkText(g, towidth, toheight, HTProject_Bizlogic.CommonEnum.WaterMarkPosition.BOTTOM_LEFT);
            //}
            try
            {
                //����������ȵ�����ͼ
                if (strFileExt == "JPG" || strFileExt == "JPEG")
                {
                    bitmap.Save(smallImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                else if (strFileExt == "GIF")
                {
                    bitmap.Save(smallImagePath, System.Drawing.Imaging.ImageFormat.Gif);
                }
                else if (strFileExt == "PNG")
                {
                    bitmap.Save(smallImagePath, System.Drawing.Imaging.ImageFormat.Png);
                }
                else if (strFileExt == "BMP")
                {
                    bitmap.Save(smallImagePath, System.Drawing.Imaging.ImageFormat.Bmp);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }

            System.IO.File.Delete(sRawImagePath);//ɾ��ԭ�����ļ�

            //Test
            //BeiAnImageUtil util = new BeiAnImageUtil();
            //String folder = "E:\\";
            //util.createImage(folder + "test.jpg", "SN-XQ-S-201311250025", folder + "test2.jpg");
            //Bitmap b = util.ByteArraytoBitmap((byte[])oRow["Content"]);
            //byte[] output = util.createImage(b, "SN-XQ-S-201311250025", folder + "test2.jpg");
            //Bitmap bm = util.ByteArraytoBitmap(output);
            //bm.Save(folder + util.getTimeStamp() + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }