コード例 #1
0
        public static void Generate(string path, string mimeType)
        {
            HostingEnvironment.QueueBackgroundWorkItem(cancellationToken =>
            {
                try
                {
                    using (var f = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                        using (var image = System.Drawing.Image.FromStream(f))
                            using (var file = File.Open(Path.Combine(BaseDirectory, Path.GetFileName(path)), FileMode.CreateNew, FileAccess.Write, FileShare.Read))
                            {
                                f.Seek(0, SeekOrigin.Begin);
                                var stream = new ThumbnailSharp.ThumbnailCreator()
                                             .CreateThumbnailStream((uint)Math.Min(image.Width, ThumbnailSize), f, GetFormat(mimeType));

                                if (stream != null)
                                {
                                    stream.CopyTo(file);
                                }

                                file.Flush();
                            }
                }
                catch
                {
                }
            });
        }
コード例 #2
0
        public static void Update(string path, string mimeType)
        {
            HostingEnvironment.QueueBackgroundWorkItem(cancellationToken =>
            {
                using (var f = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                    using (var file = File.Open(Path.Combine(BaseDirectory, Path.GetFileName(path)), FileMode.Truncate | FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
                    {
                        var stream = new ThumbnailSharp.ThumbnailCreator()
                                     .CreateThumbnailStream(ThumbnailSize, f, GetFormat(mimeType));

                        if (stream != null)
                        {
                            stream.CopyTo(file);
                        }

                        file.Flush();
                    }
            });
        }