public ReadRGBATile ( int col, int row, int raster ) : bool | ||
col | int | The column. |
row | int | The row. |
raster | int | The RGBA raster. |
return | bool |
//Displays the specified tiff in the picturebox private bool displayTiff(string tiffname) { int[] raster = new int[tileSize]; try { using (image = Tiff.Open(tiffname, "r")) { //loop through each tile column for (int g = 0; g < bmp.Width / tileWidth + 1; g++) { //loop through each tile in that column for (int h = 0; h < bmp.Height / tileHeight + 1; h++) { image.ReadRGBATile(tileWidth * g, tileHeight * h, raster); //loop through each pixel column for (int i = 0; i < tileWidth; i++) { //loop through each pixel in that column for (int j = 0; j < tileHeight; j++) { if ((g * tileWidth + i < bmp.Width) && (h * tileHeight + j < bmp.Height)) { bmp.SetPixel(g * tileWidth + i, h * tileHeight + j, getSample(i, j, raster, tileWidth, tileHeight)); } } } } } pictureBox1.Image = bmp; return true; } } catch (Exception e) { MessageBox.Show(e.Message); return false; } }
static bool cvt_by_tile(Tiff inImage, Tiff outImage, int width, int height) { int tile_width = 0; int tile_height = 0; FieldValue[] result = inImage.GetField(TiffTag.TILEWIDTH); if (result != null) { tile_width = result[0].ToInt(); result = inImage.GetField(TiffTag.TILELENGTH); if (result != null) tile_height = result[0].ToInt(); } if (result == null) { Tiff.Error(inImage.FileName(), "Source image not tiled"); return false; } outImage.SetField(TiffTag.TILEWIDTH, tile_width); outImage.SetField(TiffTag.TILELENGTH, tile_height); // Allocate tile buffer int raster_size = multiply(tile_width, tile_height); int rasterByteSize = multiply(raster_size, sizeof(int)); if (raster_size == 0 || rasterByteSize == 0) { Tiff.Error(inImage.FileName(), "Can't allocate buffer for raster of size {0}x{1}", tile_width, tile_height); return false; } int[] raster = new int[raster_size]; byte[] rasterBytes = new byte[rasterByteSize]; // Allocate a scanline buffer for swapping during the vertical mirroring pass. // (Request can't overflow given prior checks.) int[] wrk_line = new int[tile_width]; // Loop over the tiles. for (int row = 0; row < height; row += tile_height) { for (int col = 0; col < width; col += tile_width) { // Read the tile into an RGBA array if (!inImage.ReadRGBATile(col, row, raster)) return false; // For some reason the ReadRGBATile() function chooses the lower left corner // as the origin. Vertically mirror scanlines. for (int i_row = 0; i_row < tile_height / 2; i_row++) { int topIndex = tile_width * i_row * sizeof(int); int bottomIndex = tile_width * (tile_height - i_row - 1) * sizeof(int); Buffer.BlockCopy(raster, topIndex, wrk_line, 0, tile_width * sizeof(int)); Buffer.BlockCopy(raster, bottomIndex, raster, topIndex, tile_width * sizeof(int)); Buffer.BlockCopy(wrk_line, 0, raster, bottomIndex, tile_width * sizeof(int)); } // Write out the result in a tile. int tile = outImage.ComputeTile(col, row, 0, 0); Buffer.BlockCopy(raster, 0, rasterBytes, 0, rasterByteSize); if (outImage.WriteEncodedTile(tile, rasterBytes, rasterByteSize) == -1) return false; } } return true; }