// 保存图片 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); }
private void initEvent() { stickerBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (!setCurrentBtn(stickerBtn)) { return; } bottomToolBar.setVisibility(View.VISIBLE); labelSelector.hide(); emptyLabelView.setVisibility(View.GONE); commonLabelArea.setVisibility(View.GONE); initStickerToolBar(); } }); filterBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (!setCurrentBtn(filterBtn)) { return; } bottomToolBar.setVisibility(View.VISIBLE); labelSelector.hide(); emptyLabelView.setVisibility(View.INVISIBLE); commonLabelArea.setVisibility(View.GONE); initFilterToolBar(); } }); labelBtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (!setCurrentBtn(labelBtn)) { return; } bottomToolBar.setVisibility(View.GONE); labelSelector.showToTop(); commonLabelArea.setVisibility(View.VISIBLE); } }); labelSelector.setTxtClicked( new OnClickListener() { @Override public void onClick(View v) { EditTextActivity.openTextEdit( PhotoProcessActivity.this, "", 8, AppConstants.ACTION_EDIT_LABEL); } }); labelSelector.setAddrClicked( new OnClickListener() { @Override public void onClick(View v) { EditTextActivity.openTextEdit( PhotoProcessActivity.this, "", 8, AppConstants.ACTION_EDIT_LABEL_POI); } }); mImageView.setOnDrawableEventListener(wpEditListener); mImageView.setSingleTapListener( new OnImageViewTouchSingleTapListener() { @Override public void onSingleTapConfirmed() { emptyLabelView.updateLocation( (int) mImageView.getmLastMotionScrollX(), (int) mImageView.getmLastMotionScrollY()); emptyLabelView.setVisibility(View.VISIBLE); labelSelector.showToTop(); drawArea.postInvalidate(); } }); labelSelector.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { labelSelector.hide(); emptyLabelView.updateLocation( (int) labelSelector.getmLastTouchX(), (int) labelSelector.getmLastTouchY()); emptyLabelView.setVisibility(View.VISIBLE); } }); titleBar.setRightBtnOnclickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub savePicture(); } }); }