Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Not all jpg files can be displayed in a ShapeNode (Read 311 times)
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Not all jpg files can be displayed in a ShapeNode
Dec 12th, 2024 at 12:19pm
Print Post  
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-max
height-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
  

Screenshot_2024-12-12_120238.png ( 7 KB | 11 Downloads )
Screenshot_2024-12-12_120238.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #1 - Dec 12th, 2024 at 2:21pm
Print Post  
Please attach a jpeg that's not displaying. Have you verified ScaleImage isn't returning null from the catch block in that case? Generally ImageAlign.Stretch should display scaled image without you having to create a scaled copy, but I guess a smaller copy could conserve memory.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Re: Not all jpg files can be displayed in a ShapeNode
Reply #2 - Dec 12th, 2024 at 4:50pm
Print Post  
I put a breakpoint on the catch block you mentioned and there was no exception thrown.

I don't have a file to hand that is less than your 700 KB limit. Is there another way I can get the file to you?

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #3 - Dec 13th, 2024 at 6:18am
Print Post  
Please attach it zipped or send to support email address at our domain.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #4 - Dec 13th, 2024 at 11:42am
Print Post  
It's displaying on our end, testing on Windows 11. Does this project show any of the bitmap copies on yours?

https://mindfusion.eu/_samples/ImageTest.zip



Also are all images that do not load for you that large (~ 5500 x 3500)? I think GDI and GDI+ weren't able to load bitmaps larger than about 3000 x 3000 pixels on older versions of Windows, but don't know if that was a fixed limit by the OS of video RAM -related.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Re: Not all jpg files can be displayed in a ShapeNode
Reply #5 - Dec 13th, 2024 at 2:47pm
Print Post  
Yes, that seems to work fine. I will have to see what I am doing differently. So far I have set up the diagram and view to be the same and have attached the picture box to another box, but still the image is displayed OK. I will keep going and let you know how things go.

Thanks for your help so far
DavidL
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Re: Not all jpg files can be displayed in a ShapeNode
Reply #6 - Dec 13th, 2024 at 5:15pm
Print Post  
After much experimentation, I could not find what I was doing differently. However, scaling the image to 100 x 100 rather than 40 x 40 seems to have solved the problem.
Not the best solution, but the one I am going with for now.

Thanks for your help
DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #7 - Dec 16th, 2024 at 7:20am
Print Post  
Is the ScaleImage(40) result not displaying only in diagram nodes, or also in picture boxes / form.OnPaint?
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Re: Not all jpg files can be displayed in a ShapeNode
Reply #8 - Dec 16th, 2024 at 12:02pm
Print Post  
Sorry, that seems to be difficult to test in my application. I would just say that increasing the scale size from 40x40 to 44x44 makes the images display OK.

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #9 - Dec 16th, 2024 at 12:20pm
Print Post  
Well, we could file that as one of the mysteries of the universe Wink or let us know what's this code showing on your end for 40x40 if you'd like to investigate more:

Code
Select All
static Bitmap ScaleImage(string pathname, int maxWidth, int maxHeight)
....
Debug.WriteLine(scaledBitmap.GetPixel(0, 0));
Debug.WriteLine(scaledBitmap.Flags);
Debug.WriteLine(scaledBitmap.HorizontalResolution);
Debug.WriteLine(scaledBitmap.VerticalResolution);
Debug.WriteLine(scaledBitmap.RawFormat);
Debug.WriteLine(scaledBitmap.PixelFormat);

return scaledBitmap;
 



ours is:

Code
Select All
Color [A=255, R=151, G=192, B=233]
2
96
96
[ImageFormat: b96b3caa-0728-11d3-9d7b-0000f81ef32e]
Format32bppArgb
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Re: Not all jpg files can be displayed in a ShapeNode
Reply #10 - Dec 17th, 2024 at 10:12am
Print Post  
The colour of the first pixel has changed, as I might expect. But the 'Alpha' component has also changed, which I would not expect. This explains why there is an image there, but very faint.

100 x 100

Color [A=255, R=150, G=190, B=232]
2
96
96
[ImageFormat: b96b3caa-0728-11d3-9d7b-0000f81ef32e]
Format32bppArgb

40 x 40

Color [A=32, R=255, G=255, B=255]
2
96
96
[ImageFormat: b96b3caa-0728-11d3-9d7b-0000f81ef32e]
Format32bppArgb

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #11 - Dec 17th, 2024 at 11:34am
Print Post  
Check if it works better if you replace the scaledBitmap constructor call with

Code
Select All
var scaledBitmap = new Bitmap(newWidth, newHeight);
using (var graphics = Graphics.FromImage(scaledBitmap))
{
	graphics.Clear(Color.Transparent);
	graphics.DrawImage(bitmap, 0, 0, newWidth, newHeight);
} 

  
Back to top
 
IP Logged
 
David Long
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 136
Location: England
Joined: Oct 23rd, 2006
Re: Not all jpg files can be displayed in a ShapeNode
Reply #12 - Dec 17th, 2024 at 12:02pm
Print Post  
Sorry, that did not seem to help.

Color [A=32, R=255, G=255, B=255]
2
96
96
[ImageFormat: b96b3caa-0728-11d3-9d7b-0000f81ef32e]
Format32bppArgb

DavidL
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3321
Joined: Oct 19th, 2005
Re: Not all jpg files can be displayed in a ShapeNode
Reply #13 - Dec 17th, 2024 at 12:53pm
Print Post  
It looks like GDI+ drawing bug when scaling images then, and could depend on the ratio between original and target sizes (44x44 possibly working just for that specific image you sent us). You could convert the scaled bitmap to remove alpha channel, as long as you don't need to display semitransparent images. Otherwise try using a different library to resize, e.g. https://imagemagick.org/

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint