Comparing Pixelation from Image to render object

I was working on simply grabbing a pixel from an image using inner java API. One of the problems I stumbled upon was matching a AWT color to a JME ColorRGBA. I eventually figured out the problem after some googling yet this not the initial problems I am facing. The point is I have a Image with a Schematic of a 2D Rectangle that was created in any Image Processing Application. So a BLUE SQAURE would be the location of a 3D Rectangle. After reading an Image from ImageIO from FILE than scanning each pixel in the corresponding color. If the pixel is BLUE than RENDER CUBE.

This would be the basis of the Terrain Object Generation. I been surfing the net for answers and help on my project. Here is some Code ::

import java.awt.Color;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;

import javax.imageio.ImageIO;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;

public class zMod extends SimpleApplication{
public static String f_path = “C:/Users/null/eclipse_wk/ActOne/src/”;

public static String bp0 = "blueprint";

public static String f_type_0 = ".jpg";
public static String f_type_1 = ".png";

public static ColorRGBA c_rgba;
public static Color c_;

public static int x_ord;
public static int y_ord;

public static int x_max; // setup getter
public static int y_max;


public static Color getPixelColor(int x, int y, String locate_file) {
	Color c_ = Color.white;
	
	File file = new File(locate_file);
	BufferedImage image = null;
	if(image == null) {
		try {
			image = ImageIO.read(file);
			x_max = image.getWidth();
			y_max = image.getHeight(); 
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 // Getting pixel color by position x and y 
        int clr = image.getRGB(x, y);
        int red =   (clr & 0x00ff0000) >> 16;
        int green = (clr & 0x0000ff00) >> 8;
        int blue =   clr & 0x000000ff;
        
        c_ = new Color(red, green, blue);
        
        System.out.println("Red Color value = " + red);
        System.out.println("Green Color value = " + green);
        System.out.println("Blue Color value = " + blue);
        System.out.println(c_ + "--:|= rgba");
	}
    
    
    
   return c_;
}

public static ColorRGBA getPixel(int x, int y, String locate_file){
	ColorRGBA c_rgba = ColorRGBA.White;
	
	File file = new File(locate_file);
	BufferedImage image = null;
	if(image == null) {
		try {
			image = ImageIO.read(file);
			
	        
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 // Getting pixel color by position x and y 
        int clr = image.getRGB(x, y);
        int red =   (clr & 0x00ff0000) >> 16;
        int green = (clr & 0x0000ff00) >> 8;
        int blue =   clr & 0x000000ff;
        
        c_rgba.set(red, green, blue , 255);
        
        x_max = image.getWidth();
		y_max = image.getHeight();
        
        System.out.println("Red Color value = " + red);
        System.out.println("Green Color value = " + green);
        System.out.println("Blue Color value = " + blue);
        System.out.println(c_rgba + "--:|= rgba");
	}
    
    
    
   return c_rgba;
}

public static void main(String[] args) throws IOException {
	
	zMod zc = new zMod();
	
	AppSettings setting = new AppSettings(true);
	setting.setSettingsDialogImage("/Textures/ui/drag_splash.png");
	zc.setSettings(setting);
	zc.start();
	
	
}


@Override
public void simpleInitApp() {
	System.out.println(":---[" + x_max + "]---:");
	for(x_ord = 0; x_ord <= x_max; x_ord++) {
		for(y_ord = 0; y_ord <= y_max; y_ord++) {
			System.out.println("[" + x_ord + "]" +"[" + y_ord + "]:--:" + getPixel(x_ord, y_ord, (f_path + bp0 + f_type_1))); 

		}
	}
}

@Override
public void simpleUpdate(float tpf) {

}

}

Problem I am facing is with ARRAY BUFFER OVERFLOW. Maybe ran out of RAM?
blueprint

Im not sure if you all understand what my current objective is.
Scan Image -> Match Color( Pixel ) -> add cube at coordiante ( Pixel );

  Box b = new Box(Pixel.X, 1, Pixel.Y); // create cube shape
    Geometry geom = new Geometry("Box", b);  // create cube geometry from the shape
    Material mat = new Material(assetManager,
      "Common/MatDefs/Misc/Unshaded.j3md");  // create a simple material
    /*----- SET UP TEXTURE ---*/
    geom.setMaterial(mat);                   // set the cube's material
    rootNode.attachChild(geom);              // make the cube appear in the scene

Do you know about gamma correction?

Was it an exception? Or?

Note: for exceptions, the stack trace is 99% of the useful information.

And I suspect that is not doing what you think it is. Look at the javadoc for Box.

Hi Zero_Cool,

I am a newbie learning how to program game. I have not done any game at the moment. However, I notice you are using “java.awt.", which, I heard, is using CPU, and " com.jme3.”, which is using GPU.

Wouldn’t that slow your program down? Shouldn’t you change from “java.awt.*” to something else from jme?

Thank you.

I am loading the Image in a Buffer. That initializes the image in memory not processing it to display anything. My goal is to develop a program that displays a 3D scale of the 2D image. Like the schematics of a architectural building. A BluePrint for a build or object to spawn into the world.

puesodu ::

IF(PIXEL == COLOR.BLUE)Generate 3D object @ COORDERAINTS (PIXEL) to 3D Scene

Thank you.

I am guessing from my opinion, which I hope you do not mind, that RGBA in this case is kind of OpenGL RGBA. It requires certain way to perform conversion. Maybe, something likes this, below.

I do not know more than this, however.