Skip to content

Commit

Permalink
1.更新 DevEngine 部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
afkT committed Sep 2, 2021
1 parent 8290c37 commit 6b1edbb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class BarCodeData
private int mBackgroundColor = Color.WHITE;
// 条码嵌入 icon、logo
private Bitmap mIcon;
// icon 占比
private float mIconScale = 4.0F;

private BarCodeData(
String content,
Expand Down Expand Up @@ -185,4 +187,22 @@ public BarCodeData setIcon(Bitmap icon) {
this.mIcon = icon;
return this;
}

/**
* 获取 icon 占比
* @return icon 占比
*/
public float getIconScale() {
return mIconScale;
}

/**
* 设置 icon 占比
* @param iconScale icon 占比
* @return BarCode Item
*/
public BarCodeData setIconScale(float iconScale) {
this.mIconScale = iconScale;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,51 @@ public BarCodeResult decodeBarCodeSync(Bitmap bitmap)
// = 其他功能 =
// ==========

/**
* 添加 Icon 到条码图片上
* <pre>
* 目前就处理了 二维码图片 其他需要根据需求自行添加
* </pre>
* @param params BarCode ( Data、Params ) Item
* @param src 条码图片
* @param icon icon
* @return 含 icon 条码图片
*/
@Override
public Bitmap addIconToBarCode(
BarCodeData params,
Bitmap src,
Bitmap icon
)
throws Exception {
if (params == null) {
throw new Exception("BarCode ( Data、Params ) Item is null");
}
if (params.getFormat() == null) {
throw new Exception("BarCode format is null");
}
if (params.getIconScale() <= 0) {
throw new Exception("BarCode iconScale Less than or equal to 0");
}
if (src == null) {
throw new Exception("addIconToBarCode src Bitmap is null");
}
if (icon == null) {
throw new Exception("addIconToBarCode icon Bitmap is null");
}
// 获取图片宽度高度
int srcWidth = src.getWidth();
int srcHeight = src.getHeight();
int iconWidth = icon.getWidth();
int iconHeight = icon.getHeight();
float srcWidth = src.getWidth();
float srcHeight = src.getHeight();
float iconWidth = icon.getWidth();
float iconHeight = icon.getHeight();

// 这里的 4 决定 icon 在图片的比例 四分之一 ( 可自行判断 BarCodeData Format 决定绘制大小比例 )
float scaleFactor = srcWidth * 1.0f / 4 / iconWidth;
Bitmap bitmap = Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
// 这里决定 icon 在图片的比例 ( 可自行判断 BarCodeData Format 决定绘制大小比例 )
float scaleFactor = srcWidth / params.getIconScale() / iconWidth;
Bitmap bitmap = Bitmap.createBitmap(
(int) srcWidth, (int) srcHeight,
Bitmap.Config.ARGB_8888
);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(src, 0, 0, null);
canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);
canvas.drawBitmap(
Expand Down

0 comments on commit 6b1edbb

Please sign in to comment.