Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try {
                string state = get_LinkParam("state");
                string path  = Server.MapPath(SAVEPATH);
                if (string.IsNullOrEmpty(state))
                {
                    string temppath = Server.MapPath(TEMPPATH);
                    if (File.Exists(temppath))
                    {
                        path = temppath;
                    }
                }
                string showType = get_LinkParam("show");

                if (string.IsNullOrEmpty(showType))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(Server.MapPath(XMLPATH));
                    if (doc != null)
                    {
                        XmlNode node = doc.SelectSingleNode("Root/ShowType");
                        showType = node.InnerText;
                    }
                }
                ImageType obj = new ImageType();

                FileStream s = new FileStream(Server.MapPath(EXAMPLEPATH), FileMode.Open, FileAccess.Read);
                byte[]     b = new byte[int.Parse(s.Length.ToString())];
                s.Read(b, 0, int.Parse(s.Length.ToString()));
                s.Close();

                FileStream s1 = new FileStream(path, FileMode.Open, FileAccess.Read);
                byte[]     b1 = new byte[int.Parse(s1.Length.ToString())];
                s1.Read(b1, 0, int.Parse(s1.Length.ToString()));
                s1.Close();

                QJImagePro.Handles.PictureHandle pic = QJImagePro.PictureFactory.CreateHandle(QJImagePro.PictureType.Jpeg);
                byte[] by = pic.Watermarking(b, b1, 72, int.Parse(showType));

                HttpContext.Current.Response.ClearContent();
                HttpContext.Current.Response.ContentType = "image/Jpeg";
                HttpContext.Current.Response.BinaryWrite(by);
            }
            catch {
                Response.Write("图片路径不正确!");
                Response.End();
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // 400预览图路径
            string folderName     = get_LinkParam("f");
            string serverFileName = get_LinkParam("s");
            string rotate         = get_LinkParam("r");
            string yRootPath      = string.Empty;

            try {
                ImageType obj = new ImageType();
                //yangguang
                //yRootPath = obj.PreviewPath_400;
                //图片全路径
                //yRootPath = yRootPath +"/"+ folderName + @"/" + serverFileName;
                yRootPath = obj.GetPreviewPath(folderName, serverFileName, "400");
                if (rotate == "90" || rotate == "180" || rotate == "270")
                {
                    //用户选择的原图
                    FileStream fs  = new FileStream(yRootPath, FileMode.Open, FileAccess.Read);
                    byte[]     bss = new byte[int.Parse(fs.Length.ToString())];
                    fs.Read(bss, 0, int.Parse(fs.Length.ToString()));
                    fs.Close();
                    MemoryStream mstraeam = new MemoryStream(bss);
                    Bitmap       map      = new Bitmap(mstraeam);
                    Bitmap       bmp      = KiRotate(map, rotate);
                    Guid         guid     = Guid.NewGuid();
                    string       p        = Server.MapPath(@"temp/" + guid.ToString() + ".jpg");
                    bmp.Save(p, ImageFormat.Jpeg);
                    FileStream ms = new FileStream(p, FileMode.Open, FileAccess.Read);
                    byte[]     br = new byte[int.Parse(ms.Length.ToString())];
                    Session["BitmapImage"] = br;
                    ms.Read(br, 0, int.Parse(ms.Length.ToString()));
                    ms.Close();

                    //水印图片
                    FileStream fs1   = new FileStream(Server.MapPath(IMAGEPATH), FileMode.Open, FileAccess.Read);
                    byte[]     bytes = new byte[int.Parse(fs1.Length.ToString())];
                    fs1.Read(bytes, 0, int.Parse(fs1.Length.ToString()));
                    fs1.Close();

                    QJImagePro.Handles.PictureHandle picr = QJImagePro.PictureFactory.CreateHandle(QJImagePro.PictureType.Jpeg);
                    string showTyper = GetShowType();
                    int    typer     = string.IsNullOrEmpty(showTyper) ? 0 : int.Parse(showTyper);
                    byte[] byr       = picr.Watermarking(br, bytes, 72, typer);

                    if (File.Exists(p))
                    {
                        File.Delete(p);
                    }
                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.ContentType = "image/Jpeg";
                    HttpContext.Current.Response.BinaryWrite(byr);
                }
                else
                {
                    //用户选择的原图
                    FileStream s = new FileStream(yRootPath, FileMode.Open, FileAccess.Read);
                    byte[]     b = new byte[int.Parse(s.Length.ToString())];
                    s.Read(b, 0, int.Parse(s.Length.ToString()));
                    s.Close();
                    //水印图片
                    FileStream s1 = new FileStream(Server.MapPath(IMAGEPATH), FileMode.Open, FileAccess.Read);
                    byte[]     b1 = new byte[int.Parse(s1.Length.ToString())];
                    s1.Read(b1, 0, int.Parse(s1.Length.ToString()));
                    s1.Close();

                    QJImagePro.Handles.PictureHandle pic = QJImagePro.PictureFactory.CreateHandle(QJImagePro.PictureType.Jpeg);
                    string showType = GetShowType();
                    int    type     = string.IsNullOrEmpty(showType) ? 0 : int.Parse(showType);
                    byte[] by       = pic.Watermarking(b, b1, 72, type);

                    //if (rotate == "90" || rotate == "180" || rotate == "270") {
                    //    System.IO.MemoryStream m = new MemoryStream(by);
                    //    Bitmap map = new Bitmap(m);
                    //    Bitmap bmp = KiRotate(map, rotate);


                    //    HttpContext.Current.Response.ContentType = "image/Jpeg";
                    //    bmp.Save(HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);
                    //    bmp.Dispose();
                    //    map.Dispose();
                    //}
                    //else {
                    Session["BitmapImage"] = null;
                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.ContentType = "image/Jpeg";
                    HttpContext.Current.Response.BinaryWrite(by);
                    //}
                }
            }
            catch (Exception ee) {
                string a = ee.Message;
                if (File.Exists(yRootPath))
                {
                    FileStream s = new FileStream(yRootPath, FileMode.Open, FileAccess.Read);
                    byte[]     b = new byte[int.Parse(s.Length.ToString())];
                    s.Read(b, 0, int.Parse(s.Length.ToString()));
                    s.Close();

                    HttpContext.Current.Response.ClearContent();
                    HttpContext.Current.Response.ContentType = "image/Jpeg";
                    HttpContext.Current.Response.BinaryWrite(b);
                }
            }
        }
