I want to convert tiff image using LibTiff.Net, I already did that but having an black line on top of every bitmap, so am I missing something here?
private static Bitmap GetBitmapForTiffImage(
IStreamSource streamSource,
Rect sourceRectangle)
{
// Create a TIFF image from the stream source.
using var tiffImage = CreateTiffImageFromStream(streamSource);
if (tiffImage == null)
return null;
// Extract coordinates and dimensions of the source rectangle.
var sourceX = sourceRectangle.Left;
var sourceY = sourceRectangle.Top;
var sourceWidth = sourceRectangle.Width();
var sourceHeight = sourceRectangle.Height();
// Create Android Bitmap with specified dimensions and configuration.
var config = Bitmap.Config.Argb8888;
if (config == null)
return null;
var bitmap = Bitmap.CreateBitmap(sourceWidth, sourceHeight, config);
// Now Reading TIFF image into Bitmap.
// Buffer to hold scanline data from the TIFF image.
var scanline = new byte[tiffImage.ScanlineSize()];
// Iterate through each row of the source rectangle.
var destY = 0;
for (var y = sourceY; y < sourceY + sourceHeight; y++)
{
// Read the scanline data from the TIFF image.
tiffImage.ReadScanline(scanline, y);
var destX = 0;
// Iterate through each pixel in the current row.
for (var x = sourceX; x < sourceX + sourceWidth; x++)
{
// Assuming 3 bytes per pixel (RGB).
var index = x * 3;
// Extract RGB components from the scanline buffer and create a color.
var pixelColor = Color.Argb(255, scanline[index], scanline[index + 1], scanline[index + 2]);
// Set the pixel color in the Bitmap at the current coordinates.
bitmap.SetPixel(destX, destY, pixelColor);
destX++;
}
destY++;
}
return bitmap;
}
I already tried changing coordinates and play with loop. Rect values are perfect.
How can I handle that black line that’s irritating.