編輯:關於Android編程
Android 切圓圖
效果圖如下:

MyView 類
public class MyView extends View {
Bitmap bmp;
Paint paint = new Paint();
public MyView(Context context) {
super(context);
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
bmp = BitmapFactory.decodeResource(getResources(), R.mipmap.c);
src = new RectF(bmp.getWidth() / 2 - 50, bmp.getHeight() / 2 - 50, bmp.getWidth() / 2 + 50, bmp.getHeight() / 2 + 50);
dst = new Rect(200, 200, 400, 400);
paint.setAntiAlias(true);
paint.setDither(true);
Shader shaer = new BitmapShader(bmp, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT);
paint.setShader(shaer);
}
private RectF src = null;
private Rect dst = null;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//繪制Bitmap
Matrix m = new Matrix();
//每次set都會重置矩形
m.setRotate(90, bmp.getWidth() / 2, bmp.getHeight() / 2);
m.postTranslate(100, 100);
m.preScale(0.5f, 0.5f, bmp.getWidth() / 2, bmp.getHeight() / 2);
//錯切
m.postSkew(0.3f, 0.3f);
// canvas.drawBitmap(bmp, m, null);
// canvas.drawBitmap(bmp, src, dst, null);
//拿view的高寬
canvas.drawArc(src, 100, 270, true, paint);
}
}
MainActivity 類
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.administrator.lesson12_drawbitmap.MainActivity">
<com.example.administrator.lesson12_drawbitmap.MyView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
Android SystemProperties系統屬性詳解
Systemproperties類在android.os下,但這個類是隱藏的,上層程序開發無法直接使用,用Java的反射機制就可以了。Java代碼中創建與修改androi
Android開發記錄16-友盟第三方登錄、分享實現
Android開發記錄16-友盟第三方登錄、分享實現 本篇博客給大家分享一個筆者正在做的關於第三方登錄、分享的實例,這裡選用的是友盟社會化組件。 博客大綱如
關於Android中圖片大小、內存占用與drawable文件夾關系的研究與分析
從上一篇文章《Android屏幕適配全攻略》寫完之後,經常會有朋友問我這個問題:“能不能一個App只提供一套切圖適應所有的分辨率呢?”我覺得有必
Android下led控制(下)--Linux部分
這一篇我想說說Linux下的部分,從上一篇我們可以知道,jni通過打開led設備/dev/led,進而使用ioctl函數來控制led的亮和滅和蜂鳴器的發聲。那麼在Linu