从画布清除油漆而不清除背景图像 – Android

从画布清除油漆而不清除背景图像 – Android,第1张

概述我有一个带背景图片的画布.我需要知道是否可以清除此画布上的油漆以进行重绘而不清除其背景图像.这是我的例子,到目前为止我的结果. JAVA public void setCanvas() { if(mFile != null && mFile.exists()) { mPictureBitmap = BitmapFactory.decodeFile(mFile.getAbso 我有一个带背景图片的画布.我需要知道是否可以清除此画布上的油漆以进行重绘而不清除其背景图像.这是我的例子,到目前为止我的结果.

JAVA

public voID setCanvas() {    if(mfile != null && mfile.exists()) {        mPictureBitmap = BitmapFactory.decodefile(mfile.getabsolutePath());        mBitmap = Bitmap.createScaledBitmap(mPictureBitmap,mImageVIEw.getWIDth(),mImageVIEw.getHeight(),false);        mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888,true);        mCanvas = new Canvas(mBitmap);        mImageVIEw.setimageBitmap(mBitmap);        mImageVIEw.setontouchListener(this);    }}private voID draw() {    mCanvas.drawcolor(color.transparent,Mode.CLEAR); // THIS liNE CLEARS    int lastIndex = mCordHashMap.size() - 1;    int index = 0;    for (linkedHashMap.Entry<String,ArrayList<Circle>> entry : mCordHashMap.entrySet()) {        ArrayList<Circle> coords = new ArrayList<Circle>();        coords = entry.getValue();        Path path = new Path();        String key = entry.getKey();        String surface = getSurfaceFromKey(key);        changePaint(surface);        if (coords.size() < 3) {            for (Circle c : coords) {                mCanvas.drawCircle(c.getmX(),c.getmY(),RADIUS,mCirclePaint);            }        } else {            for (Circle c : coords) {                if (c == coords.get(0)) {                    path.moveto(c.getmX(),c.getmY());                } else {                    path.lineto(c.getmX(),c.getmY());                }            }            path.close();            mCanvas.drawPath(path,mPaint);            mCanvas.drawPath(path,mstrokePaint);        }        if (index == lastIndex && !mSpecificPathSelected) {            for (Circle c : coords) {                mCanvas.drawCircle(c.getmX(),mCirclePaint);                mCanvas.drawCircle(c.getmX(),mCirclestrokePaint);            }        }        mImageVIEw.invalIDate();        index++;    }}

XML

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="horizontal" >    <ExpandableListVIEw        androID:ID="@+ID/surfaceList"        androID:background="@color/light_grey"        androID:layout_wIDth="0dp"        androID:layout_height="match_parent"        androID:layout_weight=".20" />    <ImageVIEw        androID:ID="@+ID/drawContainer"        androID:layout_wIDth="0dp"        androID:layout_height="match_parent"        androID:layout_weight=".80"         androID:contentDescription="@string/app_name"/></linearLayout>

所以上面的代码将图像加载到我的Canvas中.然后每当我触摸画布时,它会绘制一个圆圈,最终形成圆圈之间的路径.但是,当我开始添加更多的圆圈和路径时,它会重新绘制自己,这看起来很糟糕.

现在我可以用这条线清除我画布上的油漆.

mCanvas.drawcolor(color.transparent,Mode.CLEAR);

但是我也丢失了我设置的Bitmap作为它的背景,现在我的背景是黑色的.那么,我如何保留我的背景图像,但清除我的油漆?这是可能的还是我必须使用两个Canvas之类的工作?

我已经尝试过以下几种变体.

1) mCanvas.drawcolor(color.transparent,Mode.CLEAR);2) mCanvas.drawcolor(color.transparent,Mode.CLEAR);   mCanvas.drawBitmap(mBitmap,mPaint);3) mBitmap.erasecolor(color.transparent);   mCanvas.drawBitmap(mBitmap,mPaint);

任何帮助表示赞赏

解决方法 据我所知,Canvas不包含图层.所以你不能删除一层(油漆)而留下另一层(背景).我相信你应该使用两个画布,甚至是画布和ImageVIEw来保存背景.然后,当您要导出图像时,将画布内容与背景组合. 总结

以上是内存溢出为你收集整理的从画布清除油漆而不清除背景图像 – Android全部内容,希望文章能够帮你解决从画布清除油漆而不清除背景图像 – Android所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1130069.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存