I'm using BitMiracle's LibTiff.Net to read in a Bitmap image and return a TIFF byte[] that gets embedded in a file as a Base64String. I've noticed that the Base64 string ends up being quite a bit longer than I expect, the tail end of which is a large number of 'A' characters. While debugging, I see that the byte[] that LibTiff is returning to me has several thousand 0 values at the end that don't seem to be a necessary part of the image itself (so far as I can tell).
I'm using BitMiracle's sample code here to convert: https://bitmiracle.github.io/libtiff.net/html/075f57db-d779-48f7-9fd7-4ca075a01599.htm
I can't quite see what would cause "garbage" at the end of the byte[], though. Any thoughts?
Edit to add code - GetTiffImageBytes() is in the link above:
public void GenImage()
using (System.Drawing.Image frontImage = System.Drawing.Image.FromStream(file))//;
{
file.Close();
//Draw something
b = new Bitmap(frontImage);
Graphics graphics = Graphics.FromImage(b);
graphics.DrawString(data1, (Font)GlobalDict.FontDict["font1"], Brushes.Black, 200, 490);
graphics.DrawString(data2, (Font)GlobalDict.FontDict["font2"], Brushes.Black, 680, 400);
}
//Convert to TIF - requires BitMiracle.LibTiff.Classic
byte[] tiffBytes = GetTiffImageBytes(b, false);
return tiffBytes;
}
The above is called by:
byte[] aFrontImage = MiscTools.GenImage(somestuff);
fileXML.WriteLine(" <FrontImage>" + System.Convert.ToBase64String(aFrontImage, 0, aFrontImage.Length) + "</FrontImage>");
All things said and done, it functions fine, the resulting images are readable by our application. I'm just trying to pare down the size since some of these files may have tens of thousands of images. I have some older sample files that were created by hand with some Base64 strings via another method that are about the same size strings, save all the tailing bytes that I'm thinking are garbage.
As someone commented, one option may be to just read the byte[] and remove all 0 values from the end prior to converting, but I'm trying to figure out why it's happening to begin with.
Thanks!