|
-
Apr 8th, 2009, 06:34 AM
#1
Thread Starter
Hyperactive Member
how do i get DPI of system
hey
is there any way to determine DPI of system ?
* If my post helped you, please Rate it
* If your problem is solved please also mark the thread resolved it is there in right top of page under thread tools
* Why Rating is useful
-
Apr 8th, 2009, 06:42 AM
#2
Re: how do i get DPI of system
Hi,
You can try something like this;
vb Code:
Public Shared Function GetResolution(ByVal visual As Visual) As Point Dim dpi As New Point(120, 120) Dim source As PresentationSource = PresentationSource.FromVisual(visual) If source Is Nothing Then Return dpi End If Dim target As CompositionTarget = source.CompositionTarget Dim m As Matrix = target.TransformToDevice Dim t As New MatrixTransform(m) Dim pt1 As New Point(0, 0) pt1 = t.Transform(pt1) Dim pt2 As New Point(96, 96) pt2 = t.Transform(pt2) dpi.X = pt2.X - pt1.X dpi.Y = pt2.Y - pt1.Y Return dpi End Function
-
Apr 8th, 2009, 06:43 AM
#3
Re: how do i get DPI of system
Try this:
Code:
Dim g As Graphics = Me.CreateGraphics
MessageBox.Show(String.Format("{0}x{1}", g.DpiX.ToString(), g.DpiY.ToString()))
g.Dispose()
-
Apr 8th, 2009, 07:03 AM
#4
Thread Starter
Hyperactive Member
Re: how do i get DPI of system
hey
@Negative0 this doesnot work for me
MessageBox.Show(String.Format("{0}x{1}", g.DpiX.ToString(), g.DpiY.ToString()))
@sparrow1
is there namespaces and refrences required as i am getting error in visual ??
Type 'Visual' is not defined.
Type 'PresentationSource' is not defined.
Type 'CompositionTarget' is not defined.
Type 'Matrix' is not defined.
Type 'MatrixTransform' is not defined.
pls help
Last edited by su ki; Apr 8th, 2009 at 07:06 AM.
* If my post helped you, please Rate it
* If your problem is solved please also mark the thread resolved it is there in right top of page under thread tools
* Why Rating is useful
-
Apr 8th, 2009, 07:41 AM
#5
Re: how do i get DPI of system
Yes,
System.Windows
System.Windows.Media
Think thats all you need.
-
Apr 8th, 2009, 08:20 AM
#6
Re: how do i get DPI of system
Can you explain what doesn't work? It worked perfectly on my machine, returning 96x96. What did it return on your machine? What are you expecting it to return?
-
Apr 8th, 2009, 12:20 PM
#7
Re: how do i get DPI of system
 Originally Posted by Negative0
Can you explain what doesn't work? It worked perfectly on my machine, returning 96x96. What did it return on your machine? What are you expecting it to return?
Works for me too.
-
Apr 8th, 2009, 03:31 PM
#8
Re: how do i get DPI of system
Code:
Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_DisplayConfiguration")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_DisplayConfiguration instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("LogPixels: {0}", queryObj("LogPixels"))
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace
or
Code:
Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_DisplayControllerConfiguration")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_DisplayControllerConfiguration instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("HorizontalResolution: {0}", queryObj("HorizontalResolution"))
Console.WriteLine("VerticalResolution: {0}", queryObj("VerticalResolution"))
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace
or
Code:
Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
Public Class MyWMIQuery
Public Overloads Shared Function Main() As Integer
Try
Dim searcher As New ManagementObjectSearcher( _
"root\CIMV2", _
"SELECT * FROM Win32_VideoController")
For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("-----------------------------------")
Console.WriteLine("Win32_VideoController instance")
Console.WriteLine("-----------------------------------")
Console.WriteLine("CurrentHorizontalResolution: {0}", queryObj("CurrentHorizontalResolution"))
Console.WriteLine("CurrentVerticalResolution: {0}", queryObj("CurrentVerticalResolution"))
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
End Function
End Class
End Namespace
-
Apr 8th, 2009, 04:12 PM
#9
Re: how do i get DPI of system
Well resolution is not the same as DPI. DPI is a setting you can change to make the fonts larger without changing your resolution.
If you just want the resolution, there is no need for WMI, you can use the My.Computer.Screen objecT:
Code:
MessageBox.Show(String.Format("{0}x{1}", My.Computer.Screen.Bounds.Width.ToString(), My.Computer.Screen.Bounds.Height.ToString()))
-
Apr 9th, 2009, 12:59 AM
#10
Thread Starter
Hyperactive Member
Re: how do i get DPI of system
hey
*@ Pino thanks for telling about required namespaces.
@Negative0 , it shows 96 when dpi setting is 96 but it doesnot change when i switch it to 120 which it suppose to be.
actually i am checking it on resolution 1920*1200 and dpi 96 or 120
i understand that resolution is not same as dpi
@dbasnett , i hv not checked ur solution as i was not on my pc , let u know soon
su ki
* If my post helped you, please Rate it
* If your problem is solved please also mark the thread resolved it is there in right top of page under thread tools
* Why Rating is useful
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|