java byte数组的RBG转int的RBG,从而用BufferedImage表示图像
刚接触opencv,想显示个图片都不会,所以想写一个opencv的图像类转BufferedImage的方法
<span style="font-family: Arial, Helvetica, sans-serif;">BufferedImage mat2BufferedImage(Mat mat){ BufferedImage bi=new BufferedImage(mat.width(),mat.height(),BufferedImage.TYPE_INT_RGB );//这里t的type不太懂 for(int i=0;i<mat.rows();i++){//mat.height() for(int j=0;j<mat.cols();j++){ byte[] b=new byte[3]; mat.get(i, j, b);//把rgb值放入b int rgb=((int)b[0])&0xff;//&0xff是为了不让结果变为负数//不知道为什么获取的b[0]是蓝色的 rgb|=(((int)b[1])&0xff)<<8;//每8位放一个值 rgb|=(((int)b[2])&0xff)<<16; rgb|=0xff000000;//从BufferedImage.getRBG()看出,这个类表示的RBG左边8位均为1 bi.setRGB(j, i, rgb); } } return bi; }</span>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。