English 中文(简体)
B. 加快实现男女两性均等对不同图象各年级学生的价值
原标题:Need Faster way to get RGB value for each Pixel of a Buffered Image

达到<条码>每一页数的微调汇率价值的最快途径是什么。 BufferedImage?

Right now I am getting the RGB values using two for loops as shown in the code below, but it took too long to get those values as the nested loop runs a total of 479999 times for my image. If I use a 16-bit image this number would be even higher!

我需要更快地获得六分之一的价值观。

在这方面,我目前正在努力与以下各方合作:

BufferedImage bi=ImageIO.read(new File("C:\images\Sunset.jpg"));

int countloop=0;  

for (int x = 0; x <bi.getWidth(); x++) {
    for (int y = 0; y < bi.getHeight(); y++) {
        Color c = new Color(bi.getRGB(x, y));
        System.out.println("red=="+c.getRed()+" green=="+c.getGreen()+"    blue=="+c.getBlue()+"  countloop="+countloop++);                                                                                                                                                  
    }
}
最佳回答

我不知道这是否有助于,我已经对它进行了测试,但你可以这样获得堡垒价值:

BufferedImage bi=ImageIO.read(new File("C:\images\Sunset.jpg"));
int[] pixel;

for (int y = 0; y < bi.getHeight(); y++) {
    for (int x = 0; x < bi.getWidth(); x++) {
        pixel = bi.getRaster().getPixel(x, y, new int[3]);
        System.out.println(pixel[0] + " - " + pixel[1] + " - " + pixel[2] + " - " + (bi.getWidth() * y + x));
    }
}

As you can see you don t have to initialize a new Color inside the loop. I also inverted the width/height loops as suggested by onemasse to retrieve the counter from data I already have.

问题回答

通过将个人体积体从一个大体的浮板改成一个阵列,将整个图像复制成一个阵列,执行时间从33 000毫秒减少到3 200毫米,而创建阵列的时间仅为31毫米秒。 www.un.org/Depts/DGACM/index_spanish.htm

无疑,一个大体读成一个阵列,直接指数化比许多个人更快。 www.un.org/Depts/DGACM/index_spanish.htm

业绩差异似乎与在班末使用记分说明有关。 虽然休息点不在圈子之内,但班级内的每一条代码似乎都经过了打破点的测试。 改变个人形象会提高速度。

由于该法典仍然正确,其余的答复可能仍然使用。

旧改为:

colorRed=new Color(bi.getRGB(x,y)).getRed();

阅读说明,将轨道图像复制成阵列

int[] rgbData = bi.getRGB(0,0, bi.getWidth(), bi.getHeight(), 
                null, 0,bi.getWidth());        

将所有3个彩色数值分成一个阵列,因此,必须以轮值和“及”方式提取个别肤色。 必须以影像的宽宏图来充实这种协调。

代码改为从阵列中排出的个人颜色

colorRed=(rgbData[(y*bi.getWidth())+x] >> 16) & 0xFF; 

colorGreen=(rgbData[(y*bi.getWidth())+x] >> 8) & 0xFF; 

colorBlue=(rgbData[(y*bi.getWidth())+x]) & 0xFF; 

您应排在外 lo和内.一栏。 这样,你就能够避开海滩。

I found a solution here https://alvinalexander.com/blog/post/java/getting-rgb-values-for-each-pixel-in-image-using-java-bufferedi

BufferedImage bi = ImageIO.read(new File("C:\images\Sunset.jpg"));

for (int x = 0; x < bi.getWidth(); x++) {
    for (int y = 0; y < bi.getHeight(); y++) {
        int pixel = bi.getRGB(x, y);
        int red = (pixel >> 16) & 0xff;
        int green = (pixel >> 8) & 0xff;
        int blue = (pixel) & 0xff;
        System.out.println("red: " + red + ", green: " + green + ", blue: " + blue);                                                                                                                                                  
    }
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签