栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android-在Canvas中绘制位图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android-在Canvas中绘制位图

使用

Canvas
方法
public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paintpaint)
。设置
dst
为要缩放整个图像的矩形的大小。

编辑:

这是在画布上以正方形绘制位图的可能实现。假设位图是二维数组(例如

BitmapbitmapArray[][];
),并且画布是正方形的,因此正方形位图的宽高比不会失真。

private static final int NUMBER_OF_VERTICAL_SQUARES = 5;private static final int NUMBER_OF_HORIZONTAL_SQUARES = 5;

    int canvasWidth = canvas.getWidth();    int canvasHeight = canvas.getHeight();    int squareWidth = canvasWidth / NUMBER_OF_HORIZONTAL_SQUARES;    int squareHeight = canvasHeight / NUMBER_OF_VERTICAL_SQUARES;    Rect destinationRect = new Rect();    int xOffset;    int yOffset;    // Set the destination rectangle size    destinationRect.set(0, 0, squareWidth, squareHeight);    for (int horizontalPosition = 0; horizontalPosition < NUMBER_OF_HORIZONTAL_SQUARES; horizontalPosition++){        xOffset = horizontalPosition * squareWidth;        for (int verticalPosition = 0; verticalPosition < NUMBER_OF_VERTICAL_SQUARES; verticalPosition++){ yOffset = verticalPosition * squareHeight; // Set the destination rectangle offset for the canvas origin destinationRect.offsetTo(xOffset, yOffset); // Draw the bitmap into the destination rectangle on the canvas canvas.drawBitmap(bitmapArray[horizontalPosition][verticalPosition], null, destinationRect, null);        }    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/438005.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号