本文整理汇总了Java中android.graphics.Bitmap.getWidth方法的典型用法代码示例。如果您正苦于以下问题:Java Bitmap.getWidth方法的具体用法?Java Bitmap.getWidth怎么用?Java Bitmap.getWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Bitmap
的用法示例。
在下文中一共展示了Bitmap.getWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotateImageExif
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Rotate and/or flip the image to match the given exif orientation.
*
* @param pool A pool that may or may not contain an image of the necessary
* dimensions.
* @param inBitmap The bitmap to rotate/flip.
* @param exifOrientation the exif orientation [1-8].
* @return The rotated and/or flipped image or toOrient if no rotation or flip was necessary.
*/
public static Bitmap rotateImageExif(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap,
int exifOrientation) {
if (!isExifOrientationRequired(exifOrientation)) {
return inBitmap;
}
final Matrix matrix = new Matrix();
initializeMatrixForRotation(exifOrientation, matrix);
// From Bitmap.createBitmap.
final RectF newRect = new RectF(0, 0, inBitmap.getWidth(), inBitmap.getHeight());
matrix.mapRect(newRect);
final int newWidth = Math.round(newRect.width());
final int newHeight = Math.round(newRect.height());
Bitmap.Config config = getSafeConfig(inBitmap);
Bitmap result = pool.get(newWidth, newHeight, config);
matrix.postTranslate(-newRect.left, -newRect.top);
applyMatrix(inBitmap, result, matrix);
return result;
}
示例2: 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;
}
示例3: transform
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public Bitmap transform(Bitmap source) {
int w = source.getWidth();
int h = source.getHeight();
Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmp);
Shader shader = new BitmapShader(source, Shader.TileMode.MIRROR,
Shader.TileMode.MIRROR);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
paint.setAntiAlias(true);
paint.setShader(shader);
RectF rec = new RectF(0, 0, w, h - (h/3));
c.drawRect(new RectF(0, (h/3), w, h), paint);
c.drawRoundRect(rec, cornerRadius, cornerRadius, paint);
source.recycle();
return bmp;
}
示例4: transform
import android.graphics.Bitmap; //导入方法依赖的package包/类
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
Bitmap source = resource.get();
int width = source.getWidth();
int height = source.getHeight();
Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888);
if (bitmap == null) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
drawRoundRect(canvas, paint, width, height);
return BitmapResource.obtain(bitmap, mBitmapPool);
}
示例5: getRoundBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 图片圆角
*
* @param bitmap
* @param pixels
* @return
*/
public static Bitmap getRoundBitmap(Bitmap bitmap, int pixels) {
if (bitmap == null) {
return null;
}
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xffffffff;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例6: roundCrop
import android.graphics.Bitmap; //导入方法依赖的package包/类
private static Bitmap roundCrop(BitmapPool pool, Bitmap source)
{
if (source == null) return null;
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
if (result == null)
{
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
canvas.drawRoundRect(rectF, radius, radius, paint);
return result;
}
示例7: addLogo
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 在二维码中间添加Logo图案
*/
private static Bitmap addLogo(Bitmap src, Bitmap logo) {
if (src == null) {
return null;
}
if (logo == null) {
return src;
}
//获取图片的宽高
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int logoWidth = logo.getWidth();
int logoHeight = logo.getHeight();
if (srcWidth == 0 || srcHeight == 0) {
return null;
}
if (logoWidth == 0 || logoHeight == 0) {
return src;
}
//logo大小为二维码整体大小的1/5
float scaleFactor = srcWidth * 1.0f / 5 / logoWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
try {
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
} catch (Exception e) {
bitmap = null;
e.getStackTrace();
}
return bitmap;
}
示例8: getRoundedCroppedBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
} else {
finalBitmap = bitmap;
}
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(finalBitmap.getWidth() / 2,
finalBitmap.getHeight() / 2,
finalBitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
示例9: decode
import android.graphics.Bitmap; //导入方法依赖的package包/类
boolean decode() {
// Get a tile from the original image. The tile is down-scaled
// by (1 << mTilelevel) from a region in the original image.
try {
Bitmap reuse = sTilePool.acquire();
if (reuse != null && reuse.getWidth() != mTileSize) {
reuse = null;
}
mDecodedTile = mModel.getTile(mTileLevel, mX, mY, reuse);
} catch (Throwable t) {
Log.w(TAG, "fail to decode tile", t);
}
return mDecodedTile != null;
}
示例10: adjustPhotoRotation
import android.graphics.Bitmap; //导入方法依赖的package包/类
public static Bitmap adjustPhotoRotation(Bitmap inputBitmap, int orientationDegree) {
if (inputBitmap == null) {
return null;
}
Matrix matrix = new Matrix();
matrix.setRotate(orientationDegree, (float) inputBitmap.getWidth() / 2, (float) inputBitmap.getHeight() / 2);
float outputX, outputY;
if (orientationDegree == 90) {
outputX = inputBitmap.getHeight();
outputY = 0;
} else {
outputX = inputBitmap.getHeight();
outputY = inputBitmap.getWidth();
}
final float[] values = new float[9];
matrix.getValues(values);
float x1 = values[Matrix.MTRANS_X];
float y1 = values[Matrix.MTRANS_Y];
matrix.postTranslate(outputX - x1, outputY - y1);
Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getHeight(), inputBitmap.getWidth(), Bitmap.Config.ARGB_8888);
Paint paint = new Paint();
Canvas canvas = new Canvas(outputBitmap);
canvas.drawBitmap(inputBitmap, matrix, paint);
return outputBitmap;
}
示例11: getRoundedCroppedBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
private Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
Bitmap finalBitmap;
if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) {
finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
} else {
finalBitmap = bitmap;
}
Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
finalBitmap.getHeight());
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(Color.parseColor("#BAB399"));
canvas.drawCircle(finalBitmap.getWidth() / 2,
finalBitmap.getHeight() / 2,
finalBitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(finalBitmap, rect, rect, paint);
return output;
}
示例12: toRoundCorner
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* 转为圆角图片
*
* @param src 源图片
* @param radius 圆角的度数
* @param borderSize 边框尺寸
* @param borderColor 边框颜色
* @param recycle 是否回收
* @return 圆角图片
*/
public static Bitmap toRoundCorner(final Bitmap src, final float radius, int borderSize, int borderColor, final boolean recycle) {
if (isEmptyBitmap(src)) {
return null;
}
int width = src.getWidth();
int height = src.getHeight();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
Canvas canvas = new Canvas(ret);
RectF rectF = new RectF(0, 0, width, height);
float halfBorderSize = borderSize / 2f;
rectF.inset(halfBorderSize, halfBorderSize);
canvas.drawRoundRect(rectF, radius, radius, paint);
if (borderSize > 0) {
paint.setShader(null);
paint.setColor(borderColor);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(borderSize);
paint.setStrokeCap(Paint.Cap.ROUND);
canvas.drawRoundRect(rectF, radius, radius, paint);
}
if (recycle && !src.isRecycled()) {
src.recycle();
}
return ret;
}
示例13: scaledBitmap
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* Bitmap 宽高缩放
*/
public static Bitmap scaledBitmap(Bitmap source, float destWidth, float destHeight) {
int srcWidth = source.getWidth();
int srcHeight = source.getHeight();
float scaleX = (float) destWidth / srcWidth;// 要强制转换
float scaleY = (float) destHeight / srcHeight;
float scale = Math.min(scaleX, scaleY);
Matrix matrix = new Matrix();
matrix.postScale(scale, scale); // 长和宽放大缩小的比例
return Bitmap.createBitmap(source, 0, 0, srcWidth, srcHeight, matrix, true);
}
示例14: initLEDFrame
import android.graphics.Bitmap; //导入方法依赖的package包/类
private void initLEDFrame(LEDFrame ledFrame,Bitmap bitmap){
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Log.d("scott","bitmap w : " + w + " bitmap h = " + h);
for(int x = 0;x<w;x++){
for(int y = 0;y<h;y++){
ledFrame.fillData(y,x,bitmap.getPixel(x,y));
}
}
}
示例15: drawDrawable
import android.graphics.Bitmap; //导入方法依赖的package包/类
/**
* draw Rounded Rectangle
*
* @param canvas
* @param bitmap
*/
private void drawDrawable(Canvas canvas, Bitmap bitmap) {
Paint paint = new Paint();
paint.setColor(0xffffffff);
paint.setAntiAlias(true); //smooths out the edges of what is being drawn
PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
// set flags
int saveFlags = Canvas.MATRIX_SAVE_FLAG
| Canvas.CLIP_SAVE_FLAG
| Canvas.HAS_ALPHA_LAYER_SAVE_FLAG
| Canvas.FULL_COLOR_LAYER_SAVE_FLAG
| Canvas.CLIP_TO_LAYER_SAVE_FLAG;
canvas.saveLayer(0, 0, width, height, null, saveFlags);
if (shapeType == 1) {
canvas.drawCircle(width / 2, height / 2, width / 2 - 1, paint);
} else if (shapeType == 2) {
RectF rectf = new RectF(1, 1, getWidth() - 1, getHeight() - 1);
canvas.drawRoundRect(rectf, radius + 1, radius + 1, paint);
}
paint.setXfermode(xfermode);
float scaleWidth = ((float) getWidth()) / bitmap.getWidth();
float scaleHeight = ((float) getHeight()) / bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
//bitmap scale
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
canvas.drawBitmap(bitmap, 0, 0, paint);
canvas.restore();
}