Java Code Examples for java.awt.image.BufferedImage.TYPE_3BYTE_BGR

The following are Jave code examples for showing how to use TYPE_3BYTE_BGR of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jaer   File: OpenCVFlow.java   View Source Code Vote up 6 votes
public BufferedImage Mat2BufferedImage(Mat m) {
    // source: http://answers.opencv.org/question/10344/opencv-java-load-image-to-gui/
    // Fastest code
    // The output can be assigned either to a BufferedImage or to an Image

    int type = BufferedImage.TYPE_BYTE_GRAY;
    if (m.channels() > 1) {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }
    int bufferSize = m.channels() * m.cols() * m.rows();
    byte[] b = new byte[bufferSize];
    m.get(0, 0, b); // get all the pixels
    BufferedImage image = new BufferedImage(m.cols(), m.rows(), type);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(b, 0, targetPixels, 0, b.length);
    return image;

}
 
Example 2
Project: PiCameraProject   File: ImagesEndpoint.java   View Source Code Vote up 6 votes
@GET
@Path("/thumb/{date}")
@Produces("image/jpeg")
public Response photo(@PathParam("date") String whenStr){
    final java.nio.file.Path path = find(whenStr);
    if(!Files.exists(path)){
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    
    try(InputStream in = Files.newInputStream(path)) {
        final BufferedImage image = ImageIO.read(in);
        final byte[] b = new byte[2048];
        //for(int length=in.read(b); length>0; length=in.read(b)){
            //stream.write(b, 0, length);
        //}
        final int width=320, height=240;
        final Image scaled = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        BufferedImage dimg = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        dimg.getGraphics().drawImage(scaled, 0, 0, null);
        ImageIO.write(dimg, "JPG", stream);
    } catch (IOException ex) {
        Logger.getLogger(ImagesEndpoint.class.getName()).log(Level.SEVERE, null, ex);
    }
    return Response.ok(stream.toByteArray()).build();
}
 
Example 3
Project: openjdk-jdk10   File: DeviceBounds.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    // NB: all images have the same type
    BufferedImage[] images = new BufferedImage[] {
            new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR),
            new BufferedImage(400, 400, BufferedImage.TYPE_3BYTE_BGR),
            new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR)
    };
    int count = 0;
    for (BufferedImage i : images) {
        Graphics2D g = i.createGraphics();
        Rectangle bounds[] = new Rectangle[images.length];
        bounds[count] = g.getDeviceConfiguration().getBounds();
        System.out.println(bounds[count]);

        g.dispose();
        if (bounds[count].width != Integer.MAX_VALUE) {
            throw new RuntimeException("Wrong getBounds");
        }
        count++;
    }
}
 
Example 4
Project: PiCameraProject   File: ErikDetectorAlgorithm.java   View Source Code Vote up 6 votes
@Override
public BufferedImage prepareImage(BufferedImage bi) {
    System.out.println("preparing " + bi + " at " + bi.getWidth() + "x" + bi.getHeight());
    final double resizePct = SCALE_WIDTH / (double)bi.getWidth();
    final int scaleHeight = (int) (resizePct * bi.getHeight());
    System.out.println("  scaling at " + resizePct + " is " + scaleHeight);
    final Image scaled = bi.getScaledInstance(SCALE_WIDTH, scaleHeight, Image.SCALE_SMOOTH);
    BufferedImage dimg = new BufferedImage(SCALE_WIDTH, scaleHeight, BufferedImage.TYPE_3BYTE_BGR);
    dimg.getGraphics().drawImage(scaled, 0, 0, null);
    for (int i = 0; i < scaleHeight; i++) {

        for (int j = 0; j < SCALE_WIDTH; j++) {

            Color c = new Color(dimg.getRGB(j, i));
            int red = (int) (c.getRed() * 0.299);
            int green = (int) (c.getGreen() * 0.587);
            int blue = (int) (c.getBlue() * 0.114);
            Color newColor = new Color(red + green + blue,
                    red + green + blue, red + green + blue);

            dimg.setRGB(j, i, newColor.getRGB());
        }
    }
    return dimg;
}
 
