public static ThumbData ReadFromFile(string path) { if (!System.IO.File.Exists(path)) { throw new System.ApplicationException("ファイルが存在していません。"); } ThumbData ret = new ThumbData(); Bitmap bmp = new Bitmap(path); ret.width = bmp.Width; ret.height = bmp.Height; ret.aspect = ret.width / (float)ret.height; Bitmap thumb = new Bitmap(bmp.GetThumbnailImage(WIDTH, HEIGHT, delegate(){ return(true); }, System.IntPtr.Zero)); Img::BitmapData bmpdat = thumb.LockBits(rect88, System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); long * d = (long *)ret.px; long * M = (long *)(ret.px + PIXELS); long * s = (long *)bmpdat.Scan0; while (d < M) { *d++ = *s++; } thumb.UnlockBits(bmpdat); thumb.Dispose(); bmp.Dispose(); return(ret); }
/// <summary> /// サムネイルの内容を更新します。 /// </summary> public void Update() { System.TimeSpan span = new System.IO.FileInfo(filepath).LastWriteTimeUtc - this.lastwrite; if (span.Ticks / System.TimeSpan.TicksPerSecond <= 2) { return; } this.data = ThumbData.ReadFromFile(filepath); this.lastwrite = new System.IO.FileInfo(filepath).LastWriteTimeUtc; }
//============================================================ // 比較 //============================================================ public static bool EqualAspect(Image img1, Image img2) { return(ThumbData.EqualAspect(img1.thm.data, img2.thm.data)); }
public static bool EqualAspect(ThumbData l, ThumbData r) { return(System.Math.Abs(l.aspect / r.aspect - 1) <= 0.01); }