density-independent-pixel

WPF Units and Code-Behind

夙愿已清 提交于 2019-12-03 23:45:36
Recently I discovered WPF supports different measurement units in XAML. Besides default DIPs, there is also support for pixels, inches and centimeters (as far as I know). This allows designer to write XAML such as this: <Canvas> <Line X1="0cm" X2="3cm" Y1="1cm" Y2="3cm" Stroke="Black"/> </Canvas> However, you cannot bind these values. Imagine we have a ViewModel with Dimension property which is a String, for example "7cm". Following won't work: <Button Width="{Binding Dimension}">Test</Button> FormatException gets thrown. Similarly, when creating a FrameworkElement in code-behind, like this:

How to get Image DPI in PHP [duplicate]

一世执手 提交于 2019-12-02 03:14:33
问题 This question already has answers here : Get/set DPI with PHP GD/Imagick? (3 answers) Closed 5 years ago . I am searching for the code which could help me to get the Image DPI in PHP. Could any one look into this ? Thanks in advance. 回答1: You can go for some image libraries for that. Eg: Imagick, GD Library... (OR) You can use the following function, function get_dpi($filename){ $a = fopen($filename,'r'); $string = fread($a,20); fclose($a); $data = bin2hex(substr($string,14,4)); $x = substr(

How do dp, dip, dpi, ppi, pixels and inches relate?

一曲冷凌霜 提交于 2019-11-30 03:00:57
I was reading dp, dip, px, sp measurements , but I still have some questions about dp/dpi vs ppi vs px vs inch. I am not able to compare them... is an inch the largest? They say 160 dpi means 160 pixels per one inch. Does that mean 1 inch contains 160 pixels? They also say 1 pixel on a 160 dpi screen = 1 dp. Does that mean 1 pixel and 1 dp are equal? And lastly, why should we use dp instead of px? I understand that it is ideal, but why ? You should (almost) always use flexible sizing units, like dp , which is Density-Independent Pixels, because 300px on one device is not necessarily the same

How do dp, dip, dpi, ppi, pixels and inches relate?

主宰稳场 提交于 2019-11-29 00:09:14
问题 I was reading dp, dip, px, sp measurements, but I still have some questions about dp/dpi vs ppi vs px vs inch. I am not able to compare them... is an inch the largest? They say 160 dpi means 160 pixels per one inch. Does that mean 1 inch contains 160 pixels? They also say 1 pixel on a 160 dpi screen = 1 dp. Does that mean 1 pixel and 1 dp are equal? And lastly, why should we use dp instead of px? I understand that it is ideal, but why ? 回答1: You should (almost) always use flexible sizing

basics of device-independent-pixels

风格不统一 提交于 2019-11-28 09:27:45
im throughoutly confused by dips on Android. I understand from the reference that the base for dp values is 160. So, shouldn't 80dp in width equals a view with a width of 50% of the screen ? On my Nexus One the width in dp is something around 300dp as it seems. What am i missing here ? thx in advance "dp" == "Density-independent Pixels" (This is also why it was earlier called "dip", though I prefer to use "dp" these days.) Think of it like other units -- "in" (inches), "mm" (millimeters), etc. It allows you to provide a size that is scaled based on the density of the screen. We define mdpi to

How do you make layouts for several Android screen sizes?

不打扰是莪最后的温柔 提交于 2019-11-27 12:41:34
I've done some research on building layouts that work for multiple screen sizes and I'm looking for some clarification. Is it common practice to just make a separate layout file for each of the three screen sizes (small, medium, large) or can you accomplish this with an easier method? I've been testing my projects on a large screen device, and even though I use DIPs (density independent pixels) for padding, margins, etc, it still scrunches stuff up when I view it on smaller screens. Should I be designing my projects for medium-sized screens and then just allow Android to scale it appropriately

basics of device-independent-pixels

这一生的挚爱 提交于 2019-11-27 02:54:57
问题 im throughoutly confused by dips on Android. I understand from the reference that the base for dp values is 160. So, shouldn't 80dp in width equals a view with a width of 50% of the screen ? On my Nexus One the width in dp is something around 300dp as it seems. What am i missing here ? thx in advance 回答1: "dp" == "Density-independent Pixels" (This is also why it was earlier called "dip", though I prefer to use "dp" these days.) Think of it like other units -- "in" (inches), "mm" (millimeters)

Does setWidth(int pixels) use dip or px?

别等时光非礼了梦想. 提交于 2019-11-26 23:21:00
Does setWidth(int pixels) use device independent pixel or physical pixel as unit? For example, does setWidth(100) set the a view's width to 100 dips or 100 pxs? Thanks. Daniel Lew It uses pixels, but I'm sure you're wondering how to use dips instead. The answer is in TypedValue.applyDimension() . Here's an example of how to convert dips to px in code: // Converts 14 dip into its equivalent px Resources r = getResources(); int px = Math.round(TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 14,r.getDisplayMetrics())); The correct way to obtain a constant number of DIPs in code is to

What is the correct way to specify dimensions in DIP from Java code?

两盒软妹~` 提交于 2019-11-26 21:23:57
I found that it is possible to set dimensions of my interface elements in XML layouts using DIPs as in following fragment: android:layout_width="10dip" But all Java interface takes integer as arguments and there is no way to specify dimensions in DIPs. What is the correct way to calculate this? I figured that I have to use property density of DisplayMetrics class but is this a correct way? May I rely on this formula being always correct? pixels * DisplayMetrics.density = dip Is there a utility function for the conversion somewhere in Android? sirhc There is an existing utility method built

How do you make layouts for several Android screen sizes?

一曲冷凌霜 提交于 2019-11-26 18:12:55
问题 I've done some research on building layouts that work for multiple screen sizes and I'm looking for some clarification. Is it common practice to just make a separate layout file for each of the three screen sizes (small, medium, large) or can you accomplish this with an easier method? I've been testing my projects on a large screen device, and even though I use DIPs (density independent pixels) for padding, margins, etc, it still scrunches stuff up when I view it on smaller screens. Should I