Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (Tiff tiff = Tiff.Open(@"TestN41E071_dem.tif", r"))
- {
- int width = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
- int height = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
- double dpiX = tiff.GetField(TiffTag.XRESOLUTION)[0].ToDouble();
- double dpiY = tiff.GetField(TiffTag.YRESOLUTION)[0].ToDouble();
- byte[] scanline = new byte[tiff.ScanlineSize()];
- ushort[] scanline16Bit = new ushort[tiff.ScanlineSize() / 2];
- for (int i = 0; i < height; i++)
- {
- tiff.ReadScanline(scanline, i); //Loading ith Line
- MultiplyScanLineAs16BitSamples(scanline, scanline16Bit, 16,i);
- }
- }
- private static void MultiplyScanLineAs16BitSamples(byte[] scanline, ushort[] temp, ushort factor,int row)
- {
- if (scanline.Length % 2 != 0)
- {
- // each two bytes define one sample so there should be even number of bytes
- throw new ArgumentException();
- }
- Buffer.BlockCopy(scanline, 0, temp, 0, scanline.Length);
- for (int i = 0; i < temp.Length; i++)
- {
- temp[i] *= factor;
- MessageBox.Show("Row:"+row.ToString()+"Column:"+(i/2).ToString()+"Value:"+temp[i].ToString());
- }
- }
- int buffersize = 1000000;
- using (Tiff tiff = Tiff.Open(geotifffile, "r"))
- {
- int nooftiles = tiff.GetField(TiffTag.TILEBYTECOUNTS).Length;
- int width = tiff.GetField(TiffTag.TILEWIDTH)[0].ToInt();
- int height = tiff.GetField(TiffTag.TILELENGTH)[0].ToInt();
- byte[] buffer = new byte[buffersize];
- for (int i = 0; i < nooftiles; i++)
- {
- int size = tiff.ReadEncodedTile(i, buffer, 0, buffersize);
- float[,] data = new float[width, height];
- Buffer.BlockCopy(buffer, 0, data, 0, size); // Convert byte array to x,y array of floats (height data)
- // Do whatever you want with the height data (calculate hillshade images etc.)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement