Android:用白色填充位图 [英] Android: padding left a bitmap with white color

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

问题描述

如何将位图左侧的 10 行设置为全白?我有一个必须在左侧填充的位图.我以为我可以创建一个新图像,在旧的每个位置上迭代 getpixel 并在新位置(白色或彩色)上设置像素,然后返回新位图……这是错误的吗?有什么建议吗?非常感谢!

How to set all white the 10 rows on the left side of a Bitmap? I'v got a Bitmap that has to be padded on the left side. I thought i can create a new image iterate on the old one getpixel for each position and setpixel on the new one (white or colored) than return the new bitmap...is this wrong? Any suggestion? thanks a lot!

推荐答案

您可以改为创建具有额外填充像素数的新位图.将此设置为画布位图并使用所需颜色为整个图像着色,然后复制您的位图.

You can instead create a new Bitmap with the extra padding number of pixels. Set this as the canvas bitmap and Color the entire image with the required color and then copy your bitmap.

public Bitmap pad(Bitmap Src, int padding_x, int padding_y) {
    Bitmap outputimage = Bitmap.createBitmap(Src.getWidth() + padding_x,Src.getHeight() + padding_y, Bitmap.Config.ARGB_8888);
    Canvas can = new Canvas(outputimage);
    can.drawARGB(FF,FF,FF,FF); //This represents White color
    can.drawBitmap(Src, padding_x, padding_y, null);
    return outputimage;
}

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

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