当前位置: 首页>>代码示例>>Java>>正文


Java Bitmap.getPixel方法代码示例

本文整理汇总了Java中android.graphics.Bitmap.getPixel方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.getPixel方法的具体用法?Java Bitmap.getPixel怎么用?Java Bitmap.getPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Bitmap的用法示例。


在下文中一共展示了Bitmap.getPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public void process(Bitmap bitmap) {
  final int w = bitmap.getWidth();
  final int h = bitmap.getHeight();

  for (int x = 0; x < w; x++) {
    for (int y = 0; y < h; y++) {
      /*
       * Using {@link Bitmap#getPixel} when iterating about an entire bitmap is inefficient as it
       * causes many JNI calls. This is only done here to provide a comparison to
       * {@link FasterGreyScalePostprocessor}.
       */
      final int color = bitmap.getPixel(x, y);
      bitmap.setPixel(x, y, SlowGreyScalePostprocessor.getGreyColor(color));
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:SlowGreyScalePostprocessor.java

示例2: turnBinary

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 实现对图像进行二值化处理
 *
 * @param origin bitmap
 * @return Bitmap
 */
public static Bitmap turnBinary(Bitmap origin) {
    int width = origin.getWidth();
    int height = origin.getHeight();
    Bitmap bitmap = origin.copy(Bitmap.Config.ARGB_8888, true);
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int col = bitmap.getPixel(i, j);
            int alpha = col & 0xFF000000;
            int red = (col & 0x00FF0000) >> 16;
            int green = (col & 0x0000FF00) >> 8;
            int blue = (col & 0x000000FF);
            int gray = (int) (red * 0.3 + green * 0.59 + blue * 0.11);
            if (gray <= 95) {
                gray = 0;
            } else {
                gray = 255;
            }
            int newColor = alpha | (gray << 16) | (gray << 8) | gray;
            bitmap.setPixel(i, j, newColor);
        }
    }
    return bitmap;
}
 
开发者ID:shenhuanet,项目名称:Ocr-android,代码行数:30,代码来源:BitmapUtils.java

示例3: getGrayscale

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 获取bitmap的灰度图像
 */
public static byte[] getGrayscale(Bitmap bitmap) {
	if (bitmap == null)
		return null;

	byte[] ret = new byte[bitmap.getWidth() * bitmap.getHeight()];
	for (int j = 0; j < bitmap.getHeight(); ++j)
		for (int i = 0; i < bitmap.getWidth(); ++i) {
			int pixel = bitmap.getPixel(i, j);
			int red = ((pixel & 0x00FF0000) >> 16);
			int green = ((pixel & 0x0000FF00) >> 8);
			int blue = pixel & 0x000000FF;
			ret[j * bitmap.getWidth() + i] = (byte) ((299 * red + 587
					* green + 114 * blue) / 1000);
		}
	return ret;
}
 
开发者ID:FacePlusPlus,项目名称:MegviiFacepp-Android-SDK,代码行数:20,代码来源:ConUtil.java

示例4: onAreaTouched

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
    Bitmap maskBitmap = phoeniciaGame.spriteMasks.get(this.getTiledTextureRegion());
    // Check click mask
    if (maskBitmap != null) {
        //Debug.d("Clicked block bitmap size: " + maskBitmap.getWidth() + "x" + maskBitmap.getHeight());
        ITextureRegion maskRegion = this.getTiledTextureRegion().getTextureRegion(3);
        float texturex = maskRegion.getTextureX();
        float texturey = maskRegion.getTextureY() + maskRegion.getHeight();
        //Debug.d("Clicked block bitmap region: " + maskRegion.getWidth() + "x" + maskRegion.getHeight() + " at " + texturex + "x" + texturey);
        int maskPixel = maskBitmap.getPixel((int) (texturex + pTouchAreaLocalX), (int) (texturey - pTouchAreaLocalY)) << 32;
        //Debug.d("Clicked block pixel at " + (texturex + pTouchAreaLocalX) + "x" + (texturey - pTouchAreaLocalY) + ": " + maskPixel);
        if (maskPixel == 0) {
            // Transparent region clicked
            return false;
        }
    }

    boolean handled = this.clickDetector.onManagedTouchEvent(pSceneTouchEvent);
    return this.holdDetector.onManagedTouchEvent(pSceneTouchEvent) || handled;
}
 
