示例#1
0
 public void SaveThumbnailToDisk(Thumbnail thumbnail, string location)
 {
     File.WriteAllBytes(Path.Combine(location, thumbnail.Name + "." + thumbnail.Format), thumbnail.ThumbnailData);
 }
示例#2
0
        public Thumbnail GetThumbnailPhoto(string username, Format format)
        {
            byte[] bytes;

            var result = GetUser(username);

            if (result == null)
            {
                return(null);
            }

            using (var user = result.GetUnderlyingObject() as DirectoryEntry)
            {
                bytes = user.Properties["thumbnailPhoto"].Value as byte[];
            }

            if (bytes == null)
            {
                return(null);
            }

            using (var inStream = new MemoryStream(bytes))
                using (var outStream = new MemoryStream())
                {
                    using (var imageFactory = new ImageFactory())
                    {
                        const int imageQuality = 95;

                        imageFactory.Load(inStream);

                        switch (format)
                        {
                        case Format.Jpg:
                            imageFactory.Format(new JpegFormat());
                            break;

                        case Format.Png:
                            imageFactory.Format(new PngFormat());
                            break;

                        case Format.Gif:
                            imageFactory.Format(new GifFormat());
                            break;

                        case Format.Bmp:
                            imageFactory.Format(new BitmapFormat());
                            break;
                        }

                        imageFactory.Quality(imageQuality);
                        imageFactory.Save(outStream);
                    }

                    outStream.Position = 0;

                    var thumbnail = new Thumbnail()
                    {
                        Name          = username,
                        Format        = format,
                        ThumbnailData = outStream.ToArray()
                    };

                    return(thumbnail);
                }
        }
示例#3
0
 public void SaveThumbnailToDisk(Thumbnail thumbnail)
 {
     File.WriteAllBytes(thumbnail.Name + "." + thumbnail.Format, thumbnail.ThumbnailData);
 }