我无法获得位图内容周围的边界,我如何获得内容边界,下面的代码只能给我图像周围的边界,而不是内容。
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(10); // set stroke width
mPaint.setColor(getResources().getColor(R.color.black)); // set stroke color
mPaint.setAntiAlias(true);
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icons8_bus_36_2);
tempBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas tempCanvas = new Canvas(tempBitmap);
Rect rect = new Rect(
10 / 2,
10 / 2,
tempCanvas.getWidth() - 10 / 2,
tempCanvas.getHeight() - 10 / 2);
tempCanvas.drawRect(rect,mPaint);
tempCanvas.drawBitmap(bitmap, 0, 0, mPaint);
答案 0 :(得分:0)
在这部分上:
redirectSub: Subscription;
constructor(
private store: Store<fromRoot.State>,
private router: Router,
private actionsSubject: ActionsSubject
) { }
ngOnInit() {
this.redirectSub = this.actionsSubject.asObservable().pipe(
ofType(ContactsActionTypes.CREATE_SUCCESS)
).subscribe(
(action: CreateSuccess) => this.router.navigate(['/contacts', action.payload.id])
);
}
ngOnDestroy() {
this.redirectSub.unsubscribe();
}
submitted(subspecialisatie: SubSpecialisatie) {
this.store.dispatch(new Create(subspecialisatie));
}
@Effect()
create$: Observable<Action> = this.actions$.pipe(
ofType(SubSpecialisatiesActionTypes.CREATE),
map((action: Create) => action.payload),
switchMap((subspecialisatie) => this.subspecialisatieService.createSubSpecialisatie(subspecialisatie)),
map((createdSubSpecialisatie: SubSpecialisatie) => new CreateSuccess(createdSubSpecialisatie))
);
更改为
Rect rect = new Rect(
10 / 2,
10 / 2,
tempCanvas.getWidth() - 10 / 2,
tempCanvas.getHeight() - 10 / 2);
那是因为10先除以两个
另外,在绘制矩形之前先绘制位图
OR
您可以这样绘制:
Rect rect = new Rect(
10 / 2,
10 / 2,
(tempCanvas.getWidth() - 10) / 2,
(tempCanvas.getHeight() - 10) / 2);