Example 5
Project: openjdk-jdk10   File: ColConvTest.java   View Source Code Vote up 6 votes
static String getImageTypeName(int type) {
    switch(type) {
        case BufferedImage.TYPE_INT_ARGB:
            return "TYPE_INT_ARGB";
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_INT_ARGB_PRE:
            return "TYPE_INT_ARGB_PRE";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_4BYTE_ABGR:
            return "TYPE_4BYTE_ABGR";
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            return "TYPE_4BYTE_ABGR_PRE";
        case BufferedImage.TYPE_BYTE_BINARY:
            return "TYPE_BYTE_BINARY";
        case BufferedImage.TYPE_BYTE_GRAY:
            return "TYPE_BYTE_GRAY";
        case BufferedImage.TYPE_BYTE_INDEXED:
            return "TYPE_BYTE_INDEXED";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case BufferedImage.TYPE_USHORT_GRAY:
            return "TYPE_USHORT_GRAY";
    }
    return "UNKNOWN";
}
 
Example 6
Project: openjdk-jdk10   File: WriteProgressive.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws IOException {
    Iterator witer = ImageIO.getImageWritersByFormatName("png");
    ImageWriter w = (ImageWriter)witer.next();

    File f = File.createTempFile("WriteProgressive", ".png");
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    w.setOutput(ios);

    BufferedImage bi = new BufferedImage(100, 100,
                                         BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = bi.createGraphics();
    Random r = new Random(10);
    for (int i = 0; i < 10000; i++) {
        Color c =
            new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
        g.setColor(c);
        g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1);
    }

    IIOImage iioimage = new IIOImage(bi, null, null);

    ImageWriteParam param = w.getDefaultWriteParam();
    param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);

    try {
        w.write(null, iioimage, param);
    } catch (NullPointerException npe) {
        throw new RuntimeException("Got NPE during write!");
    }

    ios.close();

    BufferedImage bi2 = ImageIO.read(f);
    f.delete();

    ImageCompare.compare(bi, bi2);
}
 
Example 7
Project: classchecks   File: ImageGui.java   View Source Code Vote up 5 votes
private Image toBufferedImage(Mat matrix) {
	int type = BufferedImage.TYPE_BYTE_GRAY;
	if (matrix.channels() > 1) {
		type = BufferedImage.TYPE_3BYTE_BGR;
	}
	int bufferSize = matrix.channels() * matrix.cols() * matrix.rows();
	byte[] buffer = new byte[bufferSize];
	matrix.get(0, 0, buffer); // 获取所有的像素点
	
	BufferedImage image = new BufferedImage(matrix.cols(), matrix.rows(), type);
	final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
	System.arraycopy(buffer, 0, targetPixels, 0, buffer.length);
	return image;
}
 
Example 8
Project: Pixie   File: Resize.java   View Source Code Vote up 5 votes
/**
 * Resizes an image to the wanted size, based on the provided resize ratio.
 * The resize is done the same for width and height.
 *
 * @param origImg - the image to be resized
 * @return - returns the new resized image
 */
public BufferedImage resizeImage(BufferedImage origImg) {
    if ((origImg == null) || (Double.compare(ratioWidth, 0.0) == 0) || (Double.compare(ratioHeight, 0.0) == 0)) {
        return null;
    }

    int w1 = origImg.getWidth();
    int h1 = origImg.getHeight();
    int w2 = (int) (w1 / ratioWidth);
    int h2 = (int) (h1 / ratioHeight);
    float wRatio = (float) w2 / (float) w1;
    float hRatio = (float) h2 / (float) h1;

    BufferedImage workImg = new BufferedImage(w2, h2, BufferedImage.TYPE_3BYTE_BGR);

    // for down-scale
    if ((ratioWidth >= 1.0f) && (ratioHeight >= 1.0f)) {
        for (int y = 0; y < h2; y++) {
            for (int x = 0; x < w2; x++) {
                workImg.setRGB(x, y, origImg.getRGB((int) (x * ratioWidth + 0.5f), (int) (y * ratioHeight + 0.5f)));
            }
        }
    } else {
        // for up-scale
        for (int y = 0; y < h2; y++) {
            for (int x = 0; x < w2; x++) {
                workImg.setRGB(x, y, origImg.getRGB((int) (x / wRatio), (int) (y / hRatio)));
            }
        }
    }

    return workImg;
}
 
Example 9
Project: rapidminer   File: MenuSeparatorPainter.java   View Source Code Vote up 5 votes
@Override
protected Image createImage(Component c, int w, int h, GraphicsConfiguration config) {
	if (config == null) {
		return new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
	}
	return config.createCompatibleVolatileImage(w, h);
}
 
