Bitmap

位图的常用方法:
public static Bitmap createBitmap(Bitmap src) ——以src为原图生成不可变得新图像
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth,
int dstHeight, boolean filter)——以src为原图,创建新的图像,指定新图像的高宽以及是否可变
public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)以source为原图,创建新的图片,指定起始坐标以及新图像的高宽。
注意:前三种方法的width不可以 >= source.getWidth();高类同
这些方法也可以称作为图像的切割,按照 x , y, width,height,的角标来切割,当然要切的尺寸就不能大于原图的宽高了。

public static Bitmap createBitmap(int width, int height, Config config)——创建指定格式、大小的位图

另外一种bitmap的静态方法如下:
//改变图片的尺寸

  public static Bitmap changePicSize(Bitmap bitmap, float width, float height) {

        Matrix matrix = new Matrix();
        matrix.postScale(width / bitmap.getWidth(), height / bitmap.getHeight());

       //对bitmap的尺寸横、纵 都扩大指定的倍数,倍数由matrix封装
       //前四个参数决定着新图像由原图像那部分决定,第四个是matrix,第六个是新图像的宽高是否可变。
        Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);

        return bm;

    }

这些是拼图的部分代码:
/**
* 照片碎片加入集合
* @param bitmapList 小位图的集合
* @param itemList item的集合
* @param type x/y方向上切割的份数
*/

 public static Bitmap add2List(Bitmap bitmap, int type, List<Bitmap> bitmapList, List<ItemBean> itemList, Context context) {

        int smallBitmapWidth = bitmap.getWidth() / type;//每个小位图的尺寸
        int smallBitmapHeight = bitmap.getHeight() / type;

        Log.d("ImageUtil","smallBitmapWidth00"+ smallBitmapWidth + "smallBitmapHeight00"+smallBitmapHeight);

        for (int i = 1; i <= type; i++) {
            for (int j = 1; j <= type; j++) {

                Bitmap smallBitmap = Bitmap.createBitmap(bitmap, (i - 1) * smallBitmapWidth, (j - 1) * smallBitmapHeight,
                        smallBitmapWidth, smallBitmapHeight);

                bitmapList.add(smallBitmap);//将bitmap加入集合
                itemList.add(new ItemBean((i - 1) * type + j,
                        (i - 1) * type + j, smallBitmap));//将item对象加入集合

            }

        }
             //得到最后一个小位图
            bitmap = bitmapList.get(type * type - 1);

            bitmapList.remove(type * type - 1);
            itemList.remove(type * type - 1);
            //创建最后一个小位图

            Bitmap lastbitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.lastsmallbit);

           Bitmap changeLast = changePicSize(lastbitmap,smallBitmapWidth,smallBitmapHeight);//对最后一张小位图进行缩放处理

            bitmapList.add(changeLast);

            ItemBean itemBean = new ItemBean(type * type,type * type,changeLast);
            itemList.add(itemBean);

            mBlankItemBean = itemBean;

            Log.d("ImageUtil"," "+ itemBean.getmBitmapId());
        return bitmap;//切割掉的位图

    }

更多方法链接http://www.android100.org/html/201506/30/160242.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值