//Load grid and return as 2d Grids public static GridList GifToGrids(string filename) { #if !NET2 GridList grids = new GridList(); // Open a Stream and decode a GIF image Stream imageStreamSource = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); var decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); decoder.Frames[0].Metadata.Freeze(); int width = GetMaxX(decoder); int height = GetMaxY(decoder); foreach (BitmapFrame frame in decoder.Frames) { frame.Freeze(); // Get a clone copy of the metadata var sourceMetadata = frame.Metadata as BitmapMetadata; int top = Int32.Parse(sourceMetadata.GetQuery("/imgdesc/Top").ToString()); int left = Int32.Parse(sourceMetadata.GetQuery("/imgdesc/Left").ToString()); Grid grid = new Grid(width, height, 1, 4); CopyBitmapSourceToGridPalette(frame, grid, top, left); grids.AddGrid(grid); } return(grids); #else return(null); #endif }
//Generates a set of thumbnails of the codeString, down to 1 pixels size public static GridList CodeToThumbnailed(Code code) { GridList gridList = new GridList(); Grid grid = CodeConverter.CodeToGrid(code.codeString); int toX = grid.SizeX; int toY = grid.SizeY; int toZ = grid.SizeZ; while ((toX > 0) && (toY > 0) && (toZ > 0)) { Code newCode = CodeConverter.CodeToRescaledCode(code, toX, toY, toZ); Grid newGrid = CodeConverter.CodeToGrid(newCode.codeString); gridList.AddGrid(newGrid); toX /= 2; toY /= 2; toZ /= 2; } return(gridList); }