Pixel to Centimeter?

Similar to this question which asks about points instead of centimeters. There are 72 points per inch and there are 2.54 centimeters per inch, so just substitute 2.54 for 72 in the answer to that question. I’ll quote and correct my answer here: There are 2.54 centimeters per inch; if it is sufficient to assume … Read more

What are pixels and points in iOS?

A pixel on iOS is the full resolution of the device, which means if I have an image that is 100×100 pixels in length, then the phone will render it 100×100 pixels on a standard non-retina device. However, because newer iPhones have a quadrupled pixel density, that same image will render at 100×100 pixels, but … Read more

Developing a tracking pixel

You can write a script that creates and returns a .gif, .jpeg or .png image using PHP for tracking purposes using the GD library (which is often distributed with PHP in modern versions). If you don’t have access to GD, you can always recompile PHP with GD enabled. Example: pixel.php (commented for the purposes of … Read more

How to get the pixel color on touch?

This is the one I’ve used, and it looks simpler than the methods you’ve tried. In my custom view class, I have this: – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint loc = [touch locationInView:self]; self.pickedColor = [self colorOfPoint:loc]; } colorOfPoint is a method in a category on UIView, with … Read more

How to get the color of a pixel in an UIView?

Here is more efficient solution: // UIView+ColorOfPoint.h @interface UIView (ColorOfPoint) – (UIColor *) colorOfPoint:(CGPoint)point; @end // UIView+ColorOfPoint.m #import “UIView+ColorOfPoint.h” #import <QuartzCore/QuartzCore.h> @implementation UIView (ColorOfPoint) – (UIColor *) colorOfPoint:(CGPoint)point { unsigned char pixel[4] = {0}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast); CGContextTranslateCTM(context, -point.x, -point.y); [self.layer renderInContext:context]; … Read more

OpenGL Scale Single Pixel Line

There is no “320×240 glOrtho canvas”. There is only the window’s actual resolution: 960×720. All you are doing is scaling up the coordinates of the primitives you render. So, your code says to render a line from, for example, (20, 20) to (40, 40). And OpenGL (eventually) scales those coordinates by 3 in each dimension: … Read more

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

DP to PX: public static int dpToPx(float dp, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); } SP to PX: public static int spToPx(float sp, Context context) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics()); } DP to SP: public static int dpToSp(float dp, Context context) { return (int) (dpToPx(dp, context) / context.getResources().getDisplayMetrics().scaledDensity); }