Convert Pixels to Points

There are 72 points per inch; if it is sufficient to assume 96 pixels per inch, the formula is rather simple: points = pixels * 72 / 96 There is a way to get the configured pixels per inch of your display in Windows using GetDeviceCaps. Microsoft has a guide called “Developing DPI-Aware Applications”, look … Read more

Get Pixel color of UIImage

Try this very simple code: I used to detect a wall in my maze game (the only info that I need is the alpha channel, but I included the code to get the other colors for you): – (BOOL)isWallPixel:(UIImage *)image xCoordinate:(int)x yCoordinate:(int)y { CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)); const UInt8* data = CFDataGetBytePtr(pixelData); int pixelInfo = … Read more

How to read the Color of a Screen Pixel

This is the most efficient: It grabs a pixel at the location of the cursor, and doesn’t rely on only having one monitor. using System; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Diagnostics; namespace FormTest { public partial class Form1 : Form { [DllImport(“user32.dll”)] static extern bool GetCursorPos(ref Point lpPoint); [DllImport(“gdi32.dll”, CharSet = … Read more

Setting width/height as percentage minus pixels

You can use calc: height: calc(100% – 18px); Note that some old browsers don’t support the CSS3 calc() function, so implementing the vendor-specific versions of the function may be required: /* Firefox */ height: -moz-calc(100% – 18px); /* WebKit */ height: -webkit-calc(100% – 18px); /* Opera */ height: -o-calc(100% – 18px); /* Standard */ height: … Read more

How to get screen dimensions as pixels in Android

If you want the display dimensions in pixels you can use getSize: Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y; If you’re not in an Activity you can get the default Display via WINDOW_SERVICE: WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); If you … Read more

How to Get Pixel Color in Android

You can get the pixel from the view like this: ImageView imageView = ((ImageView)v); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); int pixel = bitmap.getPixel(x,y); Now you can get each channel with: int redValue = Color.red(pixel); int blueValue = Color.blue(pixel); int greenValue = Color.green(pixel); The Color functions return the value in each channel. So all you have to … Read more

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

Building on Jeff’s answer, your first step would be to create a canvas representation of your PNG. The following creates an off-screen canvas that is the same width and height as your image and has the image drawn on it. var img = document.getElementById(‘my-image’); var canvas = document.createElement(‘canvas’); canvas.width = img.width; canvas.height = img.height; canvas.getContext(‘2d’).drawImage(img, … Read more