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


Java Bitmap.setPixels方法代码示例

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


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

示例1: renderCroppedGreyscaleBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;

    for (int y = 0; y < height; y++) {
        int outputOffset = y * width;
        for (int x = 0; x < width; x++) {
            int grey = yuv[inputOffset + x] & 0xff;
            pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
        }
        inputOffset += dataWidth;
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
开发者ID:Jusenr,项目名称:zxing_qrcode_demo,代码行数:21,代码来源:PlanarYUVLuminanceSource.java

示例2: syncEncodeQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 同步创建指定前景色、指定背景色、带logo的二维码图片。该方法是耗时操作,请在子线程中调用。
 *
 * @param content         要生成的二维码图片内容
 * @param size            图片宽高,单位为px
 * @param foregroundColor 二维码图片的前景色
 * @param backgroundColor 二维码图片的背景色
 * @param logo            二维码图片的logo
 */
public static Bitmap syncEncodeQRCode(String content, int size, int foregroundColor, int backgroundColor, Bitmap logo) {
    try {
        BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size, HINTS);
        int[] pixels = new int[size * size];
        for (int y = 0; y < size; y++) {
            for (int x = 0; x < size; x++) {
                if (matrix.get(x, y)) {
                    pixels[y * size + x] = foregroundColor;
                } else {
                    pixels[y * size + x] = backgroundColor;
                }
            }
        }
        Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
        return addLogoToQRCode(bitmap, logo);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:yinhaojun,项目名称:ZxingForAndroid,代码行数:30,代码来源:QRCodeEncoder.java

示例3: createQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap createQRCode(String str,int widthAndHeight) throws WriterException {
	Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();  
       hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
	BitMatrix matrix = new MultiFormatWriter().encode(str,
			BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
	int width = matrix.getWidth();
	int height = matrix.getHeight();
	int[] pixels = new int[width * height];
	
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (matrix.get(x, y)) {
				pixels[y * width + x] = BLACK;
			}
		}
	}
	Bitmap bitmap = Bitmap.createBitmap(width, height,
			Bitmap.Config.ARGB_8888);
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:EncodingHandler.java

示例4: renderCroppedGreyscaleBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap renderCroppedGreyscaleBitmap() {
  int width = getWidth();
  int height = getHeight();
  int[] pixels = new int[width * height];
  byte[] yuv = yuvData;
  int inputOffset = top * dataWidth + left;

  for (int y = 0; y < height; y++) {
    int outputOffset = y * width;
    for (int x = 0; x < width; x++) {
      int grey = yuv[inputOffset + x] & 0xff;
      pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
    }
    inputOffset += dataWidth;
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  return bitmap;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:PlanarYUVLuminanceSource.java

示例5: createQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    BitMatrix matrix = new MultiFormatWriter().encode(str,
            BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (matrix.get(x, y)) {
                pixels[y * width + x] = BLACK;
            }
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
开发者ID:guxiaonian,项目名称:MeiLa_GNN,代码行数:22,代码来源:EncodingHandler.java

示例6: createBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Creates a bitmap with the specified width and height.  Its initial density is
 * determined from the given DisplayMetrics.
 *
 * @param display Display metrics for the display this bitmap will be drawn on
 * @param colors The colors to write to the bitmap
 * @param offset The index of the first color to read from colors[]
 * @param stride The number of colors in pixels[] to skip between rows.
 * @param width The width of the bitmap
 * @param height The height of the bitmap
 * @param config The bitmap config to create
 * @param callerContext the Tag to track who create the Bitmap
 * @return a reference to the bitmap
 * @throws IllegalArgumentException if the width or height are <= 0
 * @throws TooManyBitmapsException if the pool is full
 * @throws java.lang.OutOfMemoryError if the Bitmap cannot be allocated
 */
public CloseableReference<Bitmap> createBitmap(
    DisplayMetrics display,
    int[] colors,
    int offset,
    int stride,
    int width,
    int height,
    Bitmap.Config config,
    @Nullable Object callerContext) {
  CloseableReference<Bitmap> bitmapRef = createBitmap(
      display,
      width,
      height,
      config,
      callerContext);
  Bitmap bitmap = bitmapRef.get();
  bitmap.setPixels(colors, offset, stride, 0, 0, width, height);
  return bitmapRef;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:PlatformBitmapFactory.java

示例7: renderCroppedGreyscaleBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap renderCroppedGreyscaleBitmap() {
	int width = getWidth();
	int height = getHeight();
	int[] pixels = new int[width * height];
	byte[] yuv = yuvData;
	int inputOffset = top * dataWidth + left;

	for (int y = 0; y < height; y++) {
		int outputOffset = y * width;
		for (int x = 0; x < width; x++) {
			int grey = yuv[inputOffset + x] & 0xff;
			pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
		}
		inputOffset += dataWidth;
	}

	Bitmap bitmap = Bitmap.createBitmap(width, height,
			Bitmap.Config.ARGB_8888);
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;
}
 
开发者ID:guzhigang001,项目名称:Zxing,代码行数:22,代码来源:PlanarYUVLuminanceSource.java

示例8: createQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap createQRCode(String str, int size) throws WriterException {
	Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
	hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
	BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, size, size);
	int width = matrix.getWidth();
	int height = matrix.getHeight();
	int[] pixels = new int[width * height];
	for(int x = 0; x < width; x ++){
		for(int y = 0; y < height; y ++){
			if(matrix.get(x, y)){
				pixels[y * width + x] = BLACK;
			}
		}
	}
	Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;
}
 
开发者ID:yun2win,项目名称:tvConnect_android,代码行数:19,代码来源:EncodingHandler.java

示例9: renderCroppedGreyscaleBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap renderCroppedGreyscaleBitmap() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = new int[width * height];
    byte[] yuv = yuvData;
    int inputOffset = top * dataWidth + left;

    for (int y = 0; y < height; y++) {
      int outputOffset = y * width;
      for (int x = 0; x < width; x++) {
        int grey = yuv[inputOffset + x] & 0xff;
        pixels[outputOffset + x] = 0xFF000000 | (grey * 0x00010101);
      }
      inputOffset += dataWidth;
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
//    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
  }
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:22,代码来源:PlanarYUVLuminanceSource.java

示例10: createQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 根据宽高生成二维码
 *
 * @param width
 * @param height
 * @param source
 * @return
 */
public static Bitmap createQRCode(int width, int height, String source) {
	try {
		if (TextUtils.isEmpty(source)) {
			return null;
		}
		Hashtable<EncodeHintType, String> hints = new Hashtable<>();
		hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
		BitMatrix bitMatrix = new QRCodeWriter().encode(source, BarcodeFormat.QR_CODE, width, height, hints);
		int[] pixels = new int[width * height];
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				if (bitMatrix.get(x, y)) {
					pixels[y * width + x] = 0xff000000;
				} else {
					pixels[y * width + x] = 0xffffffff;
				}
			}
		}
		// sheng chen de er wei ma
		Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
		bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
		return bitmap;
	} catch (WriterException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:guzhigang001,项目名称:Zxing,代码行数:36,代码来源:Util.java

示例11: encodeAsBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
Bitmap encodeAsBitmap() throws WriterException {
  String contentsToEncode = contents;
  if (contentsToEncode == null) {
    return null;
  }
  Map<EncodeHintType,Object> hints = null;
  String encoding = guessAppropriateEncoding(contentsToEncode);
  if (encoding != null) {
    hints = new EnumMap<EncodeHintType,Object>(EncodeHintType.class);
    hints.put(EncodeHintType.CHARACTER_SET, encoding);
  }
  BitMatrix result;
  try {
    result = new MultiFormatWriter().encode(contentsToEncode, format, dimension, dimension, hints);
  } catch (IllegalArgumentException iae) {
    // Unsupported format
    return null;
  }
  int width = result.getWidth();
  int height = result.getHeight();
  int[] pixels = new int[width * height];
  for (int y = 0; y < height; y++) {
    int offset = y * width;
    for (int x = 0; x < width; x++) {
      pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
    }
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  return bitmap;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:33,代码来源:QRCodeEncoder.java

示例12: renderQRCode

import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap renderQRCode(String barcode, BarcodeFormat format, int width) throws WriterException {
    float scale = this.context.getResources().getDisplayMetrics().density;

    width *= scale * 0.6;

    Writer barWriter = new MultiFormatWriter();
    Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);
    BitMatrix bm = barWriter.encode(barcode, format, width, width);

    for (int j = 0; j < width; j++) {
        int[] row = new int[width];
        for (int i = 0; i < width; i++) {
            row[i] = bm.get(i, j) ? Color.BLACK : Color.TRANSPARENT;
        }
        bitmap.setPixels(row, 0, width, 0, j, width, 1);
    }

    CropUtility cropUtility = new CropUtility();
    Bitmap cropped = cropUtility.rectangularCrop(bitmap, Color.TRANSPARENT, 0);

    FactoryManager manager = new FactoryManager();
    ShapeFactory shapeFactory = manager.getRecommendedShapeFactory();
    return shapeFactory.createShape(new RectangleShape(this.context), cropped, Constants.LOGO_BACKGROUND_COLOUR, padding);
}
 
开发者ID:AbyxBelgium,项目名称:Loyalty,代码行数:25,代码来源:BarcodeGenerator.java

示例13: getBitmapFromData

import android.graphics.Bitmap; //导入方法依赖的package包/类
protected static Bitmap getBitmapFromData(int[] pixels, int width, int height){
	Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;		
}
 
开发者ID:januslo,项目名称:react-native-sunmi-inner-printer,代码行数:6,代码来源:BytesUtil.java

示例14: adjustTone

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 更改图片色系,变亮或变暗
 *
 * @param delta 图片的亮暗程度值,越小图片会越亮,取值范围(0,24)
 * @return
 */
public static Bitmap adjustTone(Bitmap src, int delta) {
    if (delta >= 24 || delta <= 0) {
        return null;
    }
    // 设置高斯矩阵
    int[] gauss = new int[]{1, 2, 1, 2, 4, 2, 1, 2, 1};
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;
    int pixColor = 0;
    int newR = 0;
    int newG = 0;
    int newB = 0;
    int idx = 0;
    int[] pixels = new int[width * height];

    src.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            idx = 0;
            for (int m = -1; m <= 1; m++) {
                for (int n = -1; n <= 1; n++) {
                    pixColor = pixels[(i + m) * width + k + n];
                    pixR = Color.red(pixColor);
                    pixG = Color.green(pixColor);
                    pixB = Color.blue(pixColor);

                    newR += (pixR * gauss[idx]);
                    newG += (pixG * gauss[idx]);
                    newB += (pixB * gauss[idx]);
                    idx++;
                }
            }
            newR /= delta;
            newG /= delta;
            newB /= delta;
            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));
            pixels[i * width + k] = Color.argb(255, newR, newG, newB);
            newR = 0;
            newG = 0;
            newB = 0;
        }
    }
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:60,代码来源:XBitmapUtils.java

示例15: film

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * 底片效果处理
 *
 * @param bitmap 原图
 * @return 底片效果处理后的图片
 */
public static Bitmap film(Bitmap bitmap) {
    // RGBA的最大值
    final int MAX_VALUE = 255;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height,
            Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    int pos = 0;
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            pos = i * width + k;
            pixColor = pixels[pos];

            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);

            newR = MAX_VALUE - pixR;
            newG = MAX_VALUE - pixG;
            newB = MAX_VALUE - pixB;

            newR = Math.min(MAX_VALUE, Math.max(0, newR));
            newG = Math.min(MAX_VALUE, Math.max(0, newG));
            newB = Math.min(MAX_VALUE, Math.max(0, newB));

            pixels[pos] = Color.argb(MAX_VALUE, newR, newG, newB);
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}
 
开发者ID:youth5201314,项目名称:XFrame,代码行数:52,代码来源:XBitmapUtils.java


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