Example 10
Project: imageio-jnr   File: TurboJpeg.java   View Source Code Vote up 5 votes
/** Decode the JPEG image in the input buffer into a BufferedImage.
 *
 * @param jpegData  JPEG data input buffer
 * @param info Information about the JPEG image in the buffer
 * @param size Target decompressed dimensions, must be among the available sizes (see {@link Info#getAvailableSizes()})
 * @return The decoded image
 * @throws TurboJpegException
 */
public BufferedImage decode(byte[] jpegData, Info info, Dimension size) throws TurboJpegException {
  Pointer codec = null;
  try {
    codec = lib.tjInitDecompress();
    int width = info.getWidth();
    int height = info.getHeight();
    if (size != null) {
      if (!info.getAvailableSizes().contains(size)) {
        throw new IllegalArgumentException(String.format(
            "Invalid size, must be one of %s", info.getAvailableSizes()));
      } else {
        width = size.width;
        height = size.height;
      }
    }
    boolean isGray = info.getSubsampling() == TJSAMP.TJSAMP_GRAY.intValue();
    int imgType;
    if (isGray) {
      imgType = BufferedImage.TYPE_BYTE_GRAY;
    } else {
      imgType = BufferedImage.TYPE_3BYTE_BGR;
    }
    BufferedImage img = new BufferedImage(width, height, imgType);
    // Wrap the underlying data buffer of the image with a ByteBuffer so we can pass it over the ABI
    ByteBuffer outBuf = ByteBuffer.wrap(((DataBufferByte) img.getRaster().getDataBuffer()).getData())
                                  .order(runtime.byteOrder());
    int rv = lib.tjDecompress2(
        codec, ByteBuffer.wrap(jpegData), jpegData.length, outBuf,
        width, isGray ? width : width * 3, height, isGray ? TJPF.TJPF_GRAY : TJPF.TJPF_BGR, 0);
    if (rv != 0) {
      LOG.error("Could not decompress JPEG (dimensions: {}x{}, gray: {})", width, height, isGray);
      throw new TurboJpegException(lib.tjGetErrorStr());
    }
    return img;
  } finally {
    if (codec != null && codec.address() != 0) lib.tjDestroy(codec);
  }
}
 
Example 11
Project: openjdk-jdk10   File: NoExtraBytesTest.java   View Source Code Vote up 5 votes
private static String getImageTypeName(int t) {
    switch(t) {
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case TYPE_INT_GRB:
            return "TYPE_INT_GRB";
        case TYPE_INT_GBR:
            return "TYPE_INT_GBR";
        case TYPE_INT_RBG:
            return "TYPE_INT_RBG";
        case TYPE_INT_BRG:
            return "TYPE_INT_BRG";
        case TYPE_INT_555_GRB:
            return "TYPE_INT_555_GRB";
        case TYPE_3BYTE_RGB:
            return "TYPE_3BYTE_RGB";
        case TYPE_3BYTE_GRB:
            return "TYPE_3BYTE_GRB";
        default:
            throw new IllegalArgumentException("Unknown image type: " + t);
    }
}
 
Example 12
Project: OpenJSharp   File: Destinations.java   View Source Code Vote up 5 votes
public static void init() {
    destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
                                   "dest", "Output Destination Options");

    new Screen();
    new OffScreen();

    if (GraphicsTests.hasGraphics2D) {
        if (ImageTests.hasCompatImage) {
            compatimgdestroot =
                new Group.EnableSet(destroot, "compatimg",
                                    "Compatible Image Destinations");
            compatimgdestroot.setHorizontal();

            new CompatImg();
            new CompatImg(Transparency.OPAQUE);
            new CompatImg(Transparency.BITMASK);
            new CompatImg(Transparency.TRANSLUCENT);
        }

        if (ImageTests.hasVolatileImage) {
            new VolatileImg();
        }

        bufimgdestroot = new Group.EnableSet(destroot, "bufimg",
                                             "BufferedImage Destinations");

        new BufImg(BufferedImage.TYPE_INT_RGB);
        new BufImg(BufferedImage.TYPE_INT_ARGB);
        new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
        new BufImg(BufferedImage.TYPE_3BYTE_BGR);
        new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
        new BufImg(BufferedImage.TYPE_BYTE_GRAY);
        new CustomImg();
    }
}
 
