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


Java Bitmap.getHeight方法代码示例

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


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

示例1: decodeWithZxing

import android.graphics.Bitmap; //导入方法依赖的package包/类
public String decodeWithZxing(Bitmap bitmap) {
    MultiFormatReader multiFormatReader = new MultiFormatReader();
    multiFormatReader.setHints(changeZXingDecodeDataMode());

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);

    Result rawResult = null;
    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);

    if (source != null) {
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(binaryBitmap);
        } catch (ReaderException re) {
            // continue
        } finally {
            multiFormatReader.reset();
        }
    }

    return rawResult != null ? rawResult.getText() : null;
}
 
开发者ID:snice,项目名称:androidscan,代码行数:26,代码来源:DecodeUtils.java

示例2: canUseForInBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * @param candidate - Bitmap to check
 * @param targetOptions - Options that have the out* value populated
 * @return true if <code>candidate</code> can be used for inBitmap re-use with
 *      <code>targetOptions</code>
 */
@TargetApi(VERSION_CODES.KITKAT)
private static boolean canUseForInBitmap(
        Bitmap candidate, BitmapFactory.Options targetOptions) {
    //BEGIN_INCLUDE(can_use_for_inbitmap)
    if (!Utils.hasKitKat()) {
        // On earlier versions, the dimensions must match exactly and the inSampleSize must be 1
        return candidate.getWidth() == targetOptions.outWidth
                && candidate.getHeight() == targetOptions.outHeight
                && targetOptions.inSampleSize == 1;
    }

    // From Android 4.4 (KitKat) onward we can re-use if the byte size of the new bitmap
    // is smaller than the reusable bitmap candidate allocation byte count.
    int width = targetOptions.outWidth / targetOptions.inSampleSize;
    int height = targetOptions.outHeight / targetOptions.inSampleSize;
    int byteCount = width * height * getBytesPerPixel(candidate.getConfig());
    return byteCount <= candidate.getAllocationByteCount();
    //END_INCLUDE(can_use_for_inbitmap)
}
 
开发者ID:jjuiddong,项目名称:Android-Practice,代码行数:26,代码来源:ImageCache.java

示例3: circleCrop

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
开发者ID:lai233333,项目名称:MyDemo,代码行数:20,代码来源:GlideCircleTransform.java

示例4: toOvalBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Create a new bitmap that has all pixels beyond the oval shape transparent.
 * Old bitmap is recycled.
 */
public static Bitmap toOvalBitmap(@NonNull Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    int color = 0xff424242;
    Paint paint = new Paint();

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);

    RectF rect = new RectF(0, 0, width, height);
    canvas.drawOval(rect, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);

    bitmap.recycle();

    return output;
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:28,代码来源:CropImage.java

示例5: circleCrop

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = size / 2.0f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
开发者ID:jutao,项目名称:GankReader,代码行数:21,代码来源:GlideCircleTransform.java

