当前位置: 首页>>代码示例>>C#>>正文


C# Picture.Save方法代码示例

本文整理汇总了C#中Picture.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Picture.Save方法的具体用法?C# Picture.Save怎么用?C# Picture.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Picture的用法示例。


在下文中一共展示了Picture.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequest


//.........这里部分代码省略.........
            if (album == null || album.Id == 0)
            {
                album = group.CreateGroupAlbum();
            }

            //获取上传的文件并保存
            if (context.Request.Files.Count > 0)
            {

                imgFile = context.Request.Files[0];

                if (imgFile == null)
                {
                    return;
                }

                string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgFile.FileName).ToLower();
                string imgName = CY.Utility.Common.FileUtility.GetFileName(imgFile.FileName);

                string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                string dirPath = appPath + "/Content/Group/Album/" + groupId + "/";
                string fileName = "/Content/Group/Album/" + groupId + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                if (!di.Exists)
                {
                    di.Create();
                }

                string bImgName = appPath + fileName + "_big" + imgExtention;
                string mImgName = appPath + fileName + "_middle" + imgExtention;
                string sImgName = appPath + fileName + "_small" + imgExtention;

                imgFile.SaveAs(appPath + fileName + imgExtention);//临时保存原始图片

                Bitmap bmp = new Bitmap(appPath + fileName + imgExtention);
                int width = bmp.Width;
                int height = bmp.Height;

                bmp.Dispose();

                if (height <= width && width >= 600)
                {
                    height = Convert.ToInt32(width > 600 ? (600f / width) * height : height);
                    width = 600;
                }
                else if (width < height && height > 600)
                {
                    width = Convert.ToInt32(height > 600 ? (600f / height) * width : height);
                    height = 600;
                }

                // 将原始图压缩为大缩略图
                using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                {
                    CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height);
                }

                if (width > 200)
                {
                    height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                    width = 200;
                }

                // 生成图片(好友上传图片最新通知中显示)
                using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
开发者ID:dalinhuang,项目名称:ume-v3,代码行数:67,代码来源:UploadGroupImg.ashx.cs

示例2: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            HttpPostedFile imgFile;
            long accountId = 0;
            CY.UME.Core.Business.Account account=CY.UME.Core.Global.GetCurrentAccount();
            if (account == null)
                {
                    context.Response.Write("{success:false,msg:'用户登录超时'}");
                    return;
                }
            accountId = account.Id;
            CY.UME.Core.Business.Album album=account.GetMyAvatarAlbum(); // 取得当前用户的头像相册
            string picname = context.Request.Form["namepic"];
            string picremar = context.Request.Form["remark"];

            imgFile=context.Request.Files[0];

            string imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgFile.FileName).ToLower();
            string imgName = CY.Utility.Common.FileUtility.GetFileName(imgFile.FileName);
            string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
            string dirPath = appPath + "/Content/Album/" + accountId + "/";
            string fileName ="/Content/Album/" + accountId + "/" + DateTime.Now.ToString("yyyMMddhhmmss") + DateTime.Now.Millisecond.ToString();//相册图片以加时间命名
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(dirPath);
                    if (!di.Exists)
                    {
                        di.Create();
                    }

            string bImgName = appPath + fileName + "_big" + imgExtention;
            string mImgName = appPath + fileName + "_middle" + imgExtention;
            string sImgName = appPath + fileName + "_small" + imgExtention;

            imgFile.SaveAs(appPath + fileName + imgExtention);//临时保存原始图片

            Bitmap bmp = new Bitmap(appPath + fileName + imgExtention);
            int width = bmp.Width;
            int height = bmp.Height;

            bmp.Dispose();

            if (height <= width && width>=600)
            {
              height = Convert.ToInt32(width > 600 ? (600f / width) * height : height);
              width = 600;
            }
            else if(width<height && height>600)
            {
             width = Convert.ToInt32(height > 600 ? (600f / height) * width : height);
             height = 600;
            }

                    // 将原始图压缩为大缩略图
                    using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                    {
                        CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height);
                    }

                    if (width > 200)
                    {
                        height = Convert.ToInt32(width > 200 ? (200f / width) * height : height);
                        width = 200;
                    }

                    // 生成图片(好友上传图片最新通知中显示)
                    using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                    {
                        CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, sImgName, width, height);
                    }

                    if (height <= width && width>=100)
                    {
                        height = Convert.ToInt32(width > 100 ? (100f / width) * height : height);
                        width = 100;
                    }
                    else if(width<height && height>100)
                    {
                        width = Convert.ToInt32(height > 100 ? (100f / height) * width : height);
                        height = 100;
                    }

                    // 将大图片压缩为中等缩略图
                    using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention))
                    {
                        CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, width, height);
                    }

                    try
                    {
                        File.Delete(appPath + fileName +imgExtention);
                    }
                    catch
                    {
                        ;
                    }

                   //更换相册封面

                    if (album.PhotoCount == 0 || album.CoverPath.Trim().Length==0)
                    {
//.........这里部分代码省略.........
开发者ID:dalinhuang,项目名称:ume-v3,代码行数:101,代码来源:UploadQicPic.ashx.cs


注:本文中的Picture.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。