Posted By: jonathansampson | Dec 17th, 2008 @ 2:49 PM
page 1 of 1
Comments: 5 | Views: 1410
jonathansampson
jonathansampson
stick a scissor in you eye!
Here's an interesting discovery for you. I was building a small component that would popup product names when you mouse over their thumbnail. The popup was to have a semi-transparent background, so I went with a .png file. To cut down on bandwidth, I made it 1px by 1px.

I then noticed that it was getting screwed up in IE7.0.6001.18000, so I went and looked in every other browser known to man: all others did just fine. I then tested it in IE 7.0.5730.11 and it also worked just fine - something was up. It wasn't that it didn't show up, it was HOW it rendered it. There was a gradient type of transition from the top left, to the bottom right that went from near-opaque to completely transparent.

After searching Google, and finding nothing, I decided to examine other items that were using transparent png's as backgrounds. I had plenty that didn't show any problems. The difference between them, and this problem item, were the dimensions of the backgrounds. I increased the dimensions from 1x1 to 5x5, and whammo...that solved it.

Anybody have any clue what would cause this?

Left: 1x1 .png BG --- Right: 5x5 .png BG




Duncanma
Duncanma
Just Coding for Fun...

I tried to find a link about this with no luck, but I remember a discussion around this with some css-loving folks and they were advising not to use too small an image when doing transparency, that the work of laying out so many copies and handling the transparency blend of each one was a small amount of work, but by increasing the size from 1x1 to 5x5 I believe you'd be reducing the # of images to render by a factor of 25....

I don't understand why it would render it the way it did though, even if it was causing a performance problem.

Is this for a public site? Care to share which one?

evildictaitor
evildictaitor
if( !succeed( try() ) ) { while(true) try(); }
It's something to do with GDI+ and how it stretches images. I don't know how the other browsers are doing it, but I suspect them developing deliberately with more-than-one OS in-mind means that they don't use GDI+.

Basically the problem comes from the fact that GDI+ doesn't like images that are 1 pixel up or 1 pixel across - and so it extends the dimentions by adding blank (transparent black) pixels to the picture. This isn't normally a problem, unless you try and stretch the image, whereupon it becomes obvious.

You'll see the same problem if you open your image with (Right-click > Preview) and zoom in a lot.

The solution is to not use 1x1 pixels - 2x2 is probably sufficient, but because of the way the GPU works, somewhere between 5x5 and 20x20 will be less GPU intensive for drawing on large areas.
stevo_
stevo_
Human after all
IE tends to struggle with tiling anyway I've noticed you can sometimes 'witness' the tiling process when rendering is invalidated.. surely all these quirks are the fun part of being a web developer?
page 1 of 1
Comments: 5 | Views: 1410
Microsoft Communities