/// <summary> /// Loads a previously saved sprite sheet as a generic collection to be saved later /// </summary> /// <param name="b">bitmap containing sprites</param> /// <returns></returns> public static XCImageCollection Load( Bitmap b, Palette pal, int imgWid, int imgHei, int space) { XCImageCollection list = new XCImageCollection(); int cols = (b.Width + space) / (imgWid + space); int rows = (b.Height + space) / (imgHei + space); int num = 0; //Console.WriteLine("Image: {0},{1} -> {2},{3}", b.Width, b.Height, cols, rows); for (int i = 0; i < cols * rows; i++) { int x = (i % cols) * (imgWid + space); int y = (i / cols) * (imgHei + space); //Console.WriteLine("{0}: {1},{2} -> {3}", num, x, y, PckImage.Width); list.Add(LoadTile( b, num++, pal, x, y, imgWid, imgHei)); FireLoadingEvent(num, rows * cols); } list.Pal = pal; return(list); }
public static void Save( string directory, string file, XCImageCollection images, int bpp) { System.IO.BinaryWriter pck = new System.IO.BinaryWriter(System.IO.File.Create(directory + "/" + file + ".pck")); System.IO.BinaryWriter tab = new System.IO.BinaryWriter(System.IO.File.Create(directory + "/" + file + TAB_EXT)); if (bpp == 2) { ushort count = 0; foreach (XCImage img in images) { tab.Write((ushort)count); ushort encLen = (ushort)PckImage.EncodePck(pck, img); count += encLen; } } else { uint count = 0; foreach (XCImage img in images) { tab.Write((uint)count); uint encLen = (uint)PckImage.EncodePck(pck, img); count += encLen; } } pck.Close(); tab.Close(); }
/// <summary> /// Saves an image collection as a bmp sprite sheet /// </summary> /// <param name="file">output file name</param> /// <param name="collection">image collection</param> /// <param name="pal">Palette to color the images with</param> /// <param name="across">number of columns to use for images</param> public static void SaveBMP( string file, XCImageCollection collection, Palette pal, int across, int space) { if (collection.Count == 1) { across = 1; } int mod = 1; if (collection.Count % across == 0) { mod = 0; } Bitmap b = MakeBitmap( across * (collection.IXCFile.ImageSize.Width + space) - space, (collection.Count / across + mod) * (collection.IXCFile.ImageSize.Height + space) - space, pal.Colors); for (int i = 0; i < collection.Count; i++) { int x = i % across * (collection.IXCFile.ImageSize.Width + space); int y = i / across * (collection.IXCFile.ImageSize.Height + space); Draw(collection[i].Image, b, x, y); } Save(file, b); }
public override void SaveCollection( string directory, string file, XCom.XCImageCollection images) { codec.SaveCollection( directory, file, images); }
public static void Save( string directory, string file, string ext, XCImageCollection images) { System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(directory + "/" + file + ext)); foreach (XCImage tile in images) { bw.Write(tile.Bytes); } bw.Flush(); bw.Close(); }
private void openItem_Click(object sender, System.EventArgs e) { if (openFile.ShowDialog() == DialogResult.OK) { OnResize(null); string fName = openFile.FileName.Substring(openFile.FileName.LastIndexOf("/") + 1).ToLower(); string ext = fName.Substring(fName.LastIndexOf(".")); string file = fName.Substring(0, fName.LastIndexOf(".")); string path = openFile.FileName.Substring(0, openFile.FileName.LastIndexOf("/") + 1); XCom.XCImageCollection toLoad = null; bool recover = false; // remove saving - there are too many formats and stuff, // I will implement only one type of direct saving. _currentFilePath = null; SaveMenuItem.Visible = false; //Console.WriteLine(openFile.FilterIndex+" -> " + filterIndex[openFile.FilterIndex].GetType()); #if !DEBUG try { #endif IXCImageFile filterIdx = openDictionary[openFile.FilterIndex]; //filterIndex[openFile.FilterIndex]; if (filterIdx.GetType() == typeof(xcForceCustom)) // special case { toLoad = filterIdx.LoadFile(path, fName); recover = true; } else if (filterIdx.GetType() == typeof(xcCustom)) // for *.* files, try singles and then extensions { // try singles foreach (XCom.Interfaces.IXCImageFile ixf in loadedTypes.AllLoaded) { if (ixf.SingleFileName != null && ixf.SingleFileName.ToLower() == fName.ToLower()) { try { toLoad = ixf.LoadFile(path, fName); break; } catch {} } } if (toLoad == null) // singles not loaded, try non singles { foreach (XCom.Interfaces.IXCImageFile ixf in loadedTypes.AllLoaded) { if (ixf.SingleFileName == null && ixf.FileExtension.ToLower() == ext.ToLower()) { try { toLoad = ixf.LoadFile(path, fName); break; } catch {} } } if (toLoad == null) // nothing loaded, force the custom dialog { toLoad = xcCustom.LoadFile(path, fName, 0, 0); } } } else { toLoad = LoadImageCollection(filterIdx, path, fName); } #if !DEBUG } catch (Exception ex) { if (MessageBox.Show( this, "Error loading file: " + fName + "\nPath: " + openFile.FileName + "\nError loading file, do you wish to try and recover?\n\nError Message: " + ex + ":" + ex.Message, "Error loading file", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes) { toLoad = xcCustom.LoadFile(path, fName, 0, 0); recover = true; } } #endif if (!recover && toLoad != null) { SetImages(toLoad); UpdateText(); } } }
public static void Save(string outFile, XCImageCollection images) { }