BitMiracle.LibTiff.Classic.Tiff.ReadRGBAImageOriented C# (CSharp) Method

ReadRGBAImageOriented() public method

Reads the image and decodes it into RGBA format raster using specified raster origin.

ReadRGBAImageOriented reads a strip- or tile-based image into memory, storing the result in the user supplied RGBA raster. The raster is assumed to be an array of width times height 32-bit entries, where width must be less than or equal to the width of the image (height may be any non-zero size). If the raster dimensions are smaller than the image, the image data is cropped to the raster bounds. If the raster height is greater than that of the image, then the image data placement depends on orientation. Note that the raster is assumed to be organized such that the pixel at location (x, y) is raster[y * width + x]; with the raster origin specified by orientation parameter.

When ReadRGBAImageOriented is used with Orientation.BOTLEFT for the orientation the produced result is the same as retuned by O:BitMiracle.LibTiff.Classic.Tiff.ReadRGBAImage.

Raster pixels are 8-bit packed red, green, blue, alpha samples. The Tiff.GetR, Tiff.GetG, Tiff.GetB, and Tiff.GetA should be used to access individual samples. Images without Associated Alpha matting information have a constant Alpha of 1.0 (255).

ReadRGBAImageOriented converts non-8-bit images by scaling sample values. Palette, grayscale, bilevel, CMYK, and YCbCr images are converted to RGB transparently. Raster pixels are returned uncorrected by any colorimetry information present in the directory.

Samples must be either 1, 2, 4, 8, or 16 bits. Colorimetric samples/pixel must be either 1, 3, or 4 (i.e. SamplesPerPixel minus ExtraSamples).

Palette image colormaps that appear to be incorrectly written as 8-bit values are automatically scaled to 16-bits.

ReadRGBAImageOriented is just a wrapper around the more general TiffRgbaImage facilities.

All error messages are directed to the current error handler.

public ReadRGBAImageOriented ( int width, int height, int raster, Orientation orientation ) : bool
width int The raster width.
height int The raster height.
raster int The raster (the buffer to place decoded image data to).
orientation Orientation The raster origin position.
return bool
        public bool ReadRGBAImageOriented(int width, int height, int[] raster, Orientation orientation)
        {
            return ReadRGBAImageOriented(width, height, raster, orientation, false);
        }

Same methods

Tiff::ReadRGBAImageOriented ( int width, int height, int raster, Orientation orientation, bool stopOnError ) : bool

Usage Example

        private static (ProcessState state, SKImage image) ReadFullImage(T.Tiff tiff, ImageRequest request, bool allowSizeAboveFull)
        {
            int width  = tiff.GetField(T.TiffTag.IMAGEWIDTH)[0].ToInt();
            int height = tiff.GetField(T.TiffTag.IMAGELENGTH)[0].ToInt();

            var restag  = tiff.GetField(T.TiffTag.RESOLUTIONUNIT);
            var xrestag = tiff.GetField(T.TiffTag.XRESOLUTION);
            var yrestag = tiff.GetField(T.TiffTag.YRESOLUTION);

            var resunit = restag == null ? 2 : restag[0].ToShort();
            var xres    = xrestag == null ? 96 : xrestag[0].ToDouble();
            var yres    = yrestag == null ? 96 : yrestag[0].ToDouble();

            // pixels per metre
            if (resunit == 3)
            {
                xres = xres / 0.0254;
                yres = yres / 0.0254;
            }

            var isTileable = tiff.IsTiled();
            var state      = ImageRequestInterpreter.GetInterpretedValues(request, width, height, allowSizeAboveFull);

            state.HorizontalResolution = Convert.ToUInt16(xres);
            state.VerticalResolution   = Convert.ToUInt16(yres);
            var raster = new int[width * height];

            if (!tiff.ReadRGBAImageOriented(width, height, raster, T.Orientation.TOPLEFT))
            {
                throw new IOException("Unable to decode TIFF file");
            }
            using (var bmp = CreateBitmapFromPixels(raster, width, height))
            {
                var desiredWidth  = Math.Max(1, (int)Math.Round(state.RegionWidth * state.ImageScale));
                var desiredHeight = Math.Max(1, (int)Math.Round(state.RegionHeight * state.ImageScale));
                Log.Debug("Desired size {@DesiredWidth}, {@DesiredHeight}", desiredWidth, desiredHeight);

                var regionWidth  = state.RegionWidth;
                var regionHeight = state.RegionHeight;

                var srcRegion = SKRectI.Create(state.StartX, state.StartY, regionWidth, regionHeight);
                return(state, CopyImageRegion2(bmp, desiredWidth, desiredHeight, srcRegion));
            }
        }
All Usage Examples Of BitMiracle.LibTiff.Classic.Tiff::ReadRGBAImageOriented
Tiff