java类android.graphics.Bitmap.Config的实例源码

ImageLoaderUtil.java 文件源码 项目:APIJSON-Android-RxJava 阅读 36 收藏 0 点赞 0 评论 0
/**将图片改为圆角类型
 * @param bitmap
 * @param pixels
 * @return
 */
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    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());
    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;
}
ResUtil.java 文件源码 项目:boohee_v5.6 阅读 40 收藏 0 点赞 0 评论 0
private static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    try {
        Bitmap createBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
                Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        Paint paint = new Paint();
        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        RectF rectF = new RectF(rect);
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(-12434878);
        canvas.drawRoundRect(rectF, (float) (bitmap.getWidth() / 6), (float) (bitmap
                .getHeight() / 6), paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        bitmap.recycle();
        return createBitmap;
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "Cant`t create round corner bitmap. [OutOfMemoryError] ");
        return null;
    }
}
NativeUtil.java 文件源码 项目:Android-BitherCompress-master 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 4.尺寸压缩(通过缩放图片像素来减少图片占用内存大小)
 *
 * @param bmp
 * @param file
 */

public static void sizeCompress(Bitmap bmp, File file) {
    // 尺寸压缩倍数,值越大,图片尺寸越小
    int ratio = 8;
    // 压缩Bitmap到对应尺寸
    Bitmap result = Bitmap.createBitmap(bmp.getWidth() / ratio, bmp.getHeight() / ratio, Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Rect rect = new Rect(0, 0, bmp.getWidth() / ratio, bmp.getHeight() / ratio);
    canvas.drawBitmap(bmp, null, rect, null);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // 把压缩后的数据存放到baos中
    result.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baos.toByteArray());
        fos.flush();
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
BitmapUtil.java 文件源码 项目:AppCommonFrame 阅读 35 收藏 0 点赞 0 评论 0
/**
 * 根据自定义的弧度生成一张圆角图片 . <br>
 * @author liulongzhenhai 2012-7-12 上午9:06:01 <br>
 * @param bitmap 图片
 * @param pixels 圆角
 * @return 图片
 */
public static Bitmap toRoundCorner(final Bitmap bitmap, final int pixels) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    final 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());
    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(android.graphics.PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
AlphaPatternDrawable.java 文件源码 项目:SubwayTooter 阅读 29 收藏 0 点赞 0 评论 0
/**
 * This will generate a bitmap with the pattern as big as the rectangle we were allow to draw on.
 * We do this to chache the bitmap so we don't need to recreate it each time draw() is called since it takes a few milliseconds
 */
private void generatePatternBitmap() {
  if (getBounds().width() <= 0 || getBounds().height() <= 0) {
    return;
  }

  bitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);

  Rect r = new Rect();
  boolean verticalStartWhite = true;
  for (int i = 0; i <= numRectanglesVertical; i++) {
    boolean isWhite = verticalStartWhite;
    for (int j = 0; j <= numRectanglesHorizontal; j++) {
      r.top = i * rectangleSize;
      r.left = j * rectangleSize;
      r.bottom = r.top + rectangleSize;
      r.right = r.left + rectangleSize;
      canvas.drawRect(r, isWhite ? paintWhite : paintGray);
      isWhite = !isWhite;
    }
    verticalStartWhite = !verticalStartWhite;
  }
}
TeXFormula.java 文件源码 项目:FlexibleRichTextView 阅读 41 收藏 0 点赞 0 评论 0
/**
 * @param formula
 *            the formula
 * @param style
 *            the style
 * @param size
 *            the size
 * @param transparency
 *            , if true the background is transparent
 * @return the generated image
 */
public static Bitmap createBufferedImage(String formula, int style,
        float size, Integer fg, Integer bg) throws ParseException {
    TeXFormula f = new TeXFormula(formula);
    TeXIcon icon = f.createTeXIcon(style, size);
    icon.setInsets(new Insets(2, 2, 2, 2));
    int w = icon.getIconWidth(), h = icon.getIconHeight();

    Bitmap image = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas g2 = new Canvas(image);
    if (bg != null) {
        Paint st = new Paint();
        st.setStyle(Style.FILL_AND_STROKE);
        st.setColor(bg);
        g2.drawRect(0, 0, w, h, st);
    }

    icon.setForeground(fg == null ? Color.BLACK : fg);
    icon.paintIcon(g2, 0, 0);

    return image;
}
TeXFormula.java 文件源码 项目:FlexibleRichTextView 阅读 35 收藏 0 点赞 0 评论 0
/**
 * @param formula
 *            the formula
 * @param style
 *            the style
 * @param size
 *            the size
 * @param transparency
 *            , if true the background is transparent
 * @return the generated image
 */
public Bitmap createBufferedImage(int style, float size, Integer fg,
        Integer bg) throws ParseException {
    TeXIcon icon = createTeXIcon(style, size);
    icon.setInsets(new Insets(2, 2, 2, 2));
    int w = icon.getIconWidth(), h = icon.getIconHeight();

    Bitmap image = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas g2 = new Canvas(image);
    if (bg != null) {
        Paint st = new Paint();
        st.setStyle(Style.FILL_AND_STROKE);
        st.setColor(bg);
        g2.drawRect(0, 0, w, h, st);
    }

    icon.setForeground(fg == null ? Color.BLACK : fg);
    icon.paintIcon(g2, 0, 0);

    return image;
}
RoundedDrawable.java 文件源码 项目:boohee_v5.6 阅读 55 收藏 0 点赞 0 评论 0
public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }
    try {
        Bitmap bitmap = Bitmap.createBitmap(Math.max(drawable.getIntrinsicWidth(), 2), Math
                .max(drawable.getIntrinsicHeight(), 2), Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    } catch (Exception e) {
        e.printStackTrace();
        Log.w(TAG, "Failed to create bitmap from drawable!");
        return null;
    }
}
e.java 文件源码 项目:boohee_v5.6 阅读 43 收藏 0 点赞 0 评论 0
public static Bitmap c(String str) {
    int i = 1;
    Options options = new Options();
    options.inJustDecodeBounds = true;
    options.inDither = false;
    options.inPurgeable = true;
    options.inInputShareable = true;
    options.inPreferredConfig = Config.RGB_565;
    BitmapFactory.decodeFile(str, options);
    if (options.outHeight > 200 || options.outWidth > 200) {
        i = Math.min(Math.round(((float) options.outHeight) / 200.0f), Math.round(((float)
                options.outWidth) / 200.0f));
    }
    options.inJustDecodeBounds = false;
    options.inSampleSize = i;
    return BitmapFactory.decodeFile(str, options).copy(Config.ARGB_8888, false);
}
ImageLoader.java 文件源码 项目:GitHub 阅读 31 收藏 0 点赞 0 评论 0
protected Request<Bitmap> makeImageRequest(String requestUrl, int maxWidth, int maxHeight,
        ScaleType scaleType, final String cacheKey) {
    return new ImageRequest(requestUrl, new Listener<Bitmap>() {
        @Override
        public void onResponse(Bitmap response) {
            onGetImageSuccess(cacheKey, response);
        }
    }, maxWidth, maxHeight, scaleType, Config.RGB_565, new ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            onGetImageError(cacheKey, error);
        }
    });
}


问题


面经


文章

微信
公众号

扫码关注公众号