Example 13
Project: chordatlas   File: MiniFacade.java   View Source Code Vote up 5 votes
public BufferedImage render( double res, Feature... fs ) {
	BufferedImage bi = new BufferedImage( (int) ( res * width ), (int) ( res * height ), BufferedImage.TYPE_3BYTE_BGR );

	Graphics g = bi.getGraphics();

	g.setColor( Color.black );
	g.fillRect( 0, 0,  bi.getWidth(),  bi.getHeight() );
	
	if ( fs.length == 0 ) 
	{
		BufferedImage source = imageFeatures.getRectified();

		if ( source != null ) {
			g.drawImage( source,
					0, 0, bi.getWidth(), bi.getHeight(),
					(int) ( ( left - imageXM ) * scale ), source.getHeight() - (int) ( ( height ) * scale ), (int) ( ( left + width - imageXM ) * scale ), source.getHeight(), null );
		}
	}
	else
	{
		for ( Feature f : fs ) {

			g.setColor( f.color );

			for ( FRect w : rects.get( f ) ) {
				if ( w.width * w.height > 0.2 ) {
					g.fillRect( (int) ( res * ( w.x - left ) ), bi.getHeight() - (int)( res * ( w.y + w.height) ), (int) ( res * w.width ), (int) ( res * w.height ) );
				}
			}
		}
	}

	g.dispose();

	return bi;
}
 
Example 14
Project: GazePlay   File: HeatChart.java   View Source Code Vote up 5 votes
/**
 * Generates and returns a new chart <code>Image</code> configured according to this object's currently held
 * settings. The given parameter determines whether transparency should be enabled for the generated images.
 * 
 * <p>
 * No chart will be generated until this or the related <code>saveToFile(File)</code> method are called. All
 * successive calls will result in the generation of a new chart images, no caching is used.
 * 
 * @param alpha
 *            whether to enable transparency.
 * @return A newly generated chart <code>Image</code>. The returned images is a <code>BufferedImage</code>.
 */
public Image getChartImage(boolean alpha) {
    // Calculate all unknown dimensions.
    measureComponents();
    updateCoordinates();

    // Determine images type based upon whether require alpha or not.
    // Using BufferedImage.TYPE_INT_ARGB seems to break on jpg.
    int imageType = (alpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);

    // Create our chart images which we will eventually draw everything on.
    BufferedImage chartImage = new BufferedImage(chartSize.width, chartSize.height, imageType);
    Graphics2D chartGraphics = chartImage.createGraphics();

    // Use anti-aliasing where ever possible.
    chartGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Set the background.
    chartGraphics.setColor(backgroundColour);
    chartGraphics.fillRect(0, 0, chartSize.width, chartSize.height);

    // Draw the title.
    drawTitle(chartGraphics);

    // Draw the heatmap images.
    drawHeatMap(chartGraphics, zValues);

    // Draw the axis labels.
    drawXLabel(chartGraphics);
    drawYLabel(chartGraphics);

    // Draw the axis bars.
    drawAxisBars(chartGraphics);

    // Draw axis values.
    drawXValues(chartGraphics);
    drawYValues(chartGraphics);

    return chartImage;
}
 
Example 15
Project: AquamarineLake   File: DrawPanel.java   View Source Code Vote up 5 votes
public BufferedImage matToBufferedImage(Mat mat) {

        if (mat.height() > 0 && mat.width() > 0) {
            BufferedImage image = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_3BYTE_BGR);
            WritableRaster raster = image.getRaster();
            DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();
            byte[] data = dataBuffer.getData();
            mat.get(0, 0, data);
            return image;
        }
        return null;
    }
 
Example 16
Project: rapidminer   File: DynamicIconUrlStreamHandler.java   View Source Code Vote up 4 votes
@Override
protected URLConnection openConnection(final URL u) throws IOException {
	return new URLConnection(u) {

		@Override
		public InputStream getInputStream() throws IOException {
			String[] parameter = u.getFile().substring(1).split("/");
			int width = Integer.parseInt(parameter[0]);
			int height = Integer.parseInt(parameter[1]);
			int percentage = Integer.parseInt(parameter[2]);

			// make sure parameters are valid, otherwise throw
			if (width <= 0) {
				throw new IllegalArgumentException("dynicon width must not be <= 0");
			}
			if (height <= 0) {
				throw new IllegalArgumentException("dynicon height must not be <= 0");
			}
			if (percentage < 0 || percentage > 100) {
				throw new IllegalArgumentException("dynicon percentage must not be < 0 or > 100");
			}
			BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
			Graphics2D g2 = (Graphics2D) img.getGraphics();
			String type = u.getHost();

			// check if we have a registered implementation and use it
			boolean found = false;
			for (String key : mapping.keySet()) {
				if (key.equals(type)) {
					mapping.get(key).drawIcon(g2, width, height, percentage);
					found = true;
					break;
				}
			}

			// unknown dynicon type
			if (!found) {
				throw new IOException("Unknown dynamic icon type: " + type);
			}

			// create image from graphics and return it
			try {
				ByteArrayOutputStream buffer = new ByteArrayOutputStream();
				ImageIO.write(img, "png", buffer);
				buffer.close();
				return new ByteArrayInputStream(buffer.toByteArray());
			} catch (IOException e) {
				LogService.getRoot()
						.log(Level.WARNING, "com.rapidminer.tools.DynamicIconUrlStreamHandler.icon_error", e);
				e.printStackTrace();
				return null;
			}
		}

		@Override
		public void connect() throws IOException {
			// no-op
		}
	};
}
 