开发者ID:Linguaculturalists,项目名称:Phoenicia,代码行数:22,代码来源:MapBlockSprite.java

示例5: px2Byte

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 灰度图片黑白化,黑色是1,白色是0
 *
 * @param x   横坐标
 * @param y   纵坐标
 * @param bit 位图
 * @return
 */
public static byte px2Byte(int x, int y, Bitmap bit) {
    if (x < bit.getWidth() && y < bit.getHeight()) {
        byte b;
        int pixel = bit.getPixel(x, y);
        int red = (pixel & 0x00ff0000) >> 16; // 取高两位
        int green = (pixel & 0x0000ff00) >> 8; // 取中两位
        int blue = pixel & 0x000000ff; // 取低两位
        int gray = RGB2Gray(red, green, blue);
        if (gray < 128) {
            b = 1;
        } else {
            b = 0;
        }
        return b;
    }
    return 0;
}
 
开发者ID:januslo,项目名称:react-native-sunmi-inner-printer,代码行数:26,代码来源:ESCUtil.java

示例6: convert

import android.graphics.Bitmap; //导入方法依赖的package包/类
public String convert(Bitmap rgbImage, int quality) {
    if(quality > 3 && quality < 1)
        quality = 3;
    String tx = "";
    int width = rgbImage.getWidth();
    int height = rgbImage.getHeight();
    for (int y = 0; y < height; y = y + quality) {
        for (int x = 0; x < width; x = x + quality) {
            int pixel = rgbImage.getPixel(x, y);
            int red = Color.red(pixel);
            int green = Color.green(pixel);
            int blue = Color.blue(pixel);

            int brightness = red + green + blue;
            brightness = round(brightness / (765 / (chars.length - 1)));
            tx += chars[brightness];
        }
        tx += "\n";
    }
    return tx;
}
 
开发者ID:bachors,项目名称:Android-Img2Ascii,代码行数:22,代码来源:Img2Ascii.java

