为图像添加边框,例如 android 中的 google 照片扫描应用程序
Adding border to image like google photo scan app in android
在 android 中是否可以在不向用户显示图像的情况下为图像添加边框。
喜欢google照片扫描应用..Here a border is added to image with photoscan logo
你可以使用这个库
implementation 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
在Xml文件中
<com.github.siyamed.shapeimageview.BubbleImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/neo"
app:siArrowPosition="right"
app:siSquare="true"/>
- 设计了带有图像视图的自定义布局
- 将其膨胀为视图对象
- 在布局中将我的图像设置为该图像视图
- 将视图绘制成位图并保存
充气绘图代码
public Bitmap drawToBitmap(Context context, final int layoutResId,
final int width, final int height, String imageDescription) {
final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bmp);
final LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(layoutResId, null);
ImageView img = layout.findViewById(R.id.imgAnalysedBitmap);
img.setImageBitmap(croppedBitmap);
layout.setDrawingCacheEnabled(true);
layout.measure(
View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY));
layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());
canvas.drawBitmap(layout.getDrawingCache(), 0, 0, new Paint());
return bmp;
}
用法:
final DisplayMetrics metrics = getResources().getDisplayMetrics();
Bitmap bmap = drawToBitmap(this, R.layout.layout_watermark, metrics.widthPixels, metrics.heightPixels, imageDescription);
在 android 中是否可以在不向用户显示图像的情况下为图像添加边框。 喜欢google照片扫描应用..Here a border is added to image with photoscan logo
你可以使用这个库
implementation 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
在Xml文件中
<com.github.siyamed.shapeimageview.BubbleImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/neo"
app:siArrowPosition="right"
app:siSquare="true"/>
- 设计了带有图像视图的自定义布局
- 将其膨胀为视图对象
- 在布局中将我的图像设置为该图像视图
- 将视图绘制成位图并保存
充气绘图代码
public Bitmap drawToBitmap(Context context, final int layoutResId,
final int width, final int height, String imageDescription) {
final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bmp);
final LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout = inflater.inflate(layoutResId, null);
ImageView img = layout.findViewById(R.id.imgAnalysedBitmap);
img.setImageBitmap(croppedBitmap);
layout.setDrawingCacheEnabled(true);
layout.measure(
View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY));
layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());
canvas.drawBitmap(layout.getDrawingCache(), 0, 0, new Paint());
return bmp;
}
用法:
final DisplayMetrics metrics = getResources().getDisplayMetrics();
Bitmap bmap = drawToBitmap(this, R.layout.layout_watermark, metrics.widthPixels, metrics.heightPixels, imageDescription);