Questions tagged [pixel]

A pixel is the smallest unit that can be represented or controlled on a display. The word pixel is derived from the phrase "picture element".

4067 questions
1960
votes
46 answers

How to get screen dimensions as pixels in Android

I created some custom elements, and I want to programmatically place them to the upper right corner (n pixels from the top edge and m pixels from the right edge). Therefore I need to get the screen width and screen height and then set position: int…
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
950
votes
35 answers

Converting pixels to dp

I have created my application with the height and width given in pixels for a Pantech device whose resolution is 480x800. I need to convert height and width for a G1 device. I thought converting it into dp will solve the problem and provide the same…
Indhu
  • 9,806
  • 3
  • 18
  • 17
576
votes
11 answers

Setting width/height as percentage minus pixels

I'm trying to create some re-usable CSS classes for more consistency and less clutter on my site, and I'm stuck on trying to standardize one thing I use frequently. I have a container
that I don't want to set the height for (because it will…
Matt
  • 23,363
  • 39
  • 111
  • 152
228
votes
14 answers

What's the best way to set a single pixel in an HTML5 canvas?

The HTML5 Canvas has no method for explicitly setting a single pixel. It might be possible to set a pixel using a very short line, but then antialiasing and line caps might interfere. Another way might be to create a small ImageData object and…
Alnitak
  • 334,560
  • 70
  • 407
  • 495
186
votes
13 answers

How to read the RGB value of a given pixel in Python?

If I open an image with open("image.jpg"), how can I get the RGB values of a pixel assuming I have the coordinates of the pixel? Then, how can I do the reverse of this? Starting with a blank graphic, 'write' a pixel with a certain RGB value? I would…
Josh Hunt
  • 14,225
  • 26
  • 79
  • 98
144
votes
6 answers

How to check if a specific pixel of an image is transparent?

Is there any way to check if a selected (x,y) point of a PNG image is transparent?
Danny Fox
  • 38,659
  • 28
  • 68
  • 94
135
votes
12 answers

Convert Pixels to Points

I have a need to convert Pixels to Points in C#. I've seen some complicated explanations about the topic, but can't seem to locate a simple formula. Let's assume a standard 96dpi, how do I calulate this conversion?
Todd Davis
  • 5,855
  • 10
  • 53
  • 89
130
votes
5 answers

Get pixel's RGB using PIL

Is it possible to get the RGB color of a pixel using PIL? I'm using this code: im = Image.open("image.gif") pix = im.load() print(pix[1,1]) However, it only outputs a number (e.g. 0 or 1) and not three numbers (e.g. 60,60,60 for R,G,B). I guess I'm…
GermainZ
  • 1,893
  • 3
  • 15
  • 20
105
votes
4 answers

Calculating width from percent to pixel then minus by pixel in LESS CSS

I will calculate width in some element from percent to pixel so I will minus -10px via using LESS and calc(). It´s possible? div { span { width:calc(100% - 10px); } } I using CSS3 calc() so it doesn't work: calc(100% -…
l2aelba
  • 21,591
  • 22
  • 102
  • 138
102
votes
7 answers

Does setWidth(int pixels) use dip or px?

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.
101
votes
7 answers

How to convert DP, PX, SP among each other, especially DP and SP?

I have known the difference among DP, SP and PX. And after searching this topic, I found nothing satisfying me completely. Maybe this post is a duplicate, but I still want to know what is the formula of converting from DP to PX, and DP to SP, from…
SilentKnight
  • 13,761
  • 19
  • 49
  • 78
100
votes
10 answers

Draw a single pixel on Windows Forms

I'm stuck trying to turn on a single pixel on a Windows Form. graphics.DrawLine(Pens.Black, 50, 50, 51, 50); // draws two pixels graphics.DrawLine(Pens.Black, 50, 50, 50, 50); // draws no pixels The API really should have a method to set the color…
Mark T
  • 3,464
  • 5
  • 31
  • 45
89
votes
6 answers

Count all values in a matrix less than a value

I have to count all the values in a matrix (2-d array) that are less than 200. The code I wrote down for this is: za=0 p31 = numpy.asarray(o31) for i in range(o31.size[0]): for j in range(o32.size[1]): if p31[i,j]<200: …
gran_profaci
  • 8,087
  • 15
  • 66
  • 99
86
votes
6 answers

Why do I need @1x, @2x and @3x iOS images?

Why do we need these 3 particular image types? If I have a button on my app with a background image say, 50 pixels x 50 pixels, why do I need 3 versions of this image? What's stopping me from just making one image that's much higher in res, say,…
CodeMark22
  • 1,199
  • 1
  • 9
  • 11
85
votes
13 answers

Is it bad to work with pixels in CSS?

Is it bad in terms of compatibility to use pixel numbers in CSS instead of percentages? How about lower resolutions? Is it okay to work with them in ranges of 1-100?
loya
  • 749
  • 1
  • 5
  • 4
1
2 3
99 100