当前位置: 首页>>代码示例>>Java>>正文


Java BufferedImage.TYPE_3BYTE_BGR属性代码示例

本文整理汇总了Java中java.awt.image.BufferedImage.TYPE_3BYTE_BGR属性的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.TYPE_3BYTE_BGR属性的具体用法?Java BufferedImage.TYPE_3BYTE_BGR怎么用?Java BufferedImage.TYPE_3BYTE_BGR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.awt.image.BufferedImage的用法示例。


在下文中一共展示了BufferedImage.TYPE_3BYTE_BGR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Mat2BufferedImage

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;

}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:18,代码来源:OpenCVFlow.java

示例2: photo

@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();
}
 
开发者ID:erikcostlow,项目名称:PiCameraProject,代码行数:26,代码来源:ImagesEndpoint.java

示例3: main

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++;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:DeviceBounds.java

示例4: prepareImage

@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;
}
 
开发者ID:erikcostlow,项目名称:PiCameraProject,代码行数:25,代码来源:ErikDetectorAlgorithm.java

示例5: getImageTypeName

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";
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:ColConvTest.java

示例6: main

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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:WriteProgressive.java

示例7: toBufferedImage

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;
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:14,代码来源:ImageGui.java

示例8: resizeImage

/**
 * 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;
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:39,代码来源:Resize.java

示例9: createImage

@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);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:7,代码来源:MenuSeparatorPainter.java

示例10: decode

/** 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);
  }
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:46,代码来源:TurboJpeg.java

示例11: getImageTypeName

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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:NoExtraBytesTest.java

示例12: init

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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:Destinations.java

示例13: render

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;
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:36,代码来源:MiniFacade.java

示例14: getChartImage

/**
 * 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;
}
 
开发者ID:schwabdidier,项目名称:GazePlay,代码行数:51,代码来源:HeatChart.java

示例15: matToBufferedImage

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;
    }
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:12,代码来源:DrawPanel.java


注:本文中的java.awt.image.BufferedImage.TYPE_3BYTE_BGR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。