Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Converting device independent pixel to device dependent pixel?

 
 
Old 01-31-2006   #1 (permalink)
fö


 
 

Converting device independent pixel to device dependent pixel?

Visualizing 100.000 xy-data points with increasing x values
by using a Polyline takes a noticeable amount of time - espc.
if you have to visualize several data series in one chart control.
Any way it's a foolish thing to do so, since the area I am using
to plot the data might only be 1000 pixel wide.

In the old days of GDI(+) I therefore reduced the number
of data points by evaluating which points will be transformed
to the same pixel column.

But now I do not know anything about the real pixels at all!
OK, I could make an estimation and reduce the data as if
there were let's say 1000 pixels and this works fine, but isn't
there a way to exactly convert a device independent pixel from
a canvas to an absolute pixel position on the screen?

Thanks,
fö

My System SpecsSystem Spec
Old 01-31-2006   #2 (permalink)
viliescu


 
 

RE: Converting device independent pixel to device dependent pixel?

I don't think there is a way to use device dependent pixels.

What you can do is to use the fact that a DIP (device independent pixel) is
1/96 inch so any two points that are too close (for example 1/10th of a pixel
- that means 1/960 inch) will be rendered as one.
--
Valentin Iliescu [MVP C#]


"fö" wrote:

> Visualizing 100.000 xy-data points with increasing x values
> by using a Polyline takes a noticeable amount of time - espc.
> if you have to visualize several data series in one chart control.
> Any way it's a foolish thing to do so, since the area I am using
> to plot the data might only be 1000 pixel wide.
>
> In the old days of GDI(+) I therefore reduced the number
> of data points by evaluating which points will be transformed
> to the same pixel column.
>
> But now I do not know anything about the real pixels at all!
> OK, I could make an estimation and reduce the data as if
> there were let's say 1000 pixels and this works fine, but isn't
> there a way to exactly convert a device independent pixel from
> a canvas to an absolute pixel position on the screen?
>
> Thanks,
> fö

My System SpecsSystem Spec
Old 03-01-2006   #3 (permalink)
fö


 
 

RE: Converting device independent pixel to device dependent pixel?

Finally I found the answer myself: the classes PresentationSource
and CompositionTarget help to get a transformation from DIPs
to pixel and vice versa. Here's a function that returns the resolution
of a canvas' target device in dots per inch:

public Point GetResolution(Canvas canvas)
{
Point dpi = new Point(96, 96);

PresentationSource source = PresentationSource.FromVisual(canvas);
if (source == null)
return dpi;

CompositionTarget target = source.CompositionTarget;

Matrix m = target.TransformToDevice;
MatrixTransform t = new MatrixTransform(m);

Point pt1 = new Point(0, 0);
pt1 = t.Transform(pt1);

Point pt2 = new Point(96, 96);
pt2 = t.Transform(pt2);

dpi.X = pt2.X - pt1.X;
dpi.Y = pt2.Y - pt1.Y;
return dpi;
}


"fö" wrote:

> To decide what "too close" exactly means I would need to find out
> the current screen resolution and DPI settings. Is there a way to
> get these values?
>
> "viliescu" wrote:
>
> > I don't think there is a way to use device dependent pixels.
> >
> > What you can do is to use the fact that a DIP (device independent pixel) is
> > 1/96 inch so any two points that are too close (for example 1/10th of a pixel
> > - that means 1/960 inch) will be rendered as one.
> > --
> > Valentin Iliescu [MVP C#]
> >
> >
> > "fö" wrote:
> >
> > > Visualizing 100.000 xy-data points with increasing x values
> > > by using a Polyline takes a noticeable amount of time - espc.
> > > if you have to visualize several data series in one chart control.
> > > Any way it's a foolish thing to do so, since the area I am using
> > > to plot the data might only be 1000 pixel wide.
> > >
> > > In the old days of GDI(+) I therefore reduced the number
> > > of data points by evaluating which points will be transformed
> > > to the same pixel column.
> > >
> > > But now I do not know anything about the real pixels at all!
> > > OK, I could make an estimation and reduce the data as if
> > > there were let's say 1000 pixels and this works fine, but isn't
> > > there a way to exactly convert a device independent pixel from
> > > a canvas to an absolute pixel position on the screen?
> > >
> > > Thanks,
> > > fö

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
scrolling pixel by pixel rather than line by line? Vista General
Pixel lines problem Graphic cards
help !!! pixel or vertex shaders Vista Games
Pixel Shader version & Aero Vista music pictures video


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46