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


Java Bitmap.setPixel方法代码示例

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


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

示例1: getQR

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap getQR(final byte[] content, final int size) {
    final QRCodeWriter writer = new QRCodeWriter();
    try {
        final Map<EncodeHintType, Object> encodingHints = new HashMap<>();
        encodingHints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        encodingHints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);

        final BitMatrix encoding = writer.encode(Utils.makeQR(content), BarcodeFormat.QR_CODE, size, size, encodingHints);
        final Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                bitmap.setPixel(i, j, encoding.get(i, j) ? COLOR_DARK : COLOR_LIGHT);
            }
        }

        return bitmap;
    } catch (WriterException e) {
        Log.e("QRUtils", "Failed to get QR code", e);
    }
    return null;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:23,代码来源:QRUtils.java

示例2: 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

示例3: FriskyBlackandWhite

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static    Bitmap FriskyBlackandWhite(Bitmap src){

        Bitmap dest = Bitmap.createBitmap(
                src.getWidth(), src.getHeight(), src.getConfig());

        for(int x = 0; x < src.getWidth(); x++){
            for(int y = 0; y < src.getHeight(); y++){
                int pixelColor = src.getPixel(x, y);
                int pixelAlpha = Color.alpha(pixelColor);
                int pixelRed = Color.red(pixelColor);
                int pixelGreen = Color.green(pixelColor);
                int pixelBlue = Color.blue(pixelColor);

                int pixelBW = (pixelRed + pixelGreen + pixelBlue)/3;
                int newPixel = Color.argb(
                        pixelAlpha, pixelBW, pixelBW, pixelBW);

                dest.setPixel(x, y, newPixel);
            }
        }
        return dest;
    }
 
开发者ID:Dwijraj,项目名称:FriskyImage,代码行数:23,代码来源:FriskyImageProperty.java

示例4: getPreviewBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap getPreviewBitmap() {
	int d = (int) (mDensity * 31); //30dip
	int color = mValue;
	Bitmap bm = Bitmap.createBitmap(d, d, Config.ARGB_8888);
	int w = bm.getWidth();
	int h = bm.getHeight();
	int c = color;
	for (int i = 0; i < w; i++) {
		for (int j = i; j < h; j++) {
			c = (i <= 1 || j <= 1 || i >= w-2 || j >= h-2) ? Color.GRAY : color;
			bm.setPixel(i, j, c);
			if (i != j) {
				bm.setPixel(j, i, c);
			}
		}
	}

	return bm;
}
 
开发者ID:Bregnet,项目名称:TextView_CustomEdit_CustomColor,代码行数:20,代码来源:ColorPickerPreference.java

示例5: create

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static @NonNull Bitmap create(String data) {
  try {
    BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, 512, 512);
    Bitmap    bitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888);

    for (int y = 0; y < result.getHeight(); y++) {
      for (int x = 0; x < result.getWidth(); x++) {
        if (result.get(x, y)) {
          bitmap.setPixel(x, y, Color.BLACK);
        }
      }
    }

    return bitmap;
  } catch (WriterException e) {
    Log.w(TAG, e);
    return Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:20,代码来源:QrCode.java

示例6: 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

示例7: generateQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap generateQRCode(String text) {
    Bitmap bmp = null;

    Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage

    int size = 256;

    BitMatrix bitMatrix = null;
    try {
        bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, size, size, hintMap);

        int width = bitMatrix.getWidth();
        bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < width; y++) {
                bmp.setPixel(y, x, bitMatrix.get(x, y) == true ? Color.BLACK : Color.WHITE);
            }
        }
    } catch (WriterException e) {
        e.printStackTrace();
    }

    return bmp;
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:26,代码来源:PMedia.java

