use of com.customview.MyHighlightView in project StickerCamera by Skykai521.
the class EffectUtil method addStickerImage.
//添加贴纸
public static MyHighlightView addStickerImage(final ImageViewTouch processImage, Context context, final Addon sticker, final StickerCallback callback) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), sticker.getId());
if (bitmap == null) {
return null;
}
StickerDrawable drawable = new StickerDrawable(context.getResources(), bitmap);
drawable.setAntiAlias(true);
drawable.setMinSize(30, 30);
final MyHighlightView hv = new MyHighlightView(processImage, R.style.AppTheme, drawable);
//设置贴纸padding
hv.setPadding(10);
hv.setOnDeleteClickListener(new MyHighlightView.OnDeleteClickListener() {
@Override
public void onDeleteClick() {
((MyImageViewDrawableOverlay) processImage).removeHightlightView(hv);
hightlistViews.remove(hv);
((MyImageViewDrawableOverlay) processImage).invalidate();
callback.onRemoveSticker(sticker);
}
});
Matrix mImageMatrix = processImage.getImageViewMatrix();
int cropWidth, cropHeight;
int x, y;
final int width = processImage.getWidth();
final int height = processImage.getHeight();
// width/height of the sticker
cropWidth = (int) drawable.getCurrentWidth();
cropHeight = (int) drawable.getCurrentHeight();
final int cropSize = Math.max(cropWidth, cropHeight);
final int screenSize = Math.min(processImage.getWidth(), processImage.getHeight());
RectF positionRect = null;
if (cropSize > screenSize) {
float ratio;
float widthRatio = (float) processImage.getWidth() / cropWidth;
float heightRatio = (float) processImage.getHeight() / cropHeight;
if (widthRatio < heightRatio) {
ratio = widthRatio;
} else {
ratio = heightRatio;
}
cropWidth = (int) ((float) cropWidth * (ratio / 2));
cropHeight = (int) ((float) cropHeight * (ratio / 2));
int w = processImage.getWidth();
int h = processImage.getHeight();
positionRect = new RectF(w / 2 - cropWidth / 2, h / 2 - cropHeight / 2, w / 2 + cropWidth / 2, h / 2 + cropHeight / 2);
positionRect.inset((positionRect.width() - cropWidth) / 2, (positionRect.height() - cropHeight) / 2);
}
if (positionRect != null) {
x = (int) positionRect.left;
y = (int) positionRect.top;
} else {
x = (width - cropWidth) / 2;
y = (height - cropHeight) / 2;
}
Matrix matrix = new Matrix(mImageMatrix);
matrix.invert(matrix);
float[] pts = new float[] { x, y, x + cropWidth, y + cropHeight };
MatrixUtils.mapPoints(matrix, pts);
RectF cropRect = new RectF(pts[0], pts[1], pts[2], pts[3]);
Rect imageRect = new Rect(0, 0, width, height);
hv.setup(context, mImageMatrix, imageRect, cropRect, false);
((MyImageViewDrawableOverlay) processImage).addHighlightView(hv);
((MyImageViewDrawableOverlay) processImage).setSelectedHighlightView(hv);
hightlistViews.add(hv);
return hv;
}
Aggregations