示例7: setBmpData

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Converts a bitmap image to LCD screen data and sets it on the given screen at the specified
 * offset.
 * @param mScreen The OLED screen to write the bitmap data to.
 * @param xOffset The horizontal offset to draw the image at.
 * @param yOffset The vertical offset to draw the image at.
 * @param bmp The bitmap image that you want to convert to screen data.
 * @param drawWhite true for drawing only white pixels, false for drawing grayscale pixel
 * based on {@link #GRADIENT_CUTOFF}.
 */
public static void setBmpData(SSD1306 mScreen, int xOffset, int yOffset, Bitmap bmp,
                              boolean drawWhite) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    int bmpByteSize = (int) Math.ceil((double) (width * ((height / 8) > 1 ? (height / 8) : 1)));

    // Each byte stored in memory represents 8 vertical pixels.  As such, you must fill the
    // memory with pixel data moving vertically top-down through the image and scrolling
    // across, while appending the vertical pixel data by series of 8.

    for (int y = 0; y < height; y += 8) {
        for (int x = 0; x < width; x++) {
            int bytePos = x + ((y / 8) * width);

            for (int k = 0; k < 8; k++) {
                if ((k + y < height) && (bytePos < bmpByteSize)) {
                    int pixel = bmp.getPixel(x, y + k);
                    if (!drawWhite) { // Look at Alpha channel instead
                        if ((pixel & 0xFF) > GRADIENT_CUTOFF) {
                            mScreen.setPixel(x + xOffset, y + yOffset + k, SSD1306.ColorCode.WHITE);
                        }
                    } else {
                        if (pixel == -1) { // Only draw white pixels
                            mScreen.setPixel(x + xOffset, y + yOffset + k, SSD1306.ColorCode.WHITE);
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:hongcheng79,项目名称:androidthings,代码行数:42,代码来源:BitmapHelper.java

示例8: draw

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Draw the given bitmap to the LED matrix.
 *
 * @param addr   the address of the display to control
 * @param bitmap Bitmap to draw
 * @throws IOException
 */
public void draw(int addr, Bitmap bitmap) throws IOException {
    if (addr < 0 || addr >= maxDevices) {
        return;
    }

    Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 8, 8, true);
    for (int row = 0; row < 8; row++) {
        int value = 0;
        for (int col = 0; col < 8; col++) {
            value |= scaled.getPixel(col, row) == Color.WHITE ? (0x80 >> col) : 0;
        }
        setRow(addr, row, (byte) value);
    }
}
 
开发者ID:Nilhcem,项目名称:ledcontrol-androidthings,代码行数:22,代码来源:LedControl.java

示例9: bmpToBytes

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Converts a bitmap image to LCD screen data and returns the screen data as bytes.
 * @param buffer The screen's data buffer.
 * @param offset The byte offset to start writing screen bitmap data at.
 * @param bmp The bitmap image that you want to convert to screen data.
 * @param drawWhite Set to true to draw white pixels, false to draw pixels based on gradient.
 * @return A byte array with pixel data for the SSD1306.
 */
public static void bmpToBytes(byte[] buffer, int offset, Bitmap bmp, boolean drawWhite) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();

    // Each byte stored in memory represents 8 vertical pixels.  As such, you must fill the
    // memory with pixel data moving vertically top-down through the image and scrolling
    // across, while appending the vertical pixel data by series of 8.
    for (int y = 0; y < height; y += 8) {
        for (int x = 0; x < width; x++) {
            int bytePos = (offset + x) + ((y / 8) * width);

            for (int k = 0; k < 8; k++) {
                if ((k + y < height) && (bytePos < buffer.length)) {
                    int pixel = bmp.getPixel(x, y + k);
                    if (!drawWhite) { // Look at Alpha channel instead
                        if ((pixel & 0xFF) > GRADIENT_CUTOFF) {
                            buffer[bytePos] |= 1 << k;
                        }
                    } else {
                        if (pixel == -1) { // Only draw white pixels
                            buffer[bytePos] |= 1 << k;
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:hongcheng79,项目名称:androidthings,代码行数:37,代码来源:BitmapHelper.java

示例10: createQRCodeWithLogo4

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 比方法2的颜色黑一些
 *
 * @param text
 * @param size
 * @param mBitmap
 * @return
 */
public static Bitmap createQRCodeWithLogo4(String text, int size, Bitmap mBitmap) {
    try {
        IMAGE_HALFWIDTH = size / 10;
        Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");

        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        BitMatrix bitMatrix = new QRCodeWriter().encode(text,
                BarcodeFormat.QR_CODE, size, size, hints);

        //将logo图片按martix设置的信息缩放
        mBitmap = Bitmap.createScaledBitmap(mBitmap, size, size, false);

        int[] pixels = new int[size * size];
        boolean flag = true;
        for (int y = 0; y < size; y++) {
            for (int x = 0; x < size; x++) {
                if (bitMatrix.get(x, y)) {
                    if (flag) {
                        flag = false;
                        pixels[y * size + x] = 0xff000000;
                    } else {
                        pixels[y * size + x] = mBitmap.getPixel(x, y);
                        flag = true;
                    }
                } else {
                    pixels[y * size + x] = 0xffffffff;
                }
            }
        }
        Bitmap bitmap = Bitmap.createBitmap(size, size,
                Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
        return bitmap;
    } catch (WriterException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:AnyRTC,项目名称:anyRTC-RTCP-Android,代码行数:48,代码来源:QRCode.java

示例11: lineGray

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 实现对图像进行线性灰度化处理
 *
 * @param origin bitmap
 * @return Bitmap
 */
public static Bitmap lineGray(Bitmap origin) {
    int width = origin.getWidth();
    int height = origin.getHeight();
    Bitmap bitmap = origin.copy(Bitmap.Config.ARGB_8888, true);
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            int col = origin.getPixel(i, j);
            int alpha = col & 0xFF000000;
            int red = (col & 0x00FF0000) >> 16;
            int green = (col & 0x0000FF00) >> 8;
            int blue = (col & 0x000000FF);
            red = (int) (1.1 * red + 30);
            green = (int) (1.1 * green + 30);
            blue = (int) (1.1 * blue + 30);
            if (red >= 255) {
                red = 255;
            }
            if (green >= 255) {
                green = 255;
            }
            if (blue >= 255) {
                blue = 255;
            }
            int newColor = alpha | (red << 16) | (green << 8) | blue;
            bitmap.setPixel(i, j, newColor);
        }
    }
    return bitmap;
}
 
开发者ID:shenhuanet,项目名称:Ocr-android,代码行数:36,代码来源:BitmapUtils.java

示例12: calcDrawableColor

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static int[] calcDrawableColor(Drawable drawable) {
    int bitmapColor = 0xff000000;
    int result[] = new int[2];
    try {
        if (drawable instanceof BitmapDrawable) {
            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
            if (bitmap != null) {
                Bitmap b = Bitmaps.createScaledBitmap(bitmap, 1, 1, true);
                if (b != null) {
                    bitmapColor = b.getPixel(0, 0);
                    b.recycle();
                }
            }
        } else if (drawable instanceof ColorDrawable) {
            bitmapColor = ((ColorDrawable) drawable).getColor();
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    double[] hsv = rgbToHsv((bitmapColor >> 16) & 0xff, (bitmapColor >> 8) & 0xff, bitmapColor & 0xff);
    hsv[1] = Math.min(1.0, hsv[1] + 0.05 + 0.1 * (1.0 - hsv[1]));
    hsv[2] = Math.max(0, hsv[2] * 0.65);
    int rgb[] = hsvToRgb(hsv[0], hsv[1], hsv[2]);
    result[0] = Color.argb(0x66, rgb[0], rgb[1], rgb[2]);
    result[1] = Color.argb(0x88, rgb[0], rgb[1], rgb[2]);
    return result;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:29,代码来源:AndroidUtilities.java

示例13: IcsColorDrawable

import android.graphics.Bitmap; //导入方法依赖的package包/类
public IcsColorDrawable(ColorDrawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    drawable.draw(c);
    this.color = bitmap.getPixel(0, 0);
    bitmap.recycle();
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:8,代码来源:IcsColorDrawable.java

示例14: binarize

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static void binarize(Bitmap bitmap, int threshold) {
    int r, g, b;
    for (int y = 0; y < bitmap.getHeight(); y++) {
        for (int x = 0; x < bitmap.getHeight(); x++) {
            int color = bitmap.getPixel(x, y);
            r = (color >> 16) & 0xFF;
            g = (color >> 8) & 0xFF;
            b = color & 0xFF;
            float sum = 0.30f * r + 0.59f * g + 0.11f * b;
            bitmap.setPixel(x, y, sum > threshold ? Color.WHITE : Color.BLACK);
        }
    }
}
 
开发者ID:SumiMakito,项目名称:AwesomeQRCode,代码行数:14,代码来源:AwesomeQRCode.java

示例15: pick

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static int pick(int index, int x, int y) {
	Bitmap bmp = TextureCache.get(Assets.ITEMS).bitmap;
	int rows = bmp.getWidth() / SIZE;
	int row = index / rows;
	int col = index % rows;
	return bmp.getPixel(col * SIZE + x, row * SIZE + y);
}
 
开发者ID:G2159687,项目名称:ESPD,代码行数:8,代码来源:ItemSprite.java


注:本文中的android.graphics.Bitmap.getPixel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。