示例8: getQRcodeBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap getQRcodeBitmap(String msg, int width, int height, int margin) {
    QRCodeWriter qw = new QRCodeWriter();

    try {
        HashMap<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        hints.put(EncodeHintType.MARGIN, margin);
        BitMatrix matrix = qw.encode(msg, BarcodeFormat.QR_CODE, width, height, hints);
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < width; y++) {
                bmp.setPixel(x, y, matrix.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }
        return bmp;
    } catch (WriterException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:Zmingxu,项目名称:ZxingScanner,代码行数:22,代码来源:QRCodeUtil.java

示例9: createNewQR

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap createNewQR(String s) {
    MultiFormatWriter mFW = new MultiFormatWriter();
    Bitmap bM = null;

    int px = (int) GraphicUtils.dpToPx(250);

    try {
        BitMatrix bitM = mFW.encode(s, BarcodeFormat.QR_CODE, px, px);
        bM = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        for (int i = 0; i < px; i++) {
            for (int j = 0; j < px; j++) {
                int c = (bitM.get(i, j)) ? Color.BLACK : Color.WHITE;
                bM.setPixel(i, j, c);
            }
        }
    } catch (WriterException e) {
        Utils.logError(e);
    }
    return bM;
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:21,代码来源:QRWriteTask.java

示例10: adjust

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Drawable adjust(Drawable d) {
    int to = Color.RED;

    //Need to copy to ensure that the bitmap is mutable.
    Bitmap src = ((BitmapDrawable) d).getBitmap();
    Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true);
    for(int x = 0;x < bitmap.getWidth();x++)
        for(int y = 0;y < bitmap.getHeight();y++)
            if(match(bitmap.getPixel(x, y)))
                bitmap.setPixel(x, y, to);

    return new BitmapDrawable(bitmap);
}
 
开发者ID:Samehadar,项目名称:IOSDialog,代码行数:14,代码来源:IOSDialog.java

示例11: 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

示例12: setPreviewImage

import android.graphics.Bitmap; //导入方法依赖的package包/类
private void setPreviewImage()
{
	Bitmap preview = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
	preview.setPixel(0, 0, getColor());
	
	imgPreview.setImageBitmap(preview);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:8,代码来源:RgbSelectorView.java

示例13: generateQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 *
 * @param amount
 */
public void generateQRCode(String amount) {

    String coinName = getBaseActivity().getLastSyncedMessage().getCoinName();

    String uriStr = coinName + ":" + _addr;
    if (amount != null && !amount.isEmpty()) {
        uriStr += "?amount="+amount;
    }

    try {
        QRCodeWriter writer = new QRCodeWriter();

        BitMatrix bitMatrix = writer.encode(uriStr, BarcodeFormat.QR_CODE, 512, 512);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }

        _receiveFragmentView.getQrImg().setImageBitmap(bmp);
    } catch (WriterException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ehanoc,项目名称:xwallet,代码行数:32,代码来源:ReceiveFragment.java

示例14: 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

示例15: testDrawFrame

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Test for {@link GLTools#drawFrame(Buffer, int, int, int)}.
 * @throws Exception by some fails
 */
@Test
public final void testDrawFrame() throws Exception {
    final EGLDisplay eglDisplay = GLTools.newDisplay();
    final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true);
    final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig);
    final EGLSurface eglSurface =
            GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE);

    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);

    final int[] attrs = new int[5];
    GLTools.newShader(attrs);
    final int texture = GLTools.newTexture(TEXTURE_LEVEL);

    // 1-st pass
    Bitmap bitmap = Bitmap.createBitmap(FRAME_SIZE, FRAME_SIZE, Bitmap.Config.RGB_565);
    bitmap.setPixel(0, 0, Color.RED); bitmap.setPixel(1, 0, Color.GREEN);
    bitmap.setPixel(0, 1, Color.BLUE); bitmap.setPixel(1, 1, Color.YELLOW);
    ByteBuffer buffer = ByteBuffer.allocate(FRAME_SIZE * FRAME_SIZE * 2);
    bitmap.copyPixelsToBuffer(buffer); bitmap.recycle();

    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);
    GLTools.drawFrame(buffer, FRAME_SIZE, FRAME_SIZE, 0); buffer.clear();
    //GLTools.swapBuffers(eglDisplay, eglSurface);

    buffer = ByteBuffer.allocateDirect(FRAME_SIZE * FRAME_SIZE * 4);
    GLES20.glReadPixels(0, 0, FRAME_SIZE, FRAME_SIZE,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);

    bitmap = Bitmap.createBitmap(FRAME_SIZE, FRAME_SIZE, Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(buffer); buffer.clear(); //bitmap.eraseColor(Color.BLACK);

    Assert.assertArrayEquals(new int[]{bitmap.getPixel(0, 0)}, new int[]{Color.BLUE});
    Assert.assertArrayEquals(new int[]{bitmap.getPixel(1, 0)}, new int[]{Color.YELLOW});
    Assert.assertArrayEquals(new int[]{bitmap.getPixel(0, 1)}, new int[]{Color.RED});
    Assert.assertArrayEquals(new int[]{bitmap.getPixel(1, 1)}, new int[]{Color.GREEN});
    bitmap.recycle();

    // 2-nd pass
    bitmap = Bitmap.createBitmap(FRAME_SIZE, FRAME_SIZE, Bitmap.Config.RGB_565);
    bitmap.setPixel(0, 0, Color.YELLOW); bitmap.setPixel(1, 0, Color.BLUE);
    bitmap.setPixel(0, 1, Color.GREEN); bitmap.setPixel(1, 1, Color.RED);
    buffer = ByteBuffer.allocate(FRAME_SIZE * FRAME_SIZE * 2);
    bitmap.copyPixelsToBuffer(buffer); bitmap.recycle();

    GLTools.makeCurrent(eglDisplay, eglSurface, eglContext);
    GLTools.drawFrame(buffer, FRAME_SIZE, FRAME_SIZE, 0); buffer.clear();
    //GLTools.swapBuffers(eglDisplay, eglSurface);

    buffer = ByteBuffer.allocateDirect(FRAME_SIZE * FRAME_SIZE * 4);
    GLES20.glReadPixels(0, 0, FRAME_SIZE, FRAME_SIZE,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer);

    bitmap = Bitmap.createBitmap(FRAME_SIZE, FRAME_SIZE, Bitmap.Config.ARGB_8888);
    bitmap.copyPixelsFromBuffer(buffer); buffer.clear(); //bitmap.eraseColor(Color.BLACK);

    Assert.assertArrayEquals(new int[]{bitmap.getPixel(0, 0)}, new int[]{Color.GREEN});
    Assert.assertArrayEquals(new int[]{bitmap.getPixel(1, 0)}, new int[]{Color.RED});
    Assert.assertArrayEquals(new int[]{bitmap.getPixel(0, 1)}, new int[]{Color.YELLOW});
    Assert.assertArrayEquals(new int[]{bitmap.getPixel(1, 1)}, new int[]{Color.BLUE});
    bitmap.recycle();

    GLTools.closeTexture(texture, TEXTURE_LEVEL);
    GLTools.closeShader(attrs);

    GLTools.closeSurface(eglDisplay, eglSurface);
    GLTools.closeContext(eglDisplay, eglContext);
    GLTools.closeDisplay(eglDisplay);
}
 
开发者ID:Nik-Gleb,项目名称:mpeg-encoder,代码行数:74,代码来源:GLToolsAndroidTest.java


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