/// <summary> /// 获得头像缩略图流 /// </summary> /// <param name="fileId">文件信息ID(Base_Article中的ID)</param> /// <param name="thumbnailSize">缩略图大小</param> /// <returns>缩略图流</returns> public Stream GetSysAvatarThumbnail(int fileId) { Stream targetStream = null; var myArticle = SiteManager.Kernel.Get <EFAuditDataService <Base_Article> >(); var art = myArticle.GetQuery().Include(a => a.Exts).FirstOrDefault(a => a.Id == fileId); var filekeyId = Catalog.GetExtByName(Catalog.GetRootId(), SystemTypes.Root.Key).Id; var filekey = art.Exts.FirstOrDefault(e => e.CatlogExtId == filekeyId).Value; Stream sourceStream = StreamCache[filekey]; if (sourceStream == null) { return(null); } targetStream = FileExtensionTypeHelper.GetThumbnail(sourceStream, ThumbnailSize.Large); //所以要手动释放 //sourceStream.Flush(); //sourceStream.Close(); //targetStream.Position = 0; sourceStream.Position = 0; return(sourceStream); }
/// <summary> /// 获得文件缩略图流 /// </summary> /// <param name="fileId">文件信息ID</param> /// <param name="thumbnailSize">缩略图大小</param> /// <returns>缩略图流</returns> public Stream GetFileThumbnail(int fileId, Size thumbnailSize) { Stream targetStream = null; Stream sourceStream = GetFileStream(fileId); if (sourceStream == null) { return(null); } targetStream = FileExtensionTypeHelper.GetThumbnail(sourceStream, thumbnailSize); //所以要手动释放 sourceStream.Flush(); sourceStream.Close(); targetStream.Position = 0; return(targetStream); }
/// <summary> /// 获得文件缩略图流 /// </summary> /// <param name="id">文件信息ID</param> /// <param name="thumbnailSize">缩略图大小</param> /// <returns>缩略图流</returns> public Stream GetThumbnail(DirectoryInfo directoryInfo, string key, Size thumbnailSize) { Stream targetStream = null; DiskFileInfo info = Get(directoryInfo, key); if (info == null) { return(null); } Stream sourceStream = info.FileStream; if (sourceStream == null) { return(null); } targetStream = FileExtensionTypeHelper.GetThumbnail(sourceStream, thumbnailSize); //所以要手动释放 sourceStream.Flush(); sourceStream.Close(); return(targetStream); }