Android uses Rotateimageview to rotate imageview_android

Source: Internet
Author: User

Nonsense not much said, directly to everyone code.

The specific code looks like this:

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 {/** rotation angle **/private float _degree;/** Rotary Center **/Private float _x; private fl
Oat _y;
/** background and foreground resources * * Private Bitmap _bgres, _fgres;
/** Digital Picture Resources * * Private Bitmap _nums;
Private Bitmap _buffer;
Private Canvas _canvas;
private int start =;
private int UNITX =; Public Rotateimageview {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) {_deg
ree = degree;
_x = x;
_y = y;  public float Getdegree () {return _degree.} public Float Getrotatex () {return _x.} public float Getrotatey ()
_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 (); }
}

The above code is all about the Android Rotateimageview rotatable ImageView, and hopefully it will help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.