示例6: extractThumbnail

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap extractThumbnail(Bitmap source, int width, int height,
                                      int options) {
    if (source == null) {
        return null;
    }
    float scale;
    if (source.getWidth() < source.getHeight()) {
        scale = width / (float) source.getWidth();
    } else {
        scale = height / (float) source.getHeight();
    }
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    return transform(matrix, source, width, height,
            OPTIONS_SCALE_UP | options);
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:17,代码来源:FeThumbUtils.java

示例7: getSquareBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * Gets square bitmap.
 *
 * @param src  the src
 * @param rate the rate
 * @return the square bitmap
 */
public static Bitmap getSquareBitmap(Bitmap src, float rate) {
    if (src == null || src.isRecycled())
        return null;
    Bitmap ret = src;
    int w = src.getWidth();
    int h = src.getHeight();
    int min = Math.min(w, h);
    int max = Math.max(w, h);
    float r = (float) (max - min) / (float) min;
    if (w != h && r > rate) {
        max = Math.round((1.0f + rate) * min);
        if (w > h) {
            ret = Bitmap.createBitmap(src, (w - max) / 2, 0, max, min);
        } else {
            ret = Bitmap.createBitmap(src, 0, (h - max) / 2, min, max);
        }
    }
    return ret;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:27,代码来源:BmpUtil.java

示例8: getBGRAImageByte

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
     * Get the pixels by byte[] of Bitmap
     * @param image
	 * @return pixels by byte[]
     */
    public static int[] getBGRAImageByte(Bitmap image) {
        int width = image.getWidth();
        int height = image.getHeight();

		if(image.getConfig().equals(Config.ARGB_8888)) {
	        int[] imgData = new int[width * height];
	        image.getPixels(imgData, 0, width, 0, 0, width, height);
	        return imgData;
	       
//	        byte[] imgPixels = new byte[width * height];
//	        for (int i = 0; i < imgData.length; ++i) {
//	        	int p = 0;
//	        	//p += ((imgData[i] >> 24) & 0xFF);
//	        	p += ((imgData[i] >> 16) & 0xFF);
//	        	p += ((imgData[i] >> 8) & 0xFF);
//	        	p += ((imgData[i] >> 0) & 0xFF);
//	            imgPixels[i] = (byte) (p/3);
//	        }
		} else {
			// TODO
		}

        return null;
    }
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:30,代码来源:STUtils.java

示例9: transform

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();
  int size = Math.min(source.getWidth(), source.getHeight());

  mWidth = (source.getWidth() - size) / 2;
  mHeight = (source.getHeight() - size) / 2;

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(mWidth, mHeight, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(source, mWidth, mHeight, size, size);
  }

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
开发者ID:open-android,项目名称:Glide-transformations,代码行数:18,代码来源:CropSquareTransformation.java

示例10: getCroppedRoundBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap squareBitmap;
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    Bitmap bitmap;
    int i;
    if (bmpHeight > bmpWidth) {
        bitmap = bmp;
        i = (bmpHeight - bmpWidth) / 2;
        squareBitmap = Bitmap.createBitmap(bitmap, 0, i, bmpWidth, bmpWidth);
    } else if (bmpHeight < bmpWidth) {
        int x = (bmpWidth - bmpHeight) / 2;
        bitmap = bmp;
        i = 0;
        squareBitmap = Bitmap.createBitmap(bitmap, x, i, bmpHeight, bmpHeight);
    } else {
        squareBitmap = bmp;
    }
    if (squareBitmap.getWidth() == diameter && squareBitmap.getHeight() == diameter) {
        scaledSrcBmp = squareBitmap;
    } else {
        scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);
    }
    Bitmap output = Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle((float) (scaledSrcBmp.getWidth() / 2), (float) (scaledSrcBmp.getHeight() / 2), (float) (scaledSrcBmp.getWidth() / 2), paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    return output;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:39,代码来源:RoundImageView.java

示例11: bitmap2grayByteArry

import android.graphics.Bitmap; //导入方法依赖的package包/类
public static byte[][] bitmap2grayByteArry(Bitmap bm) {
    byte[][] grayImage = new byte[bm.getHeight()][bm.getWidth()];
    for (int i = 0; i < bm.getWidth(); i++) {
        for (int j = 0; j < bm.getHeight(); j++) {
            if (bm.getPixel(i, j) == Color.WHITE) {
                grayImage[j][i] = 0;
            } else {
                grayImage[j][i] = 1;
            }
        }
    }
    return grayImage;
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:14,代码来源:OCRUtility.java

示例12: getScaledDownBitmap

import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
 * @param bitmap                the Bitmap to be scaled
 * @param threshold             the maxium dimension (either width or height) of the scaled bitmap
 * @param isNecessaryToKeepOrig is it necessary to keep the original bitmap? If not recycle the original bitmap to prevent memory leak.
 */

public static Bitmap getScaledDownBitmap(Bitmap bitmap, int threshold, boolean isNecessaryToKeepOrig) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int newWidth = width;
    int newHeight = height;

    if (width > height && width > threshold) {
        newWidth = threshold;
        newHeight = (int) (height * (float) newWidth / width);
    }

    if (width > height && width <= threshold) {
        //the bitmap is already smaller than our required dimension, no need to resize it
        return bitmap;
    }

    if (width < height && height > threshold) {
        newHeight = threshold;
        newWidth = (int) (width * (float) newHeight / height);
    }

    if (width < height && height <= threshold) {
        //the bitmap is already smaller than our required dimension, no need to resize it
        return bitmap;
    }

    if (width == height && width > threshold) {
        newWidth = threshold;
        newHeight = newWidth;
    }

    if (width == height && width <= threshold) {
        //the bitmap is already smaller than our required dimension, no need to resize it
        return bitmap;
    }

    return getResizedBitmap(bitmap, newWidth, newHeight, isNecessaryToKeepOrig);
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:45,代码来源:ImageUtil.java

示例13: display

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_4444);

    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);

    //--CROP THE IMAGE
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2 - 1, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    //--ADD BORDER IF NEEDED
    if(this.borderWidth > 0){
        final Paint paint2 = new Paint();
        paint2.setAntiAlias(true);
        paint2.setColor(this.borderColor);
        paint2.setStrokeWidth(this.borderWidth);
        paint2.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, (float) (bitmap.getWidth() / 2 - Math.ceil(this.borderWidth / 2)), paint2);
    }
    imageAware.setImageBitmap(output);
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:31,代码来源:CircleBitmapDisplayer.java

示例14: transform

import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;
    Bitmap result = Bitmap.createBitmap(source, x, y, size, size);
    if (result != source) {
        //回收
        source.recycle();
    }
    return result;
}
 
开发者ID:lijizhi,项目名称:studydemo,代码行数:13,代码来源:PicassoUtils.java

示例15: assertHasOriginalAspectRatio

import android.graphics.Bitmap; //导入方法依赖的package包/类
private static void assertHasOriginalAspectRatio(Bitmap original, Bitmap transformed) {
  double originalAspectRatio = (double) original.getWidth() / (double) original.getHeight();
  double transformedAspectRatio =
      (double) transformed.getWidth() / (double) transformed.getHeight();

  assertThat(transformedAspectRatio)
      .isIn(Range.open(originalAspectRatio - 0.05f, originalAspectRatio + 0.05f));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:TransformationUtilsTest.java


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