Example 17
Project: openjdk-jdk10   File: StreamFlush.java   View Source Code Vote up 4 votes
public static void main(String[] args) throws IOException {
    ImageIO.setUseCache(true);

    // Create a FileImageOutputStream from a FileOutputStream
    File temp1 = File.createTempFile("imageio", ".tmp");
    temp1.deleteOnExit();
    ImageOutputStream fios = ImageIO.createImageOutputStream(temp1);

    // Create a FileCacheImageOutputStream from a BufferedOutputStream
    File temp2 = File.createTempFile("imageio", ".tmp");
    temp2.deleteOnExit();
    FileOutputStream fos2 = new FileOutputStream(temp2);
    BufferedOutputStream bos = new BufferedOutputStream(fos2);
    ImageOutputStream fcios1 = ImageIO.createImageOutputStream(bos);

    // Create a FileCacheImageOutputStream from a ByteArrayOutputStream
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream fcios2 = ImageIO.createImageOutputStream(baos);

    BufferedImage bi =
        new BufferedImage(10, 10, BufferedImage.TYPE_3BYTE_BGR);

    ImageIO.write(bi, "jpg", fios); // No bug, check it anyway
    ImageIO.write(bi, "png", fcios1); // Bug 4414990
    ImageIO.write(bi, "jpg", fcios2); // Bug 4415041

    // It should not be necessary to flush any of the streams
    // If flushing does make a difference, it indicates a bug
    // in the writer or the stream implementation

    // Get length of temp1 before and after flushing
    long file1NoFlushLength = temp1.length();
    fios.flush();
    long file1FlushLength = temp1.length();

    // Get length of temp2 before and after flushing
    long file2NoFlushLength = temp2.length();
    fcios1.flush();
    bos.flush();
    long file2FlushLength = temp2.length();

    byte[] b0 = baos.toByteArray();
    int cacheNoFlushLength = b0.length;
    fcios2.flush();
    byte[] b1 = baos.toByteArray();
    int cacheFlushLength = b1.length;

    if (file1NoFlushLength != file1FlushLength) {
        // throw new RuntimeException
        System.out.println
            ("FileImageOutputStream not flushed!");
    }

    if (file2NoFlushLength != file2FlushLength) {
        // throw new RuntimeException
        System.out.println
         ("FileCacheImageOutputStream/BufferedOutputStream not flushed!");
    }

    if (cacheNoFlushLength != cacheFlushLength) {
        // throw new RuntimeException
        System.out.println
        ("FileCacheImageOutputStream/ByteArrayOutputStream not flushed!");
    }
}
 
Example 18
Project: CGL   File: Texture.java   View Source Code Vote up 4 votes
/**
 * Analyes the specified image and sets the proper openGLImage-values.
 * @return <code>true</code> if the image foramt has successfully detected.
 */
