Android复习14【高级编程:推荐网址、抠图片上的某一角下来、Bitmap引起的OOM问题、三个绘图工具类详解、画线条、Canvas API详解(平移、旋转、缩放、倾斜)、矩阵详解】

   日期:2020-06-04     浏览:109    评论:0    
核心提示:推荐网址抠图片上的某一角下来8.2.2Bitmap引起的OOM问题8.3.1三个绘图工具类详解画线条8.3.16CanvasAPI详解(Part1)1.translate(平移)2.rotate(旋转)3.scale(缩放)4.skew(倾斜)AndroidMatrix详解

目   录

推荐网址

抠图片上的某一角下来

8.2.2 Bitmap引起的OOM问题

8.3.1 三个绘图工具类详解

画线条

8.3.16 Canvas API详解(Part 1)

1.translate(平移)

2.rotate(旋转)

3.scale(缩放)

4.skew(倾斜)

Android Matrix 详解

推荐网址

【菜鸟教程】8.2.1 Bitmap(位图)全解析 Part 1
https://www.runoob.com/w3cnote/android-tutorial-bitmap1.html


1.Android自定义控件
https://blog.csdn.net/yuanheng19930119/article/details/88055225

2.自定义控件其实很简单
https://blog.csdn.net/aigestudio/article/details/41212583?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-2

3.Android Matrix 详解
https://www.jianshu.com/p/5e30db034596

4.android matrix 最全方法详解与进阶
https://blog.csdn.net/cquwentao/article/details/51445269

5.Android动画
https://blog.csdn.net/zhangbijun1230/article/details/80262359

抠图片上的某一角下来

 

Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.mipmap.pic_meizi);
Bitmap bitmap2 = Bitmap.createBitmap(bitmap1,100,100,200,200);
img_bg = (ImageView) findViewById(R.id.img_bg);
img_bg.setImageBitmap(bitmap2);

8.2.2 Bitmap引起的OOM问题

https://www.runoob.com/w3cnote/android-tutorial-bitmap2.html

8.3.1 三个绘图工具类详解

https://www.runoob.com/w3cnote/android-tutorial-drawable-tool.html

画线条

【菜鸟教程】8.3.2 绘图类实战示例

https://www.runoob.com/w3cnote/android-tutorial-bitmap-demo.html


public class MyView extends View{

    private Paint mPaint;  //绘制线条的Path
    private Path mPath;      //记录用户绘制的Path
    private Canvas mCanvas;  //内存中创建的Canvas
    private Bitmap mBitmap;  //缓存绘制的内容

    private int mLastX;
    private int mLastY;

    public MyView(Context context) {
        super(context);
        init();
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        mPath = new Path();
        mPaint = new Paint();   //初始化画笔
        mPaint.setColor(Color.GREEN);
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND); //结合处为圆角
        mPaint.setStrokeCap(Paint.Cap.ROUND); // 设置转弯处为圆角
        mPaint.setStrokeWidth(20);   // 设置画笔宽度
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = getMeasuredWidth();
        int height = getMeasuredHeight();
        // 初始化bitmap,Canvas
        mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
    }

    //重写该方法,在这里绘图
    @Override
    protected void onDraw(Canvas canvas) {
        drawPath();
        canvas.drawBitmap(mBitmap, 0, 0, null);
    }

    //绘制线条
    private void drawPath(){
        mCanvas.drawPath(mPath, mPaint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {

        int action = event.getAction();
        int x = (int) event.getX();
        int y = (int) event.getY();

        switch (action)
        {
            case MotionEvent.ACTION_DOWN:
                mLastX = x;
                mLastY = y;
                mPath.moveTo(mLastX, mLastY);
                break;
            case MotionEvent.ACTION_MOVE:
                int dx = Math.abs(x - mLastX);
                int dy = Math.abs(y - mLastY);
                if (dx > 3 || dy > 3)
                    mPath.lineTo(x, y);
                mLastX = x;
                mLastY = y;
                break;
        }

        invalidate();
        return true;
    }
}

 

8.3.16 Canvas API详解(Part 1)

【菜鸟教程】https://www.runoob.com/w3cnote/android-tutorial-canvas-api1.html

1.translate(平移)

2.rotate(旋转)

3.scale(缩放)

4.skew(倾斜)

Android Matrix 详解

https://www.jianshu.com/p/5e30db034596

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
更多>相关资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服