use of android.graphics.Bitmap in project KJFrameForAndroid by kymjs.
the class ImageUtils method getSmallImageFile.
/**
* 压缩图片
*
* @param filePath 源图片地址
* @param width 想要的宽度
* @param height 想要的高度
* @param isAdjust 是否自动调整尺寸, true图片就不会拉伸,false严格按照你的尺寸压缩
* @return Bitmap
*/
public static File getSmallImageFile(Context cxt, String filePath, int width, int height, boolean isAdjust) {
Bitmap bitmap = reduce(BitmapFactory.decodeFile(filePath), width, height, isAdjust);
File file = new File(getRandomFileName(cxt.getCacheDir().getPath()));
BufferedOutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
outputStream.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
use of android.graphics.Bitmap in project KJFrameForAndroid by kymjs.
the class RoundImageView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
initCurrentBitmap();
if (currentBitmap == null || getWidth() == 0 || getHeight() == 0) {
return;
}
this.measure(0, 0);
int width = getWidth();
int height = getHeight();
// 半径
int radius = 0;
if (mBorderInsideColor != 0 && mBorderOutsideColor != 0) {
// 画两个边框
radius = (width < height ? width : height) / 2 - 2 * mBorderThickness;
// 画内圆
drawCircleBorder(canvas, radius + mBorderThickness / 2, width, height, mBorderInsideColor);
// 画外圆
drawCircleBorder(canvas, radius + mBorderThickness + mBorderThickness / 2, width, height, mBorderOutsideColor);
} else if (mBorderInsideColor != 0 && mBorderOutsideColor == 0) {
// 画一个边框
radius = (width < height ? width : height) / 2 - mBorderThickness;
drawCircleBorder(canvas, radius + mBorderThickness / 2, width, height, mBorderInsideColor);
} else if (mBorderInsideColor == 0 && mBorderOutsideColor != 0) {
// 画一个边框
radius = (width < height ? width : height) / 2 - mBorderThickness;
drawCircleBorder(canvas, radius + mBorderThickness / 2, width, height, mBorderOutsideColor);
} else {
// 没有边框
radius = (width < height ? width : height) / 2;
}
Bitmap roundBitmap = getCroppedRoundBitmap(currentBitmap, radius);
canvas.drawBitmap(roundBitmap, width / 2 - radius, height / 2 - radius, null);
}
use of android.graphics.Bitmap in project KJFrameForAndroid by kymjs.
the class RoundImageView method initCurrentBitmap.
private void initCurrentBitmap() {
Bitmap temp = null;
Drawable drawable = getDrawable();
if (drawable instanceof BitmapDrawable) {
temp = ((BitmapDrawable) drawable).getBitmap();
}
if (temp != null) {
currentBitmap = temp;
}
}
use of android.graphics.Bitmap in project QuickReturn by lawloretienne.
the class RoundedDrawable method drawableToBitmap.
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
Bitmap bitmap;
int width = Math.max(drawable.getIntrinsicWidth(), 1);
int height = Math.max(drawable.getIntrinsicHeight(), 1);
try {
bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
} catch (Exception e) {
e.printStackTrace();
bitmap = null;
}
return bitmap;
}
use of android.graphics.Bitmap in project TwinklingRefreshLayout by lcodecorex.
the class CircleImageView method getBitmapFromDrawable.
private Bitmap getBitmapFromDrawable(Drawable drawable) {
if (drawable == null) {
return null;
}
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap bitmap;
if (drawable instanceof ColorDrawable) {
bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
} else {
if (!(drawable.getIntrinsicWidth() > 0) || !(drawable.getIntrinsicHeight() > 0)) {
bitmap = Bitmap.createBitmap(DensityUtil.dip2px(getContext(), 40), DensityUtil.dip2px(getContext(), 40), BITMAP_CONFIG);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
}
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
} catch (OutOfMemoryError e) {
return null;
}
}
Aggregations