带边框的Android位图 [英] Android bitmap with border

查看:69
本文介绍了带边框的Android位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能,有了这个功能,我可以稍微旋转一下就可以显示图像.我正在尝试在位图周围显示白色边框.

I have this function, with this function I can show an image with a little rotation. I'm trying to display a white border arround the bitmap.

Matrix m = new Matrix();
        m.postRotate( rotation, center.x, center.y );
        m.postTranslate( ( position.x - center.x ) - xOffset , position.y - ( center.x ) );

        //  set the current position to the updated position
        positionMatrix.set( m );            
        renderAnimation();          
        c.drawBitmap( this.bitmap , positionMatrix, paint );

我正在尝试使用此功能添加白色边框:参考:stackoverflow边框

I'm trying to add the white border with this function: reference: stackoverflow border

    RectF targetRect = new RectF(left+10, top+10, left + scaledWidth, top + scaledHeight);
    Bitmap dest = Bitmap.createBitmap(this.bitmap.getWith() +20, this.bitmap.getHeight() +20, this.bitmap.getConfig());
    Canvas canvas = new Canvas(dest);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(this.bitmap, null, targetRect, null);
c.drawBitmap( this.bitmap , positionMatrix, paint );

但是,这行不通,可以帮助我

But, not works, can some help me

推荐答案

我认为您应该按照以下步骤操作:

I think you should follow these steps:

  1. 创建一个位图,其宽度= yourImageWidth + boderThick和height = yourImageHeight + boderThick
  2. 画布绘制白色矩形(先绘制背景)
  3. 画布绘制图像(您需要将图像居中)

在计算侧面时您可能犯了一个错误,或者绘制顺序错误.绘图时请记住使用相同的画布.在您的代码中,我看到您使用c.draw和canvas.draw ...这可能会导致问题.

Maybe you made a mistake when calculating the side, or draw in a wrong order. Remember to use the same canvas when drawing. In your code i see you use c.draw and canvas.draw... That may cause the problem.

请参阅以下代码:

 Paint paint = new Paint();
 paint.setColor(Color.WHITE);
 paint.setStrokeWidth(3);
 canvas.drawRect(0, 0, 200, 200, paint);//draw your bg
 canvas.drawBitmap(bitmap, 20, 20, paint);//draw your image on bg

对不起,我没有太多时间来检查您计算出的尺寸.希望对您有所帮助.

Sorry, i don't have much time to check your calculated size. I hope this can help.

这篇关于带边框的Android位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