Most of the bitmaps I add display correctly, however, there seems to be a certain dot height that leaves the images looking skewed.
For Example: (All Images heights are in Screen Pixels (96 DPI) and the DPIs represent the DPI the Bitmap is created with)
- 43 Height at 120DPI (53.75 dots)
- 17 Height at 300DPI (53.125 dots)
- 08 Height at 600DPI (50 dots)
All display incorrectly, while
- 44 Height at 120DPI (55 dots)
- 18 Height at 300DPI (56.25 dots)
- 09 Height at 600DPI (56.25 dots)
All display correctly.
I am creating bitmaps at runtime and are adding them to the pdf afterwards.
Here's the code I'm using to add the Bitmaps to the PDF. When I save them to an external file right before the memory stream, the bitmaps are correct
Code: Select all
private bool AddImageToPage(Bitmap bmp, ref IacPage page, string sImageName, int iLeftTwips, int iTopTwips, int iRightTwips, int iBottomTwips, bool bMakeTransparent, bool bMakeGray)
{
Bitmap bmpToDraw = bmp;
if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
bmpToDraw = ConvertToFormat24bppRgb(bmp);
using (IacObject imageObject = page.CreateObject(IacObjectType.acObjectTypePicture, sImageName))
{
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.CommonAttributes.TOP).Value = iTopTwips;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.CommonAttributes.LEFT).Value = iLeftTwips;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.CommonAttributes.RIGHT).Value = iRightTwips;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.CommonAttributes.BOTTOM).Value = iBottomTwips;
if (bMakeTransparent)
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.RGB_MASK).Value = 0x00ffffff; //White
using (MemoryStream stream = new MemoryStream())
{
bmpToDraw.Save(stream, ImageFormat.Bmp);
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.BITMAP_WIDTH).Value = bmpToDraw.Width;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.BITMAP_HEIGHT).Value = bmpToDraw.Height;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.BITS_PER_COMPONENT).Value = 24;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.BITS_PER_COLOR).Value = 8;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.BITMAP_DATA).Value = stream.GetBuffer();
stream.Close();
}
if (bMakeGray)
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.PictureAttributes.GRAY_SCALE).Value = bGrayScale;
imageObject.AttributeByName(AmyuniHelpers.DrawingObjects.CommonAttributes.LOCKED).Value = true;
}
}
Thanks for your help