Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1476

Metafile Graphics for DPI Scaling

$
0
0
One of the headaches in addressing High DPI issues is the scaling of images within our user interfaces. These are typically small "icon" type images we display in various controls. In many cases we can head the problem off by simply dropping our use of iconic graphics, but in others we want icons for a number of reasons. ListView, TreeView, and similar controls just aren't the same when we limit ourselves to textual captions with no iconic images.

I'm not addressing Shell icons (file icons) here because that's a separate topic and one that metafile graphics can't help. There are other ways to manage scaling for those. I'm also not addressing .ICO format custom icons, which can be managed much like Shell icons and also can't be helped using metafiles.

So instead these are completely custom small images used "iconically" in your programs. Images you might have created a BMP, GIF, or ICO for back in the 96 DPI world.


Vector Graphics

Some people will claim that WMF and EMF (and EMF+) metafiles are "vector graphics" formats. I'm not sure that is accurate, but they are probably the closest thing we have natively in Windows

I see metafiles as really a kind of "GDI macro" that can be "played back" into bitmaps. By nature they have a transparent background unless you use some sort of fill operation to color it in.

Things like the hatch and pattern fills that do not scale at all (and thus are of limited real value) tend to disprove the "vector graphics" assertion for me.


Drawing Metafiles: MakeEMF

I'll focus on Enhanced Metafile (EMF) format here. Windows Metafile (WMF) can still be useful. You can do much the same thing for WMFs with only a few changes here and there to MakeEMF.

Even though EMF format images can have OpenGL and GDI+ drawing within them I am sticking with GDI for simplicity and have not investigated those options much. I'm not sure those work in a StdPicture or with VB/ActiveX controls anyway. I haven't looked into EMF+ format metafiles at all and they might even be more problematic for VB anyway.


Project1

Project1 makes use of MakeEMF.cls, a simple class for creating, drawing, and saving an EMF image to disk or retrieving it as a StdPicture object for direct use in VB.

MakeEMF only implements Ellipse and Line drawing. You could also add Arc, Curve, Rectangle, and more drawing operations, as well as fills and even more.


Name:  sshot1.png
Views: 44
Size:  4.3 KB

Project1


Project1 itself is a little silly, but just a simple demo. However it does create a simple "saved.emf" that is used in the other Projects.

I haven't seen many meaningful examples of creating and drawing metafile graphics in VB6. If you really want to do this you can probably adapt code from other GDI drawing examples to flesh out MakeEMF's repertoire with additional drawing methods.


MakeEMF: Impractical?

I suspect that it isn't worth the trouble of doing something like this in many programs. This probably explains why so little sample code seems to be floating around. I suppose you could use this as a starting point to make your own metafile graphics drawing utility.

My main direction here is using metafile graphics to address DPI scaling. Most people will probably use an existing 3rd party utility for that.

I tend to fall back on Old Reliable: Windows Draw 6 (originally by Micrografx, who were bought out and then bought out at least a second time). I doubt you can buy a copy anymore, but I have it working in Windows Vista and Windows 10 with only a slight loss in functionality.

I got used to Window Draw long ago, originally getting the Windows 3.1 version bundled with a trackball I bought in the early 1990s.

Since I'm no graphics artist my "tool bag" is pretty limited these days, mainly: IrfanView, MS Paint, IcoFX, and Windows Draw 6. These fit like old shoes aside from MS Paint which got re-boned in Windows 7 resulting in a chaotic and often inscrutable user interface.
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>