Discussion:
Scalemode vbTwips vs. vbPixels, and picture quality
(too old to reply)
K
2006-04-07 01:06:38 UTC
Permalink
I have an image viewer I've written in which I've been using Scalemode =
vbTwips for just about everything (forms, pictureboxes, etc). Recently
I've implemented a rotate-picture function where I found out that in order
to make the speed of calculation and drawing anywhere near acceptable I
needed to temporarily switch to using Scalemode = vbPixels, and that worked
great. While I know that in certain situations (like when moving forms
around the screen) it is necessary to deal in twips, the question I have
is... If I were to convert all of my other routines to deal in pixels
instead of twips (routines that resize pictures, mirror them, scroll them,
etc), would I be sacrificing anything in the way of picture quality? Is
there any reason to deal in twips other than when working with the screen?
Thanks for any thoughts...
-K
Mike Williams
2006-04-07 07:43:43 UTC
Permalink
Post by K
I have an image viewer I've written in which I've been using
Scalemode = vbTwips for just about everything (forms,
pictureboxes, etc). Recently I've implemented a rotate
picture function where I found out that in order to make
the speed of calculation and drawing anywhere near acceptable
I needed to temporarily switch to using Scalemode = vbPixels,
and that worked great.
What you've probably been doing is running a loop across the ScaleWidth and
ScaleHeight of your "twips scalemode" picture box reading the colour at each
position. On most machines there are 15 twips per pixel, and so if the
picture happens to be (say) 200 pixels wide by 100 pixels high then it will
on your machine be 3000 x 1500 twips. So, your code will be looking at a
total of 4500000 "twip positions". However, the only "real things" as far as
the screen is concerned are pixels. You cannot actually have anything on the
screen that is smaller than a pixel (except in a very limited way and under
certain very specific circumstances which I won't go into here). If you
think about this, you'll see that your code will be reading the colour of
every single pixel 15 x 15 = 225 times! However, if you change your
picturebox scalemode to vbPixels your code will be reading each pixel just
once, which is what you really want it to do.
Post by K
While I know that in certain situations (like when moving forms around the
screen) it is necessary to deal in twips, the question
I have is... If I were to convert all of my other routines to deal
in pixels instead of twips (routines that resize pictures, mirror
them, scroll them, etc), would I be sacrificing anything in the way
of picture quality?
Nope. The quality would be just the same. You would be wise to use pixels
for all your graphic routines. A pixel is the basic unit as far as screen
objects are concerned.
Post by K
Is there any reason to deal in twips other than when working
with the screen?
Twips are just another standard unit of meaurement, just like centimetres or
inches or miles or yards. There are always 1440 twips in an inch, just as
there are always 12 inches in a foot or 2.54 centimetres in an inch. The
only reason you are forced to sometimes consider twips in your programs is
because Visual Basic uses those units for the Width and Height properties of
Forms and printers and the Screen object. That means that if, for example,
you want a Form to have an overall width of (say) 500 pixels then you have
to convert that value from pixels to twips in order to set the Width
property of the Form. There are various different ways of performing such
conversions, but I think the simplest is the ScaleX function (for horizontal
measurements) and the ScaleY function (for vertical measurements). For
example, if you want to set the overall size of a Form to 500 x 400 pixels
you could do it this way:

Me.Width = Me.ScaleX(500, vbPixels, vbTwips)
Me.Height = Me.ScaleY(400, vbPixels, vbTwips)

There is a lot more that can be said about this stuff, but what I've said so
far should get you on the right track. Post again if you have any further
questions.

Mike
K
2006-04-08 01:43:53 UTC
Permalink
Thanks Mike. This is very good to know.
-K
Post by Mike Williams
Post by K
I have an image viewer I've written in which I've been using
Scalemode = vbTwips for just about everything (forms,
pictureboxes, etc). Recently I've implemented a rotate
picture function where I found out that in order to make
the speed of calculation and drawing anywhere near acceptable
I needed to temporarily switch to using Scalemode = vbPixels,
and that worked great.
What you've probably been doing is running a loop across the ScaleWidth
and ScaleHeight of your "twips scalemode" picture box reading the colour
at each position. On most machines there are 15 twips per pixel, and so if
the picture happens to be (say) 200 pixels wide by 100 pixels high then it
will on your machine be 3000 x 1500 twips. So, your code will be looking
at a total of 4500000 "twip positions". However, the only "real things" as
far as the screen is concerned are pixels. You cannot actually have
anything on the screen that is smaller than a pixel (except in a very
limited way and under certain very specific circumstances which I won't go
into here). If you think about this, you'll see that your code will be
reading the colour of every single pixel 15 x 15 = 225 times! However, if
you change your picturebox scalemode to vbPixels your code will be reading
each pixel just once, which is what you really want it to do.
Post by K
While I know that in certain situations (like when moving forms around
the screen) it is necessary to deal in twips, the question
I have is... If I were to convert all of my other routines to deal
in pixels instead of twips (routines that resize pictures, mirror
them, scroll them, etc), would I be sacrificing anything in the way
of picture quality?
Nope. The quality would be just the same. You would be wise to use pixels
for all your graphic routines. A pixel is the basic unit as far as screen
objects are concerned.
Post by K
Is there any reason to deal in twips other than when working
with the screen?
Twips are just another standard unit of meaurement, just like centimetres
or inches or miles or yards. There are always 1440 twips in an inch, just
as there are always 12 inches in a foot or 2.54 centimetres in an inch.
The only reason you are forced to sometimes consider twips in your
programs is because Visual Basic uses those units for the Width and Height
properties of Forms and printers and the Screen object. That means that
if, for example, you want a Form to have an overall width of (say) 500
pixels then you have to convert that value from pixels to twips in order
to set the Width property of the Form. There are various different ways of
performing such conversions, but I think the simplest is the ScaleX
function (for horizontal measurements) and the ScaleY function (for
vertical measurements). For example, if you want to set the overall size
Me.Width = Me.ScaleX(500, vbPixels, vbTwips)
Me.Height = Me.ScaleY(400, vbPixels, vbTwips)
There is a lot more that can be said about this stuff, but what I've said
so far should get you on the right track. Post again if you have any
further questions.
Mike
J French
2006-04-07 07:51:50 UTC
Permalink
Post by K
I have an image viewer I've written in which I've been using Scalemode =
vbTwips for just about everything (forms, pictureboxes, etc). Recently
I've implemented a rotate-picture function where I found out that in order
to make the speed of calculation and drawing anywhere near acceptable I
needed to temporarily switch to using Scalemode = vbPixels, and that worked
great. While I know that in certain situations (like when moving forms
around the screen) it is necessary to deal in twips, the question I have
is... If I were to convert all of my other routines to deal in pixels
instead of twips (routines that resize pictures, mirror them, scroll them,
etc), would I be sacrificing anything in the way of picture quality? Is
there any reason to deal in twips other than when working with the screen?
Thanks for any thoughts...
I've never found any reason for dealing in Twips

Some time ago, I became a firm convert to vbPixels only when I noticed
that there was a very slight difference in the same 'drawing' on two
different machines
- moving from Twips to vbPixels fixed it

AFAIK Windows only works in Pixels anyway, that is the smallest dot
you can put on a screen.
K
2006-04-08 01:46:50 UTC
Permalink
Good info. Thanks JF.
Post by J French
Post by K
I have an image viewer I've written in which I've been using Scalemode =
vbTwips for just about everything (forms, pictureboxes, etc). Recently
I've implemented a rotate-picture function where I found out that in order
to make the speed of calculation and drawing anywhere near acceptable I
needed to temporarily switch to using Scalemode = vbPixels, and that worked
great. While I know that in certain situations (like when moving forms
around the screen) it is necessary to deal in twips, the question I have
is... If I were to convert all of my other routines to deal in pixels
instead of twips (routines that resize pictures, mirror them, scroll them,
etc), would I be sacrificing anything in the way of picture quality? Is
there any reason to deal in twips other than when working with the screen?
Thanks for any thoughts...
I've never found any reason for dealing in Twips
Some time ago, I became a firm convert to vbPixels only when I noticed
that there was a very slight difference in the same 'drawing' on two
different machines
- moving from Twips to vbPixels fixed it
AFAIK Windows only works in Pixels anyway, that is the smallest dot
you can put on a screen.
Loading...