Research Article
MyOcrTool: Visualization System for Generating Associative Images of Chinese Characters in Smart Devices
Program Listing 1
Program Listing 1: Implementation of picture graying procedure.
Input: original image | Output: grayImage private static Bitmap getGrayImg(){ | int alpha = 0xFF << 24; | // Set transparency | for (int i = 0; i < imgHeight; i++) { | for (int j = 0; j < imgWidth; j++) { | int grey = imgPixels[imgWidth∗i + j]; | // Get the jth pixel of the i-th row | int red = ((grey & 0x00FF0000) >> 16); | // Get red gray value | int green = ((grey & 0x0000FF00) >> 8); | // Get green gray value | int blue = (grey & 0x000000FF); | // Get bule gray value | grey = (int) ((float) red∗0.3 + (float) green∗0.59 + (float) blue∗0.11); | // obtain grayscale color values | grey = alpha | (grey << 16) | (grey << 8) | grey; imgPixels[imgWidth∗i + j] = grey; | } | } | Bitmap result = Bitmap.createBitmap(imgWidth, imgHeight, Config.RGB_565); | result.setPixels(imgPixels, 0, imgWidth, 0, 0, imgWidth, imgHeight); | return result; | } |
|