服务器之家

服务器之家 > 正文

Android使用RotateImageView 旋转ImageView

时间:2021-05-07 16:03     来源/作者:DerDeath

废话不多说了,直接给大家代码。

具体代码如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 的全部内容,希望对大家有所帮助。

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
返回顶部