WPF Cover Flow Tutorial : Part 7 (source)
来源:互联网 发布:淘宝网唢呐哨盒 编辑:程序博客网 时间:2024/05/01 07:33
Before disclosing sources of Part 7, here a few notes.
I provide a sample ThumbnailManager, working with an IsolatedStorageFile.I deal with host names because I am also working on an implementation dealing with many shares on the network. The GetThumbnail method just resizes pictures.For the sample videos on youtube, I downloaded many covers from amazon. That's why I need the helper function that removes the blank frame around the picture:Well this whole class is not perfect code, but it is sufficient for a demo.
If you do not know innerings of IsolatedStorage, you will find the thumbnails in a folder like C:\Documents and Settings\ded\Local Settings\Application Data\IsolatedStorage\0ypqvhod.rll\j4pydd3v.g4v\StrongName.alr3sbzvfezz2fk22sd5g0b5dxbwzr0b\AssemFiles.
Here is the source.
I provide a sample ThumbnailManager, working with an IsolatedStorageFile.
- public class ThumbnailManager : IThumbnailManager
- {
- #region Fields
- private readonly IsolatedStorageFile store;
- #endregion
- public ThumbnailManager()
- {
- store = IsolatedStorageFile.GetUserStoreForAssembly();
- }
- public ImageSource GetThumbnail(string host, string path)
- {
- string thumbName = Path.GetFileName(path);
- if (store.GetFileNames(thumbName).Length == 0)
- {
- using (var stream = new IsolatedStorageFileStream(thumbName, FileMode.CreateNew, store))
- {
- byte[] data = GetThumbnail(path);
- stream.Write(data, 0, data.Length);
- }
- }
- using (var stream = new IsolatedStorageFileStream(thumbName, FileMode.Open, store))
- {
- var image = new BitmapImage();
- image.BeginInit();
- image.CacheOption = BitmapCacheOption.OnLoad;
- image.StreamSource = stream;
- image.EndInit();
- image.Freeze();
- return image;
- }
- }
- }
- private byte[] GetThumbnail(string path)
- {
- Image source = Image.FromFile(path);
- source = AmazonCut(source);
- int height = source.Height;
- int width = source.Width;
- int factor = (height - 1) / 250 + 1;
- int smallHeight = height / factor;
- int smallWidth = width / factor;
- Image thumb = source.GetThumbnailImage(smallWidth, smallHeight, null, IntPtr.Zero);
- using (var ms = new MemoryStream())
- {
- thumb.Save(ms, ImageFormat.Png);
- ms.Flush();
- ms.Seek(0, SeekOrigin.Begin);
- var result = new byte[ms.Length];
- ms.Read(result, 0, (int)ms.Length);
- return result;
- }
- }
- private static Image AmazonCut(Image image)
- {
- if (image.Width != image.Height)
- return image;
- var bmp = new Bitmap(image);
- int size = image.Height;
- int white = System.Drawing.Color.FromKnownColor(KnownColor.White).ToArgb();
- int i = 0;
- while (i < size / 2)
- {
- if (bmp.GetPixel(i, i).ToArgb() != white)
- break;
- if (bmp.GetPixel(i, size - 1 - i).ToArgb() != white)
- break;
- if (bmp.GetPixel(size - 1 - i, i).ToArgb() != white)
- break;
- if (bmp.GetPixel(size - 1 - i, size - 1 - i).ToArgb() != white)
- break;
- i++;
- }
- if (i > 0)
- {
- i += 8;
- var zone = new Rectangle(i, i, size - 2 * i, size - 2 * i);
- return bmp.Clone(zone, System.Drawing.Imaging.PixelFormat.DontCare);
- }
- return bmp;
- }
If you do not know innerings of IsolatedStorage, you will find the thumbnails in a folder like C:\Documents and Settings\ded\Local Settings\Application Data\IsolatedStorage\0ypqvhod.rll\j4pydd3v.g4v\StrongName.alr3sbzvfezz2fk22sd5g0b5dxbwzr0b\AssemFiles.
Here is the source.
- WPF Cover Flow Tutorial : Part 7 (source)
- WPF Cover Flow Tutorial : Part 7
- WPF Cover Flow Tutorial : Part 1
- WPF Cover Flow Tutorial : Part 2
- WPF Cover Flow Tutorial : Part 3
- WPF Cover Flow Tutorial : Part 4
- WPF Cover Flow Tutorial : Part 5
- WPF Cover Flow Tutorial : Part 6
- WPF Cover Flow Tutorial : Part 6 (bis)
- Cover Flow编程1118
- Cover Flow布局
- Cover Flow 期待已久!
- Android下Cover Flow(1)
- Android OpenGL Gallery Cover Flow
- Cover Flow特效实现(1)
- Cover Flow特效实现(2)
- Storyboards Tutorial in iOS 7: Part 2
- iphone基础之前篇:Cover Flow
- openSUSE SDB:配置显卡
- 学习tomcat安装服务脚本
- SQL Server改变自增列字段的初始值
- x&(x-1)含义
- i2c设备驱动实例分析-pca9541(下)
- WPF Cover Flow Tutorial : Part 7 (source)
- VS2005水晶报表的横向打印问题
- Android-接受来自Appwidget的广播、更新Appwidget控件的状态
- MySQL技术专场沙龙--LAMP人第十八期活动
- 【原创】类的交叉使用。
- 读《Javascript高级程序设计》中的javascript事件处理程序(事件侦听器)心得
- 泡MM的android小程序
- Linux进程线程学习笔记:进程创建
- 使用Navicat for Oracle工具连接oracle