本文整理了Java中android.graphics.Bitmap.getPixel()
方法的一些代码示例,展示了Bitmap.getPixel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.getPixel()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:getPixel
暂无
代码示例来源:origin: stackoverflow.com
private int getOverlapDistance(Bitmap bottomBitmap) {
int height = bottomBitmap.getHeight();
int width = bottomBitmap.getWidth();
int distance = 0;
for (int i = 0; i < height; i++) {
if (Color.alpha(bottomBitmap.getPixel(width - 1, i)) != 0) {
distance = (i + 1);
break;
}
}
return distance;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testGetPixels() {
// Create a dummy bitmap.
Bitmap bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
for (int y = 0; y < bmp.getHeight(); ++y) {
for (int x = 0; x < bmp.getWidth(); ++x) {
bmp.setPixel(x, y, packRGB(x, y, 0));
}
}
// Use getPixels to get pixels as an array (getPixels was the missing Shadowed Function).
int[] pixels = new int[bmp.getWidth() * bmp.getHeight()];
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
// Every entry should match regardless of accessing it by getPixel vs getPixels.
for (int y = 0; y < bmp.getHeight(); ++y) {
for (int x = 0; x < bmp.getWidth(); ++x) {
assertThat(bmp.getPixel(x, y)).isEqualTo(pixels[y * bmp.getWidth() + x]);
}
}
}
代码示例来源:origin: WangDaYeeeeee/Mysplash
private int computeBackgroundColor(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.setScale((float) (1.0 / bitmap.getWidth()), (float) (1.0 / 2.0));
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), 2, matrix, false);
return bitmap.getPixel(0, 0);
}
代码示例来源:origin: stackoverflow.com
Bitmap bitmap = someFunctionReturningABitmap();
long redBucket = 0;
long greenBucket = 0;
long blueBucket = 0;
long pixelCount = 0;
for (int y = 0; y < bitmap.getHeight(); y++)
{
for (int x = 0; x < bitmap.getWidth(); x++)
{
Color c = bitmap.getPixel(x, y);
pixelCount++;
redBucket += Color.red(c);
greenBucket += Color.green(c);
blueBucket += Color.blue(c);
// does alpha matter?
}
}
Color averageColor = Color.rgb(redBucket / pixelCount,
greenBucket / pixelCount,
blueBucket / pixelCount);
代码示例来源:origin: WangDaYeeeeee/Waves
public static int calcBackgroundColor(Bitmap bitmap) {
Matrix matrix = new Matrix();
matrix.setScale((float) (1.0 / bitmap.getWidth()), (float) (1.0 / 2.0));
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), 2, matrix, false);
return bitmap.getPixel(0, 0);
}
代码示例来源:origin: stackoverflow.com
// ** Declare your Bitmap somewhere **
final Bitmap TheBitmap;
TheBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.TheImage);
// ** My onTouch code **
public boolean onTouch(View v, MotionEvent event) {
int eventPadTouch = event.getAction();
switch (eventPadTouch) {
case MotionEvent.ACTION_DOWN:
if (iX>=0 & iY>=0 & iX<TheBitmap.getWidth() & iY<TheBitmap.getHeight()) { // ** Makes sure that X and Y are not less than 0, and no more than the height and width of the image.
if (TheBitmap.getPixel(iX,iY)!=0) {
// * A non-alpha area was clicked, do something
}
}
return true;
}
return false;
}
代码示例来源:origin: ConsideredHamster/YetAnotherPixelDungeon
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 );
}
代码示例来源:origin: google/ExoPlayer
assertThat(firstBitmap.getWidth()).isEqualTo(secondBitmap.getWidth());
assertThat(firstBitmap.getHeight()).isEqualTo(secondBitmap.getHeight());
long mse = 0;
for (int i = 0; i < firstBitmap.getWidth(); i++) {
for (int j = 0; j < firstBitmap.getHeight(); j++) {
int firstColorInt = firstBitmap.getPixel(i, j);
int firstRed = Color.red(firstColorInt);
int firstGreen = Color.green(firstColorInt);
int firstBlue = Color.blue(firstColorInt);
int secondColorInt = secondBitmap.getPixel(i, j);
int secondRed = Color.red(secondColorInt);
int secondGreen = Color.green(secondColorInt);
代码示例来源:origin: qs-lll/ExpandingPager
int A = 0, R = 0, G = 0, B = 0;
int pixelColor;
int height = bitmap.getHeight();
int width = bitmap.getWidth();
pixelColor = bitmap.getPixel(x, y);
A = A + Color.alpha(pixelColor);
R = R + Color.red(pixelColor);
代码示例来源:origin: bumptech/glide
private void assertSamePixels(Bitmap expected, Bitmap actual) {
assertEquals(expected.getWidth(), actual.getWidth());
assertEquals(expected.getHeight(), actual.getHeight());
assertEquals(expected.getConfig(), actual.getConfig());
for (int y = 0; y < expected.getHeight(); y++) {
for (int x = 0; x < expected.getWidth(); x++) {
assertEquals(expected.getPixel(x, y), actual.getPixel(x, y));
}
}
}
代码示例来源:origin: tyrantgit/ExplosionField
public ExplosionAnimator(View container, Bitmap bitmap, Rect bound) {
mPaint = new Paint();
mBound = new Rect(bound);
int partLen = 15;
mParticles = new Particle[partLen * partLen];
Random random = new Random(System.currentTimeMillis());
int w = bitmap.getWidth() / (partLen + 2);
int h = bitmap.getHeight() / (partLen + 2);
for (int i = 0; i < partLen; i++) {
for (int j = 0; j < partLen; j++) {
mParticles[(i * partLen) + j] = generateParticle(bitmap.getPixel((j + 1) * w, (i + 1) * h), random);
}
}
mContainer = container;
setFloatValues(0f, END_VALUE);
setInterpolator(DEFAULT_INTERPOLATOR);
setDuration(DEFAULT_DURATION);
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: google/cameraview
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (android.os.Build.VERSION.SDK_INT < 14) {
return;
}
CameraView cameraView = (CameraView) view;
TextureView textureView = (TextureView) cameraView.findViewById(R.id.texture_view);
Bitmap bitmap = textureView.getBitmap();
int topLeft = bitmap.getPixel(0, 0);
int center = bitmap.getPixel(bitmap.getWidth() / 2, bitmap.getHeight() / 2);
int bottomRight = bitmap.getPixel(
bitmap.getWidth() - 1, bitmap.getHeight() - 1);
assertFalse("Preview possibly blank: " + Integer.toHexString(topLeft),
topLeft == center && center == bottomRight);
}
};
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldCreateBitmapWithColors() throws Exception {
int[] colors = new int[] {
Color.parseColor("#ff0000"), Color.parseColor("#00ff00"), Color.parseColor("#0000ff"),
Color.parseColor("#990000"), Color.parseColor("#009900"), Color.parseColor("#000099")
};
Bitmap bitmap = Bitmap.createBitmap(colors, 3, 2, Bitmap.Config.ARGB_8888);
assertThat(bitmap.getWidth()).isEqualTo(3);
assertThat(bitmap.getHeight()).isEqualTo(2);
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.ARGB_8888);
assertThat(bitmap.getPixel(0, 0)).isEqualTo(Color.parseColor("#ff0000"));
assertThat(bitmap.getPixel(0, 1)).isEqualTo(Color.parseColor("#990000"));
assertThat(bitmap.getPixel(1, 0)).isEqualTo(Color.parseColor("#00ff00"));
assertThat(bitmap.getPixel(1, 1)).isEqualTo(Color.parseColor("#009900"));
assertThat(bitmap.getPixel(2, 0)).isEqualTo(Color.parseColor("#0000ff"));
assertThat(bitmap.getPixel(2, 1)).isEqualTo(Color.parseColor("#000099"));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldCreateActiveBitmap() throws Exception {
Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
assertThat(bitmap.isRecycled()).isFalse();
assertThat(bitmap.getPixel(0, 0)).isEqualTo(0);
assertThat(bitmap.getWidth()).isEqualTo(100);
assertThat(bitmap.getHeight()).isEqualTo(200);
assertThat(bitmap.getConfig()).isEqualTo(Bitmap.Config.ARGB_8888);
}
代码示例来源:origin: google/ExoPlayer
assertThat(firstBitmap.getWidth()).isEqualTo(secondBitmap.getWidth());
assertThat(firstBitmap.getHeight()).isEqualTo(secondBitmap.getHeight());
long mse = 0;
for (int i = 0; i < firstBitmap.getWidth(); i++) {
for (int j = 0; j < firstBitmap.getHeight(); j++) {
int firstColorInt = firstBitmap.getPixel(i, j);
int firstRed = Color.red(firstColorInt);
int firstGreen = Color.green(firstColorInt);
int firstBlue = Color.blue(firstColorInt);
int secondColorInt = secondBitmap.getPixel(i, j);
int secondRed = Color.red(secondColorInt);
int secondGreen = Color.green(secondColorInt);
代码示例来源:origin: yipianfengye/android-zxingLibrary
int scaleHeight = 0;
if (scaleLogo != null) {
scaleWidth = scaleLogo.getWidth();
scaleHeight = scaleLogo.getHeight();
offsetX = (w - scaleWidth) / 2;
offsetY = (h - scaleHeight) / 2;
for (int x = 0; x < w; x++) {
if(x >= offsetX && x < offsetX + scaleWidth && y>= offsetY && y < offsetY + scaleHeight){
int pixel = scaleLogo.getPixel(x-offsetX,y-offsetY);
if(pixel == 0){
if(bitMatrix.get(x, y)){
代码示例来源:origin: bumptech/glide
assertThat(bitmap.getWidth()).isEqualTo(100);
assertThat(bitmap.getHeight()).isEqualTo(100);
for (int x = 0; x < bitmap.getWidth(); x++) {
for (int y = 0; y < bitmap.getHeight(); y++) {
assertThat(bitmap.getPixel(x, y)).isEqualTo(expected.getPixel(x, y));
代码示例来源:origin: stackoverflow.com
final Bitmap bitmap; //Declare bitmap
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.TheImage);
public boolean onTouch(View v, MotionEvent event) {
int eventPadTouch = event.getAction();
float iX=event.getX();
float iY=event.getY();
switch (eventPadTouch) {
case MotionEvent.ACTION_DOWN:
if (iX>=0 & iY>=0 & iX<bitmap.getWidth() & iY<bitmap.getHeight()) { //Makes sure that X and Y are not less than 0, and no more than the height and width of the image.
if (bitmap.getPixel((int) iX, (int) iY)!=0) {
// actual image area is clicked(alpha not equal to 0), do something
}
}
return true;
}
return false;
}
代码示例来源:origin: stackoverflow.com
int imgHeight = bmp.getHeight();
int imgWidth = bmp.getWidth();
if (startWidth == 0) {
for (int y = 0; y < imgHeight; y++) {
if (bmp.getPixel(x, y) != Color.TRANSPARENT) {
startWidth = x;
break;
if (endWidth == 0) {
for (int y = 0; y < imgHeight; y++) {
if (bmp.getPixel(x, y) != Color.TRANSPARENT) {
endWidth = x;
break;
if (startHeight == 0) {
for (int x = 0; x < imgWidth; x++) {
if (bmp.getPixel(x, y) != Color.TRANSPARENT) {
startHeight = y;
break;
if (endHeight == 0 ) {
for (int x = 0; x < imgWidth; x++) {
if (bmp.getPixel(x, y) != Color.TRANSPARENT) {
endHeight = y;
break;
内容来源于网络,如有侵权,请联系作者删除!