由网友(敢毁她清白就敢给她未来)分享简介:我有,我想使用一个覆盖PNG文件 - 但是,这个文件必须镜像(并旋转180°),但为了节省空间,我不想把镜像文件在APK,但编程做这个动作。I have a PNG file that I want to use for an overlay - however, this file has to be mirror...
我有,我想使用一个覆盖PNG文件 - 但是,这个文件必须镜像(并旋转180°),但为了节省空间,我不想把镜像文件在APK,但编程做这个动作。
I have a PNG file that I want to use for an overlay - however, this file has to be mirrored (and rotated by 180°), but in order to save space, I don't want to place the mirrored file in the apk, but do this action programmatically.
我怎样才能做到这一点与升级Froyo或以上?
How can I do this with Froyo and above?
推荐答案
缩放由-1.0导致图像翻转。假设 BMP
是要镜像(这里的X轴),你可以做的位图:
Scaling by -1.0 causes the image to be flipped. Assuming bmp
is the bitmap you want to mirror (here on the x axis) you can do :
Matrix matrix = new Matrix();
matrix.preScale(-1.0f, 1.0f);
Bitmap mirroredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.width(), bmp.height(), matrix, false);
如果您不希望创建第二个位图,你可以用 canvas.scale
做同样的:
If you don't want to create a second bitmap, you can do the same with canvas.scale
:
canvas.save();
canvas.scale(-1.0f, 1.0f);
canvas.drawBitmap(bitmap, ...); // The bitmap is flipped
canvas.restore();
相关推荐
最新文章