Android:padding留白色的位图 [英] Android: padding left a bitmap with white color

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

问题描述

如何设置所有白色的位图左侧的10行?
我有一个位图,必须在左侧填充。我想我可以创建一个新的图像迭代旧的一个getpixel为每个位置和setpixel新的(白色或彩色)比返回新的位图...这是错误吗?
任何建议?非常感谢!

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!

推荐答案

您可以使用额外的填充像素数创建一个新的位图。
将此设置为画布位图,并使用所需颜色对整个图像进行Color,然后复制位图。

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:padding留白色的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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