private CY.UME.Core.Business.Album GetActivityAlbum(string type, string instanceId, string albumName) { IList<CY.UME.Core.Business.AlbumExtend> aeList = CY.UME.Core.Business.AlbumExtend.GetAlbumExtend(CurrentAccount.Id, type, instanceId); long aId = 0; CY.UME.Core.Business.Album album = new CY.UME.Core.Business.Album(); if (aeList.Count != 0) { aId = aeList[0].Id; } //创建活动相册 if (aId == 0) { album.AccountId = CurrentAccount.Id; album.DateCreated = DateTime.Now; album.IsAvatar = false; album.LastModifiedTime = DateTime.Now; album.Name = albumName; album.ViewPermission = 0; album.Save(); CY.UME.Core.Business.AlbumExtend ae = new CY.UME.Core.Business.AlbumExtend(); ae.Type = type; ae.InstanceId = instanceId; ae.AccountId = album.AccountId; ae.Id = album.Id; ae.Save(); aId = album.Id; } else { album = CY.UME.Core.Business.Album.Load(aId); } return album; }
private void CompressImg(string appPath, string fileName, string imgExtention, int activeId, long albumID) { string bImgName = appPath + fileName + "_big" + imgExtention; string mImgName = appPath + fileName + "_middle" + imgExtention; string sImgName = appPath + fileName + "_small" + imgExtention; #region 压缩图片 Bitmap bmp = new Bitmap(appPath + fileName + imgExtention); int width = bmp.Width; int height = bmp.Height; bmp.Dispose(); width = 200; height = 200; // 将原始图压缩为大缩略图 using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention)) { CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, bImgName, width, height); } // 生成中图片(好友上传图片最新通知中显示)200*200 using (StreamReader reader = new StreamReader(appPath + fileName + imgExtention)) { CY.Utility.Common.ImageUtility.ThumbAsJPG(reader.BaseStream, mImgName, 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, sImgName, width, height); } try { File.Delete(appPath + fileName + imgExtention); } catch { ; } #endregion //更换活动海报 CY.UME.Core.Business.Activities ac = CY.UME.Core.Business.Activities.Load(activeId); if (ac != null) { fileName = fileName.Replace("\\", "/"); ac.Pic = fileName + "_small" + imgExtention; ac.Save(); } //更换相册封面 CY.UME.Core.Business.Album album = CY.UME.Core.Business.Album.Load(albumID); if (album.PhotoCount == 0 || album.CoverPath.Trim().Length == 0) { album.CoverPath = fileName.Replace("\\", "/") + "_small" + imgExtention; album.Save(); } CY.UME.Core.Business.AlbumExtend albumExtend = new CY.UME.Core.Business.AlbumExtend(); albumExtend.Id = albumID;//相册ID albumExtend.InstanceId = activeId.ToString();//活动ID albumExtend.AccountId = CurrentAccount.Id;//用户ID albumExtend.Type = "active"; albumExtend.Save(); ////将路径及图片信息保存到数据库 //CY.UME.Core.Business.Picture pic = new CY.UME.Core.Business.Picture(); //pic.AlbumId = albumID;//相册ID //fileName = fileName.Replace("\\", "/"); //pic.BigPath = fileName + "_big" + imgExtention; //pic.DateCreated = DateTime.Now; //pic.MiddlePath = fileName + "_middle" + imgExtention; //pic.Name = CY.Utility.Common.StringUtility.HTMLEncode(ac.Name.Substring(0, ac.Name.Length > 30 ? 30 : ac.Name.Length)); //pic.SmallPath = fileName + "_small" + imgExtention; //pic.Save(); }