Some jpg files will not display in a ShapeNode. This does not seem to be a function of the file size. Is there any attribute of a jpg file that will stop the image from displaying?
My code looks like this...
internal static Bitmap ScaleImage(string pathname, int maxWidth, int maxHeight)
{
// See:
https://stackoverflow.com/questions/6501797/resize-image-proportionally-with-maxheight-and-maxwidth-constraints
try
{
var bitmap = new Bitmap(pathname);
var ratioX = (double)maxWidth / bitmap.Width;
var ratioY = (double)maxHeight / bitmap.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(bitmap.Width * ratio);
var newHeight = (int)(bitmap.Height * ratio);
var scaledBitmap = new Bitmap(bitmap, newWidth, newHeight);
bitmap.Dispose();
return scaledBitmap;
}
catch
{
// If there's not enough memory the above code can fail.
// Also, 'pathname' may not be able to be converted into a Bitmap.
return null;
}
}
private void AddPictureBox(ShapeNode box, string pathname)
{
var yOffset = CountOfLinkAttachments(box) * 7;
var pictureBox = FlowChart.Factory.CreateShapeNode(box.Bounds.X - 7, box.Bounds.Y + yOffset, 6, 6, Shapes.Rectangle);
pictureBox.Transparent = false;
pictureBox.Locked = true;
pictureBox.Expandable = false;
// Create a scaled bitmap of the picture 40 x 40 pixels
Bitmap bm = ScaleImage(pathname, 40, 40);
pictureBox.Image = bm;
pictureBox.ImageAlign = ImageAlign.Stretch;
// Attach the picture box to the subordinate group (Top Left)
SubordinateGroup(box).AttachToCorner(pictureBox, 0);
}
DavidL