@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_process); ButterKnife.inject(this); EffectUtil.clear(); initView(); initEvent(); initStickerToolBar(); ImageUtils.asyncLoadImage( this, getIntent().getData(), new ImageUtils.LoadImageCallback() { @Override public void callback(Bitmap result) { currentBitmap = result; mGPUImageView.setImage(currentBitmap); } }); ImageUtils.asyncLoadSmallImage( this, getIntent().getData(), new ImageUtils.LoadImageCallback() { @Override public void callback(Bitmap result) { smallImageBackgroud = result; } }); }
// 保存图片 private void savePicture() { // 加滤镜 final Bitmap newBitmap = Bitmap.createBitmap(mImageView.getWidth(), mImageView.getHeight(), Bitmap.Config.ARGB_8888); Canvas cv = new Canvas(newBitmap); RectF dst = new RectF(0, 0, mImageView.getWidth(), mImageView.getHeight()); try { cv.drawBitmap(mGPUImageView.capture(), null, dst, null); } catch (InterruptedException e) { e.printStackTrace(); cv.drawBitmap(currentBitmap, null, dst, null); } // 加贴纸水印 EffectUtil.applyOnSave(cv, mImageView); new SavePicToFileTask().execute(newBitmap); }
// 添加标签 private void addLabel(TagItem tagItem) { labelSelector.hide(); emptyLabelView.setVisibility(View.INVISIBLE); if (labels.size() >= 5) { alert("温馨提示", "您只能添加5个标签!", "确定", null, null, null, true); } else { int left = emptyLabelView.getLeft(); int top = emptyLabelView.getTop(); if (labels.size() == 0 && left == 0 && top == 0) { left = mImageView.getWidth() / 2 - 10; top = mImageView.getWidth() / 2; } LabelView label = new LabelView(PhotoProcessActivity.this); label.init(tagItem); EffectUtil.addLabelEditable(mImageView, drawArea, label, left, top); labels.add(label); } }
private void initView() { // 添加贴纸水印的画布 View overlay = LayoutInflater.from(PhotoProcessActivity.this) .inflate(R.layout.view_drawable_overlay, null); mImageView = (MyImageViewDrawableOverlay) overlay.findViewById(R.id.drawable_overlay); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(App.getApp().getScreenWidth(), App.getApp().getScreenWidth()); mImageView.setLayoutParams(params); overlay.setLayoutParams(params); drawArea.addView(overlay); // 添加标签选择器 RelativeLayout.LayoutParams rparams = new RelativeLayout.LayoutParams( App.getApp().getScreenWidth(), App.getApp().getScreenWidth()); labelSelector = new LabelSelector(this); labelSelector.setLayoutParams(rparams); drawArea.addView(labelSelector); labelSelector.hide(); // 初始化滤镜图片 mGPUImageView.setLayoutParams(rparams); // 初始化空白标签 emptyLabelView = new LabelView(this); emptyLabelView.setEmpty(); EffectUtil.addLabelEditable( mImageView, drawArea, emptyLabelView, mImageView.getWidth() / 2, mImageView.getWidth() / 2); emptyLabelView.setVisibility(View.INVISIBLE); // 初始化推荐标签栏 commonLabelArea = LayoutInflater.from(PhotoProcessActivity.this).inflate(R.layout.view_label_bottom, null); commonLabelArea.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); toolArea.addView(commonLabelArea); commonLabelArea.setVisibility(View.GONE); }