public static void endFileTmp(PngWriter png) { ImageLine imline = new ImageLine(png.ImgInfo); for (int i = 0; i < png.ImgInfo.Rows; i++) png.WriteRow(imline, i); png.End(); }
public static void fatalError(String s, PngReader png1, PngWriter png2) { try { png1.End(); png2.End(); } catch (Exception ) { } throw new PngjException(s); }
private void btnSave_Click( object sender, RoutedEventArgs e ) { CommonSaveFileDialog saveDialog = new CommonSaveFileDialog(); saveDialog.ShowPlacesList = true; saveDialog.AddToMostRecentlyUsedList = true; saveDialog.Filters.Add( new CommonFileDialogFilter( "PNG images", "*.png" ) ); saveDialog.DefaultFileName = DateTime.Now.ToString( "yyyyMMddhhmmss" ) + ".png"; if ( saveDialog.ShowDialog( this ) == CommonFileDialogResult.Ok ) { using ( FileStream newFileStream = new FileStream( saveDialog.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite ), oldFileStream = new FileStream( soureFilePath, FileMode.Open, FileAccess.Read ) ) { string semanticInfo = @" sky: blue sky. heart: cloud heart. Meaning: It means love|爱|❤. "; ////// Reference: http://code.google.com/p/pngcs/wiki/Overview // get decoder pngReader = new PngReader( oldFileStream ); // create encoder pngWriter = new PngWriter( newFileStream, pngReader.ImgInfo ); // copy int chunkBehav = Hjg.Pngcs.Chunks.ChunkCopyBehaviour.COPY_ALL; // tell to copy all 'safe' chunks pngWriter.CopyChunksFirst( pngReader, chunkBehav ); // copy some metadata from reader int channels = pngReader.ImgInfo.Channels; if ( channels < 3 ) throw new Exception( "This example works only with RGB/RGBA images" ); for ( int row = 0; row < pngReader.ImgInfo.Rows; row++ ) { ImageLine l1 = pngReader.ReadRow( row ); // format: RGBRGB... or RGBARGBA... pngWriter.WriteRow( l1, row ); } pngWriter.CopyChunksLast( pngReader, chunkBehav ); // metadata after the image pixels? can happen // app info pngWriter.GetMetadata().SetText( Hjg.Pngcs.Chunks.PngChunkTextVar.KEY_Software, "Semantic Image" ); // semantic info Hjg.Pngcs.Chunks.PngChunk chunk = pngWriter.GetMetadata().SetText( Key_SemanticInfo, semanticInfo, false, false ); chunk.Priority = true; pngWriter.End(); // dont forget this pngReader.End(); oldFileStream.Close(); newFileStream.Close(); } } }
public override void Work() { MapCanvasTile[,] tiles = canvas.Images; int rowCount = tiles.GetLength(1); int colCount = tiles.GetLength(0); ImageInfo info = new ImageInfo((colCount * canvas.MaxTiles) * 256, (rowCount * canvas.MaxTiles) * 256, 8, false); PngWriter writer = new PngWriter(File.OpenWrite(fileName), info); int lineOfs = 0; int tileLines = 256 * canvas.MaxTiles; int canvasCols = (colCount * canvas.MaxTiles) * 256; for (int tileY = 0; tileY < rowCount; tileY++) { Color[,] rows = new Color[tileLines, canvasCols]; for (int tileX = 0; tileX < colCount; tileX++) { List<MapCanvasTile.SubTile> subTiles = tiles[tileX, tileY].tiles; subTiles.Sort((a, b) => a.CompareTo(b)); for (int subTileY = 0; subTileY < canvas.MaxTiles; subTileY++) { for (int subTileX = 0; subTileX < canvas.MaxTiles; subTileX++) { int subTileIndex = (subTileX * canvas.MaxTiles) + subTileY; if (subTileIndex < subTiles.Count) { using (BlpFile blp = new BlpFile(File.OpenRead(subTiles[subTileIndex].File))) using (Bitmap bmp = blp.GetBitmap(0)) { for (int pY = 0; pY < 256; pY++) for (int pX = 0; pX < 256; pX++) rows[pY + (subTileY * 256), pX + (subTileX * 256) + (tileX * (256 * canvas.MaxTiles))] = bmp.GetPixel(pX, pY); } } } } } for (int iLine = 0; iLine < tileLines; iLine++) { byte[] compRow = new byte[canvasCols * 3]; for (int iCol = 0; iCol < canvasCols; iCol++) { Color color = rows[iLine, iCol]; int ofs = 3 * iCol; compRow[ofs] = color.R; compRow[ofs + 1] = color.G; compRow[ofs + 2] = color.B; } writer.WriteRowByte(compRow, lineOfs); lineOfs++; } } writer.End(); EventManager.Trigger_MapExportDone2D(); }