zoukankan      html  css  js  c++  java
  • Canvas Path 绘制柱体

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            if (savedInstanceState == null) {
                getFragmentManager().beginTransaction()
                        .add(R.id.container, new PlaceholderFragment()).commit();
            }
        }
    
        /**
         * A placeholder fragment containing a simple view.
         */
        public static class PlaceholderFragment extends Fragment {
    
            public PlaceholderFragment() {
            }
            
            ImageView drawingImageView;
            
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                View rootView = inflater.inflate(R.layout.fragment_main, container,
                        false);
                
                drawingImageView = (ImageView)rootView.findViewById(R.id.drawingImageView);
                
                int width = (int) getActivity().getWindowManager().getDefaultDisplay().getWidth();
                int height = (int)getActivity().getWindowManager().getDefaultDisplay().getHeight();
                
                Bitmap bitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
                
                Canvas canvas = new Canvas(bitmap);
                drawingImageView.setImageBitmap(bitmap);
                
                Paint paint = new Paint();
                paint.setStyle(Paint.Style.FILL);
                paint.setColor(Color.GREEN);
                
                Path p = new Path();
                float offsetX = 30;
                float offsetY = 30;
                
                //正面
                p.moveTo(0.75f, 60f);
                p.lineTo(0.75f, 229.1f);
                p.lineTo(92.5f, 229.1f);
                p.lineTo(92.5f, 60f);
                p.lineTo(0.75f, 60f);
                canvas.drawPath(p, paint);
    
                //右侧面
                p.reset();
                p.moveTo(92.5f, 60f);
                p.lineTo(92.5f, 229.1f);
                p.lineTo(92.5f+offsetX, 229.1f-offsetY);
                p.lineTo(92.5f+offsetX, 60f-offsetY);
                p.lineTo(92.5f, 60f);
                canvas.drawPath(p, paint);
                
                //上面
                p.reset();
                p.moveTo(0.75f+offsetX, offsetY);
                p.lineTo(0.75f, 60f);
                p.lineTo(92.5f, 60f);
                p.lineTo(92.5f+offsetX, 60f-offsetY);
                p.lineTo(0.75f+offsetX, offsetY);
                canvas.drawPath(p, paint);
                
                //针对上面,绘制一个白色的菱形强化立体效果
                paint.reset();
                paint.setStyle(Style.STROKE);
                paint.setColor(Color.WHITE);
                
                p.reset();
                p.moveTo(0.75f+offsetX, offsetY);
                p.lineTo(0.75f, 60f);
                p.lineTo(92.5f, 60f);
                p.lineTo(92.5f+offsetX, 60f-offsetY);
                p.lineTo(0.75f+offsetX, offsetY);
                canvas.drawPath(p, paint);
                
                //针对右侧面,绘制一个白色菱形强化立体效果
                p.reset();
                p.moveTo(92.5f, 60f);
                p.lineTo(92.5f, 229.1f);
                p.lineTo(92.5f+offsetX, 229.1f-offsetY);
                p.lineTo(92.5f+offsetX, 60f-offsetY);
                p.lineTo(92.5f, 60f);
                canvas.drawPath(p, paint);
                
                return rootView;
            }
        }
    
    }
  • 相关阅读:
    [转]How can I create a design netlist without including my source design files?
    [转]基于FPGA的以太网开发
    [转]GMII/RGMII/SGMII/TBI/RTBI接口信号及时序介绍
    [原]Altium画PCB时鼠标十字不能对准焊盘中心
    [转]Altera特殊管脚的使用(适用全系列Altera FPGA,MSEL区别除外)-来自altera论坛
    [转]STM32正交编码器驱动电机
    [转]使用D触发器制作正交编码器的鉴相电路
    [转]解决STM32开启定时器时立即进入一次中断程序问题
    [转]ISE iMPACT bit生成mcs
    [转]NiosII处理器软件代码优化方法
  • 原文地址:https://www.cnblogs.com/yshyee/p/4115472.html
Copyright © 2011-2022 走看看