| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3399 人关注过本帖
标题:不知道那里出错,找不出来,请帮忙看看,谢谢!!!
只看楼主 加入收藏
笔墨痕干
Rank: 1
等 级:新手上路
威 望:1
帖 子:56
专家分:0
注 册:2014-3-24
结帖率:84.21%
收藏
 问题点数:0 回复次数:1 
不知道那里出错,找不出来,请帮忙看看,谢谢!!!
程序代码:
private void initIdentifyTabView() {
        // TODO Auto-generated method stub
        final TextView sample01 = (TextView) identifyTabView
                .findViewById(R.id.sample01);
        final TextView sample02 = (TextView) identifyTabView
                .findViewById(R.id.sample02);
        final TextView sample03 = (TextView) identifyTabView
                .findViewById(R.id.sample03);
        final TextView textColorDiff = (TextView) identifyTabView
                .findViewById(R.id.textColorDiff);
        final TextView textColorInfo = (TextView) identifyTabView
                .findViewById(R.id.textColorInfo);
        final View viewPickedColor = identifyTabView
                .findViewById(R.id.viewPickedColor);
        Button btnCamera = (Button) identifyTabView
                .findViewById(R.id.btnCamera);
        // 设置初始默认显示的辨色图片
        Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                R.drawable.android);
        imageview = identifyTabView.findViewById(R.id.viewPicture);
        imageview.setBackgroundDrawable(new BitmapDrawable(bmp));
        // 从触摸图片以辨别颜色
        imageview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int x = (int) event.getX();
                int y = (int) event.getY();
                int w = imageview.getWidth();
                int h = imageview.getHeight();
                // 限制触摸位置的范围,避免超出图片之外
                if (x < 0 || y < 0 || x >= w || y >= h) {
                    textColorInfo.setText("超出范围");
                    return true;
                }
                // 如果图像没有初始化,则先获得图像数据
                if (pickbmp == null) {
                    Bitmap bgBmp = ((BitmapDrawable) imageview.getBackground())
                            .getBitmap();
                    pickbmp = Bitmap.createScaledBitmap(bgBmp, w, h, false);
                }
                // 得到当前触摸的像素颜色并显示
                int pixel = pickbmp.getPixel(x, y);
                viewPickedColor.setBackgroundColor(pixel);
                // 显示其RGB 值
                String rgb = "#"
                        + Integer.toHexString(pixel).substring(2).toUpperCase();
                textColorInfo.setText("当前颜色:" + rgb);
                // 转换当前像素为HSV 颜色,为颜色差异计算做准备
                int r = Color.red(pixel);
                int g = Color.green(pixel);
                int b = Color.blue(pixel);
                float[] hsv = new float[3];
                Color.RGBToHSV(r, g, b, hsv);
               
                String[][] str=new String[sampleList.size()][2];
                for(int i=0;i<sampleList.size();i++){
                    String RGB=sampleList.get(i).rgb;
                    int val1=Color.parseColor(RGB);
                   
                    int r1=Color.red(val1);
                    int g1=Color.green(val1);
                    int b1=Color.blue(val1);
                    //转换rgb颜色为hsv颜色
                    float[] hsv1=new float[3];
                    Color.RGBToHSV(r1,g1,b1,hsv1);
                   
                    String s=ColorSample.distHSV(hsv[1],hsv[2],hsv[3],hsv1[1],hsv1[2],hsv1[3])+"";
                    str[i][0]=s;
                    str[i][1]=RGB;
                }
                //数组排序
                for(int i=0;i<str.length;i++){
                    for(int j=0;j<str.length-1;j++){
                        String[] ss;
                        if (str[i][0].compareTo(str[i + 1][0]) > 0) {
                            ss = str[i];
                            str[i] = str[i + 1];
                            str[i + 1] = ss;
                           
                        }
                    }
                }
                    String grb1=str[0][1];
                    String grb2=str[1][1];
                    String grb3=str[2][1];
                   
                    textColorDiff.setText("差异度:" + Integer.parseInt(str[0][0]) + ", " + Integer.parseInt(str[1][0]) + ", "
                            + Integer.parseInt(str[2][0]));
                   
                    sample01.setBackgroundColor(Integer.parseInt(grb1));
                    sample02.setBackgroundColor(Integer.parseInt(grb2));
                    sample03.setBackgroundColor(Integer.parseInt(grb1));
    
                return true;
            }
           
        });
    }
    //色卡数据列表,这个程序前面定义的sampleList,
    private List<ColorSample> sampleList=new ArrayList<ColorSample>();
触摸事件一触动,程序就报错了,
搜索更多相关主题的帖子: private method 
2015-04-23 15:32
q215236213
Rank: 4
等 级:业余侠客
威 望:1
帖 子:148
专家分:276
注 册:2012-7-24
收藏
得分:0 
错误信息要能贴出来的话,最好能贴上
2015-05-10 20:57
快速回复:不知道那里出错,找不出来,请帮忙看看,谢谢!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021586 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved