Windows 8.1 scales WinForms application for no reason

State this and you will be my programming hero:

My client is using a Surface Pro tablet running Windows 8.1 The app is a WinForms based desktop app.

When an application tries to open a TIFF image, and only then does Windows decide to extend the application (called Display Scaling), and as a result, everything in the application suddenly looks so small that you cannot see or work with it at all. Therefore, we want to avoid this scaling. (And turning it off from the Compatibility tab is even worse)

Now comes the fun part. The code looks like this:

Stream stream = new MemoryStream(File.ReadAllBytes(fileName));

// At this point the app looks ok...
bitmap = LoadTiffFromStream(stream);

private static Bitmap LoadTiffFromStream(Stream stream)
{
// Here before any code executes, the app is scaled

      

As you can see, we are loading some file into a stream, we are passing a stream to the method, and before any method code is executed, the application is scaled up. This only happens for TIFF images, as if the application somehow knows the stream contains TIFF data!

Some tests:

  • The same code placed in an empty test application does not give the same behavior
  • The TIFF file is no larger or smaller than other files, which are loaded in order and are not associated with stream size, file name, or any file system permissions.
  • I have confirmed that no other code is executing between these two lines.
  • This happens absolutely every time, only for TIFF images, for any TIFF image, and before executing any code that has anything to do with the TIFF format (I'm just sending a stream to the method!)

I can not understand. Can you?

+3


source to share


1 answer


Have you experimented with different ways to upload an image?



Bitmap img = Image.FromFile(@"MyImage.tif").Clone() as Bitmap;

      

-1


source







All Articles