欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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 的全部内容,希望对大家有所帮助。

上一篇:

下一篇: