Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help! #112

Open
wangmuzhi126 opened this issue Sep 14, 2024 · 0 comments
Open

Help! #112

wangmuzhi126 opened this issue Sep 14, 2024 · 0 comments

Comments

@wangmuzhi126
Copy link

using the following code i can got a tif picture but i can't open it .

using (Tiff input = Tiff.Open(@"C:\Users\11370\Desktop\2024-09-13-14-05-16\RES\sti.tif", "r"))
{
input.SetDirectory(0);
int width = input.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
int height = input.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
int tileWidth = input.GetField(TiffTag.TILEWIDTH)[0].ToInt();
int tileLentgh = input.GetField(TiffTag.TILELENGTH)[0].ToInt();

            int samplesPerPixel = input.GetField(TiffTag.SAMPLESPERPIXEL)[0].ToInt();
            int bitsPerSample = input.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();
            int photo = input.GetField(TiffTag.PHOTOMETRIC)[0].ToInt();

            int tiles = 0;
            int tileSize = input.TileSize();
            byte[][] buffer = new byte[tileSize][];


            for (int y = 0; y < height; y += tileLentgh)
            {
                for (int x = 0; x < width; x += tileWidth)
                {
                    buffer[tiles] = new byte[tileSize];
                    input.ReadTile(buffer[tiles], 0, x, y, 0, 0);
                    tiles++;
                }
            }

            // writing
            using (Tiff output = Tiff.Open("output.tif", "w"))
            {

                output.SetField(TiffTag.TILEWIDTH, tileWidth);
                output.SetField(TiffTag.TILELENGTH, tileLentgh);
                output.SetField(TiffTag.TILEDEPTH, 1);

                output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                output.SetField(TiffTag.IMAGEWIDTH, width);
                output.SetField(TiffTag.IMAGELENGTH, height);
                output.SetField(TiffTag.BITSPERSAMPLE, bitsPerSample);
                //output.SetField(TiffTag.ROWSPERSTRIP, output.DefaultStripSize(0));
                output.SetField(TiffTag.PHOTOMETRIC, photo);
                output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);

                int c = 0;

                for (int y = 0; y < height; y += tileLentgh)
                {
                    for (int x = 0; x < width; x += tileWidth)
                    {
                        output.WriteTile(buffer[c], x, y, 0, 0);
                        c++;
                    }
                }
            }
        }
        System.Diagnostics.Process.Start("output.tif");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants