Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建仅包含指定像素的ArrayList_Java_Image Processing_Arraylist - Fatal编程技术网

Java 创建仅包含指定像素的ArrayList

Java 创建仅包含指定像素的ArrayList,java,image-processing,arraylist,Java,Image Processing,Arraylist,我正在加载一个BuffereImage并根据像素的xy位置获取其RGB值。 之后,我想创建一个只包含黑色像素的ArrayList。 我正在尝试创建列表,以便执行以下操作: List<Integer> blackpixels = new ArrayList<Integer>(); List blackpixels=new ArrayList(); 但是我在声明列表的行中得到了这个错误: 类型列表不是泛型的;不能使用参数对其进行参数化 以下是我的完整代码: import

我正在加载一个BuffereImage并根据像素的xy位置获取其RGB值。 之后,我想创建一个只包含黑色像素的ArrayList。 我正在尝试创建列表,以便执行以下操作:

List<Integer> blackpixels = new ArrayList<Integer>();
List blackpixels=new ArrayList();
但是我在声明列表的行中得到了这个错误:

类型列表不是泛型的;不能使用参数对其进行参数化

以下是我的完整代码:

import java.awt.Color;
import java.awt.List;
import java.awt.image.BufferedImage;
import java.util.*;


public class ImageTest {
    public static BufferedImage Threshold(BufferedImage img) {

        int height = img.getHeight();
        int width = img.getWidth();
        BufferedImage finalImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);

        int r = 0;
        int g = 0;
        int b = 0;
        List<Integer> blackpixels = new ArrayList<Integer>();



        for (int x = 0; x < width; x++) {
//          System.out.println("Row: " + x);
            try {

                for (int y = 0; y < height; y++) {

                    //Get RGB values of pixels
                    int rgb = img.getRGB(x, y); 
                    r = ImageTest.getRed(rgb);
                    g = ImageTest.getGreen(rgb);
                    b = ImageTest.getBlue(rgb);


                    finalImage.setRGB(x,y,ImageTest.mixColor(r, g,b));  
                    System.out.println(r);
                }

                }
            catch (Exception e) {
                    e.getMessage();
            }
    }
    return finalImage;

    }
    private static int mixColor(int red, int g, int b) {
        return red<<16|g<<8|b;
    }

    public static int getRed(int rgb) {
        return (rgb & 0x00ff0000)  >> 16;
    }

    public static int getGreen(int rgb) {
        return  (rgb & 0x0000ff00)  >> 8;
    }

    public static int getBlue(int rgb) {
        return (rgb & 0x000000ff)  >> 0;

    }
}
导入java.awt.Color;
导入java.awt.List;
导入java.awt.image.buffereImage;
导入java.util.*;
公共类图像测试{
公共静态BuffereImage阈值(BuffereImage img){
int height=img.getHeight();
int width=img.getWidth();
BuffereImage finalImage=新的BuffereImage(宽度、高度、BuffereImage.TYPE_INT_RGB);
int r=0;
int g=0;
int b=0;
List blackpixels=new ArrayList();
对于(int x=0;x>0;
}
}

您得到的错误是,您试图创建的
列表来自
java.awt.List
,而不是
java.util.List
。如果不打算使用
java.awt.List
,只需删除

import java.awt.List; 

您已经使用
import java.util.*导入了正确的类,因此在删除上述句子后,它应该可以正常工作。

您得到的错误是,您试图创建的
列表来自
java.awt.List
,而不是
java.util.List
。如果不打算使用
java.awt.List
,只需删除

import java.awt.List; 
您已经使用
import java.util.*导入了正确的类,因此在删除上述句子后,它应该可以正常工作