public boolean analyseAndSetOpenGLParameters() {
	boolean retValue = true;
	String errorString = "";

	try {
		switch(image.getType()) {
		case BufferedImage.TYPE_4BYTE_ABGR:
			openGLImageFormat= GL2.GL_RGBA;
			openGLImageType  = GL2.GL_UNSIGNED_INT_8_8_8_8; // OK!
			openGLImageInternalFormat = GL2.GL_RGBA;
			break;

		case BufferedImage.TYPE_3BYTE_BGR:
			openGLImageFormat= GL2.GL_BGR;
			openGLImageType  = GL2.GL_UNSIGNED_BYTE;
			openGLImageInternalFormat = GL2.GL_RGB;
			break;

		case BufferedImage.TYPE_BYTE_GRAY:
			openGLImageFormat= GL2.GL_LUMINANCE;
			openGLImageType  = GL2.GL_UNSIGNED_BYTE;
			openGLImageInternalFormat = GL2.GL_LUMINANCE;
			break;
		case BufferedImage.TYPE_CUSTOM:
			ColorModel colorModel = image.getColorModel();
			ColorSpace colorSpace = colorModel.getColorSpace();
			if(colorSpace.getType()==ColorSpace.TYPE_GRAY) {
				if(colorModel.hasAlpha()==true) {
					openGLImageFormat= GL2.GL_LUMINANCE_ALPHA;
					openGLImageType  = GL2.GL_UNSIGNED_BYTE;
					openGLImageInternalFormat = GL2.GL_LUMINANCE_ALPHA;
				}
				else {
					openGLImageFormat= GL2.GL_LUMINANCE;
					openGLImageType  = GL2.GL_UNSIGNED_BYTE;
					openGLImageInternalFormat = GL2.GL_LUMINANCE;
				}
			}
			else {
				errorString = "Unsupported image format."+
						"\nURL="+textureBaseURL+textureURL+"\n";
				retValue = false;
			}
			break;
		}
	}
	catch(Throwable t) {
		errorString = "Exception during image analyzing."+
				"\nURL="+textureBaseURL+textureURL+"\n"+t.getMessage();
		retValue = false;
	}

	if(!errorString.isEmpty()){
		StatusPrinter.print("ERROR", errorString, Texture.class);
	}
	return retValue;
}
 
Example 19
Project: AquamarineLake   File: DrawPanel.java   View Source Code Vote up 3 votes
public BufferedImage bufferedImage(Mat m) {


        int type = BufferedImage.TYPE_BYTE_GRAY;
        if (m.channels() > 1) {
            type = BufferedImage.TYPE_3BYTE_BGR;
        }
        BufferedImage image = new BufferedImage(m.cols(), m.rows(), type);

        m.get(0, 0, ((DataBufferByte)image.getRaster().getDataBuffer()).getData());
        return image;

    }
 
Example 20
Project: chordatlas   File: SatUtils.java   View Source Code Vote up 2 votes
public static void render( Tweed tweed, LoopL<Point3d> loopL ) {

		double[] range = Loopz.minMax( loopL );
		
		double jump = 30;
		int xMin = -1, xMax = 1, yMin = -1, yMax = 1;
		
		BufferedImage out = new BufferedImage( 640 * ( xMax-xMin+1), 640 * (yMax - yMin + 1), BufferedImage.TYPE_3BYTE_BGR );
		Graphics2D g = out.createGraphics();
		
		int cenX = out.getWidth()/2, cenY = out.getHeight()/2;
		
		int removeBottom = 30;
		
		try {
			
			for (int x = xMin; x <= xMax; x++)
				for (int y = yMax; y >= yMin; y--) 
				{
			
				Point3d cen = new Point3d( 
						( range[ 0 ] + range[ 1 ] ) * 0.5 + x*jump, 
						0, 
						( range[ 4 ] + range[ 5 ] ) * 0.5 + y*jump );

				Point2d ll = worldToLLong( tweed, cen );

				System.out.println( "in EPSG:27700 " + cen );
				System.out.println( "lat long " + ll.x + " " + ll.y );

				URL url = new URL( "https://maps.googleapis.com/maps/api/staticmap?center=" + 
						ll.x + "," + ll.y + 
						"&zoom=20&size=640x640&maptype=satellite&format=png32&key=go_get_your_own" );

				URLConnection connection = url.openConnection();
				InputStream is = connection.getInputStream();

				BufferedImage image = ImageIO.read( is );

				g.drawImage( image, 
						cenX - image.getWidth() /2 - x * 323 + y * 8,
						cenY - image.getHeight()/2 - x * 8   - y * 323, 
						cenX + image.getWidth() /2 - x * 323 + y * 8,
						cenY + image.getHeight()/2 - x * 8   - y * 323 - removeBottom,
						
						0,0,image.getWidth(), image.getHeight() - removeBottom,
						
						 null );
				
				
				
			}

			g.dispose();
			ImageIO.write( out, "png", new File( Tweed.SCRATCH + "ssat.png" ) );
			
		} catch ( Throwable e ) {
			e.printStackTrace();
		}
	}