object IExtractIcon.ExtractIcon(ExtractIconType type, Size desiredSize) { if (type == ExtractIconType.Thumbnail) { //// Have we already extracted the image? //if (cachedImage != null) // return cachedImage; // Do we support this extension? string ext = base.File.Extension.ToLowerInvariant(); if (ext == ".mif") { #if false using (Stream stream = base.File.OpenRead()) using (QQGame.MifImageDecoder mif = new QQGame.MifImageDecoder(stream)) { // TODO: should we dispose the original image??? Image img = mif.DecodeFrame().Image; return (Image)img.Clone(); } #else Stream stream = base.File.OpenRead(); QQGame.MifImage mif = new QQGame.MifImage(stream); mif.Name = base.File.Name; return mif; #endif } else if (ext == ".bmp" || ext == ".png") { using (Stream stream = base.File.OpenRead()) using (Bitmap bmp = new Bitmap(stream)) { // Make a copy of the bitmap, because MSDN says "You must // keep the stream open for the lifetime of the Bitmap." return bmp.Clone(); } } } return null; }
private void btnTest_Click(object sender, EventArgs e) { //if (true) //{ // Bitmap icon = Util.IO.Shell.GetExtensionIcon("bmp"); //} string path = @"D:\Games\QQGame\GameShow\item"; FileInfo[] files = (new DirectoryInfo(path)).GetFiles("*.mif"); int numFiles = 0; long totalSize = 0; long totalCompressed = 0; const int LoopCount = 0; const int FileLimit = 100; // Load and release all the files. Stopwatch watch = new Stopwatch(); foreach (FileInfo file in files) { numFiles++; totalSize += file.Length; using (Stream input = file.OpenRead()) using (MemoryStream memory = new MemoryStream()) { input.CopyTo(memory); memory.Seek(0, SeekOrigin.Begin); watch.Start(); using (QQGame.MifImage mif = new QQGame.MifImage(memory)) { totalCompressed += mif.CompressedSize; if (mif.FrameCount > 1) { for (int i = 0; i < mif.FrameCount * LoopCount; i++) mif.AdvanceFrame(true); } } watch.Stop(); } if (numFiles >= FileLimit) break; } string msg = ""; msg += string.Format( "Loaded {0} files in {1:0.000} seconds.\n", numFiles, watch.Elapsed.TotalSeconds); msg += string.Format( "Total size: {0:#,0} KB.\n", totalSize / 1024); msg += string.Format( "Memory size: {0:#,0} KB.\n", totalCompressed / 1024); System.Diagnostics.Debug.Write("\n" + msg); MessageBox.Show(msg); }
// NOTE: The following implementation duplicates with ImageFile. // We need to consolidate and remove one of them. object IExtractIcon.ExtractIcon(ExtractIconType type, Size desiredSize) { if (type == ExtractIconType.Thumbnail) { // Do we support this extension? string ext = Path.GetExtension( entry.FullName).ToLowerInvariant(); if (ext == ".mif") { using (Stream stream = entry.Open()) { QQGame.MifImage mif = new QQGame.MifImage(stream); mif.Name = entry.FullName; return mif; } } else if (ext == ".bmp" || ext == ".png") { using (Stream stream = entry.Open()) using (Bitmap bmp = new Bitmap(stream)) { // Make a copy of the bitmap, because MSDN says "You must // keep the stream open for the lifetime of the Bitmap." return bmp.Clone(); } } else if (ext == ".tga") { using (Stream stream = entry.Open()) using (TgaImage tga = new TgaImage(stream)) { // Make a copy of the bitmap so that we can dispose // the TgaImage object. return tga.Image.Clone(); } } } return null; }