Exemple #1
0
        public static void CreateGrayScaleTiff(TiffInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (info.Buffer == null || info.Buffer.Length <= 0)
            {
                throw new ArgumentNullException("info.Buffer");
            }
            if (string.IsNullOrWhiteSpace(info.FilePath))
            {
                throw new ArgumentNullException("info.FilePath");
            }
            using (var image = BitMiracle.LibTiff.Classic.Tiff.Open(info.FilePath, WriteMode))
            {
                SetTiffField(info, image);

                int    bytesPerRow = info.Width * sizeof(ushort);
                byte[] tempBuffer  = new byte[bytesPerRow];

                for (int i = 0; i < info.Height; i++)
                {
                    Buffer.BlockCopy(info.Buffer, i * bytesPerRow, tempBuffer, 0, bytesPerRow);
                    image.WriteScanline(tempBuffer, i);
                }
            }
        }
Exemple #2
0
        private static void SetTiffField(TiffInfo info, BitMiracle.LibTiff.Classic.Tiff image)
        {
            if (image == null)
            {
                throw new NullReferenceException("image");
            }

            // We need to set some values for basic tags before we can add any data
            image.SetField(TiffTag.IMAGEWIDTH, info.Width);
            image.SetField(TiffTag.IMAGELENGTH, info.Height);
            image.SetField(TiffTag.BITSPERSAMPLE, info.BitsPerSample);
            image.SetField(TiffTag.SAMPLESPERPIXEL, info.SamplesPerPixel);
            image.SetField(TiffTag.ORIENTATION, info.Orientation);
            image.SetField(TiffTag.ROWSPERSTRIP, info.Height);
            image.SetField(TiffTag.XRESOLUTION, info.XResolution);
            image.SetField(TiffTag.YRESOLUTION, info.YResolution);
            image.SetField(TiffTag.RESOLUTIONUNIT, info.ResolutionUnit);
            image.SetField(TiffTag.PLANARCONFIG, info.PlanarConfig);
            image.SetField(TiffTag.PHOTOMETRIC, info.Photometric);
            image.SetField(TiffTag.COMPRESSION, info.Compression);
            image.SetField(TiffTag.FILLORDER, info.FillOrder);
        }