Android使用RotateImageView 旋转ImageView
程序员文章站
2023-12-19 12:20:28
废话不多说了,直接给大家代码。
具体代码如下所示:
package com.droidhen.game.layout;
import android.cont...
废话不多说了,直接给大家代码。
具体代码如下所示:
package com.droidhen.game.layout; import android.content.context; import android.graphics.bitmap; import android.graphics.bitmap.config; import android.graphics.canvas; import android.graphics.paint; import android.graphics.paintflagsdrawfilter; import android.graphics.rect; import android.widget.imageview; public class rotateimageview extends imageview { /**旋转角度**/ private float _degree; /**旋转中心**/ private float _x; private float _y; /** 背景和前景资源 */ private bitmap _bgres, _fgres; /** 数字图片资源 */ private bitmap _nums; private bitmap _buffer; private canvas _canvas; private int start = ; private int unitx = ; public rotateimageview(context context) { super(context); _degree = f; _x = ; _y = ; _nums = bitmapfactory.decoderesource(getresources(), r.drawable.level_num); } public void setresids(int bgresid, int fgresid) { _bgres = bitmapfactory.decoderesource(getresources(), bgresid); _fgres = bitmapfactory.decoderesource(getresources(), fgresid); } public void setlevel(int level) { string _level = string.valueof(level); _buffer = bitmap.createbitmap( _level.length()*(_nums.getwidth()/), _nums.getheight(), config.argb_); unitx = _nums.getwidth()/; _canvas = new canvas(_buffer); for(int i = ; i <= _level.length()-; i++){ rect src = new rect((_level.charat(i) - '')*unitx, , (_level.charat(i) - '' + )*unitx, _nums.getheight()); rect dst = new rect( i*unitx, , (i + )*unitx, _nums.getheight()); _canvas.drawbitmap(_nums, src, dst, null); } } public void setlevel(int level, int resid) { _nums = bitmapfactory.decoderesource(getresources(), resid); string _level = string.valueof(level); _buffer = bitmap.createbitmap( _level.length()*(_nums.getwidth()/), _nums.getheight(), config.argb_); unitx = _nums.getwidth()/; _canvas = new canvas(_buffer); for(int i = ; i <= _level.length()-; i++){ rect src = new rect((_level.charat(i) - '')*unitx, , (_level.charat(i) - '' + )*unitx, _nums.getheight()); rect dst = new rect( i*unitx, , (i + )*unitx, _nums.getheight()); _canvas.drawbitmap(_nums, src, dst, null); } } public void setdegree(float degree) { _degree = degree; } public void setdegree(float degree, float x, float y) { _degree = degree; _x = x; _y = y; } public float getdegree() { return _degree; } public float getrotatex() { return _x; } public float getrotatey() { return _y; } @override public void draw(canvas canvas) { canvas.save(); canvas.setdrawfilter(new paintflagsdrawfilter(, paint.anti_alias_flag|paint.filter_bitmap_flag)); canvas.rotate(_degree, _x, _y); canvas.drawbitmap(_bgres, , , null); canvas.drawbitmap(_fgres, , , null); canvas.drawbitmap(_buffer, (_bgres.getwidth() - _buffer.getwidth())/f, , null); canvas.restore(); } }
以上代码是关于android rotateimageview 可旋转imageview 的全部内容,希望对大家有所帮助。
推荐阅读
-
Android 中ImageView的ScaleType使用方法
-
Android使用RotateImageView 旋转ImageView
-
Android 中ImageView的ScaleType使用方法
-
Android控件系列之ImageView使用方法
-
Android控件系列之ImageView使用方法
-
Android中imageView图片放大缩小及旋转功能示例代码
-
Android中imageview.ScaleType使用方法详细介绍
-
Android UI之ImageView实现图片旋转和缩放
-
Android中imageView图片放大缩小及旋转功能示例代码
-
Android中ImageView使用网络图片资源的方法