Beispiel #3
0
        protected void GetImageInfo(Guid itemId)
        {
            Resource       rs = new Resource();
            ResourceEntity r  = rs.GetResourceInfoByItemId(itemId.ToString());

            if (!r.ResourceType.ToLower().Equals("image"))
            {
                return;
            }



            //水印图片
            FileStream s1 = new FileStream(Server.MapPath(IMAGEPATH), FileMode.Open, FileAccess.Read);

            byte[] b1 = new byte[int.Parse(s1.Length.ToString())];
            s1.Read(b1, 0, int.Parse(s1.Length.ToString()));
            s1.Close();



            ImageType obj = new ImageType();
            //yangguang
            //string strPhysicalPath = Path.Combine(Path.Combine(obj.SourcePath,r.FolderName),r.ServerFileName);
            string strPhysicalPath = obj.GetSourcePath(r.FolderName, r.ServerFileName);

            if (File.Exists(strPhysicalPath))
            {
                Stream iStream     = null;
                String tmpFilePath = string.Empty;
                try
                {
                    byte[] buffer = new Byte[10000];
                    int    length;
                    long   dataToRead;
                    string filepath = strPhysicalPath;
                    string filename = Path.GetFileName(filepath);


                    //压缩
                    String tmpFileName = DateTime.Now.ToString("yyyyMMddhhmmss") + ".bin";
                    //yangguang
                    //tmpFilePath=Path.Combine(obj.SourcePath,tmpFileName);
                    tmpFilePath = Path.Combine(obj.SourcePaths[obj.PathNumber].Trim(), tmpFileName);//obj.GetSourcePath(string.Empty, tmpFileName);

                    System.Drawing.Image srcImage = System.Drawing.Image.FromFile(filepath);
                    int imgWidth  = srcImage.Width;
                    int imgHeight = srcImage.Height;


                    if (imgWidth > 1000 || imgHeight > 1000)
                    {
                        ArrayList sarray = new ArrayList();
                        sarray.Add(strPhysicalPath);
                        ArrayList aarray = new ArrayList();
                        aarray.Add(tmpFilePath);
                        ImageController.ToZipImage(sarray, aarray, 1000);

                        iStream = new FileStream(tmpFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }
                    else
                    {
                        iStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    }

                    //用户选择的原图

                    byte[] b = new byte[int.Parse(iStream.Length.ToString())];
                    iStream.Read(b, 0, int.Parse(iStream.Length.ToString()));
                    iStream.Close();


                    QJImagePro.Handles.PictureHandle pic = QJImagePro.PictureFactory.CreateHandle(QJImagePro.PictureType.Jpeg);
                    string showType = GetShowType();
                    int    type     = string.IsNullOrEmpty(showType) ? 0 : int.Parse(showType);
                    byte[] by       = pic.Watermarking(b, b1, 72, type);
                    Response.ContentType = "image/Jpeg";
                    Response.BinaryWrite(by);
                }
                catch (Exception ex)
                {
                    LogWriter.WriteExceptionLog(ex);
                }
                finally
                {
                    if (iStream != null)
                    {
                        iStream.Close();
                    }
                    if (File.Exists(tmpFilePath))
                    {
                        File.Delete(tmpFilePath);
                    }
                }
            }
        }