国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android開發(fā)之圖片切割工具類定義與用法示例

2019-10-22 18:24:00
字體:
供稿:網(wǎng)友

本文實(shí)例講述了Android開發(fā)之圖片切割工具類定義與用法。分享給大家供大家參考,具體如下:

該工具類比較常見于拼圖游戲中使用。這里演示了類基本的定義與使用方法。

圖片切割工具類定義:

public class ImageSplitter{  /**   * 將圖片切成 , piece *piece   *   * @param bitmap   * @param piece   * @return   */  public static List<ImagePiece> split(Bitmap bitmap, int piece)  {    List<ImagePiece> pieces = new ArrayList<ImagePiece>(piece * piece);    int width = bitmap.getWidth();    int height = bitmap.getHeight();    Log.e("TAG", "bitmap Width = " + width + " , height = " + height);    int pieceWidth = Math.min(width, height) / piece;    for (int i = 0; i < piece; i++)    {      for (int j = 0; j < piece; j++)      {        ImagePiece imagePiece = new ImagePiece();        imagePiece.index = j + i * piece;        int xValue = j * pieceWidth;        int yValue = i * pieceWidth;        imagePiece.bitmap = Bitmap.createBitmap(bitmap, xValue, yValue,            pieceWidth, pieceWidth);        pieces.add(imagePiece);      }    }    return pieces;  }}

圖片切割實(shí)體類:

public class ImagePiece{  public int index = 0;  public Bitmap bitmap = null;}

使用方法:

private void initBitmap(){    if (mBitmap == null)      mBitmap = BitmapFactory.decodeResource(getResources(),          R.drawable.aa);    List<ImagePiece> mItemBitmaps = ImageSplitter.split(mBitmap, mColumn);    Collections.sort(mItemBitmaps, new Comparator<ImagePiece>()    {      @Override      public int compare(ImagePiece lhs, ImagePiece rhs)      {        return Math.random() > 0.5 ? 1 : -1;      }    });}

希望本文所述對大家Android程序設(shè)計(jì)有所幫助。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永清县| 天台县| 崇左市| 屏东市| 永定县| 巴南区| 横峰县| 平昌县| 黎城县| 锦屏县| 商城县| 正阳县| 甘洛县| 南江县| 琼海市| 无为县| 长宁区| 永康市| 海口市| 西丰县| 海林市| 东宁县| 贵溪市| 德惠市| 乐昌市| 西乡县| 潞城市| 吉安市| 闸北区| 阳原县| 井陉县| 延庆县| 陵水| 荥经县| 辰溪县| 肥东县| 分宜县| 江安县| 叶城县| 恭城| 乐亭县|