Home Javascript Point to Pixel Conversion
07.09.2010
Main Menu
Programming
.NET Controls
Operating System
Databases
Articles
Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: StumbleUpon Add to: Slashdot Add to: Yahoo Add to: Technorati Add to: Google
Point to Pixel Conversion

To convert point point to pixel it is not that difficult. Here are the two formulas you can use to do the conversion.

To convert pixel to point:

points = pixel * 72 / 96

To convert point to pixel:

pixels = point * 96 / 72


Try it now


Source Code:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Point to Pixel Conversion</title>

 

</head>

<body>

<form>     

      <div>

        <script type="text/javascript">

            function PointToPixel()

            {

                obj = document.getElementById("txtPoint");                               

                result = document.getElementById("lblPoint");               

                result.value = (eval(obj.value) * 96 / 72) + "px";                           

            }

 

            function PixelToPoint()

            {

                obj = document.getElementById("txtPixel");                               

                result = document.getElementById("lblPixel");               

                result.value = (eval(obj.value) * 72 / 96) + "pt";                           

            }

        </script>

        <div>

            Pixel To Point: <input id="txtPixel" type="text" /> &nbsp;

            <input type="text" id="lblPixel" readonly="true" style="background-color:gray; color:#ffffff;" />

            <input type="button" onclick="PixelToPoint()" value="Convert"/>

        </div>

        <div>

            Point To Pixel: <input id="txtPoint" type="text" /> &nbsp;

            <input type="text" id="lblPoint" readonly="true" style="background-color:gray; color:#ffffff;" />

            <input type="button" onclick="PointToPixel()" value="Convert"/>

        </div>       

      </div>

</form>

</body>

</html>



Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."