How do I load and edit a bitmap file at the pixel level in Swift for iOS?

This is how I am getting a color from an image at a touch location. I translated this answer: https://stackoverflow.com/a/12579413/359578 (This sample does no error checking for nil) func createARGBBitmapContext(inImage: CGImage) -> CGContext { var bitmapByteCount = 0 var bitmapBytesPerRow = 0 //Get image width, height let pixelsWide = CGImageGetWidth(inImage) let pixelsHigh = CGImageGetHeight(inImage) // … Read more

Get pixel color from an image [duplicate]

Create a canvas document.createElement Get the 2d context canvas.getContext(‘2d’) Draw the image to the canvas context.drawImage(image, x, y) Make sure the image is from the same domain or you won’t have access to its pixels Get the pixel data for the image context.getImageData(x1, y1, x2, y2) You want just the top left so context.getImageData(0, 0, … Read more

Get color of each pixel of an image using BufferedImages

import java.io.*; import java.awt.*; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; public class GetPixelColor { public static void main(String args[]) throws IOException { File file = new File(“your_file.jpg”); BufferedImage image = ImageIO.read(file); // Getting pixel color by position x and y int clr = image.getRGB(x, y); int red = (clr & 0x00ff0000) >> 16; int green = (clr … Read more

How to draw a pixel on the screen directly?

Direct answer: This can only be done with OS-specific APIs. Some OSes do not allow changing pixels on the screen directly. On Windows, you can use pywin32 libraries to get screen’s device context with dc = GetDC(0) call, then paint pixels with SetPixel(dc, x, y, color). import win32gui import win32api dc = win32gui.GetDC(0) red = … Read more