List of usage examples for java.awt.image BufferedImage TYPE_3BYTE_BGR
int TYPE_3BYTE_BGR
To view the source code for java.awt.image BufferedImage TYPE_3BYTE_BGR.
Click Source Link
From source file:org.jboss.arquillian.extension.videoRecorder.impl.VideoRecorder.java
/** * Starts recording a video to the temporary file. If {@link #stopRecording(java.io.File) } * is invoked, this method stops recording. */// ww w . j a v a2s. c o m public void startRecording() { running = true; thread = new Thread(new Runnable() { @Override public void run() { File output; try { output = File.createTempFile("arquillain-screen-recorder", "." + videoType); output.deleteOnExit(); output.createNewFile(); } catch (IOException e) { throw new IllegalStateException("Can't create a temporary file for recording.", e); } IMediaWriter writer = ToolFactory.makeWriter(output.getAbsolutePath()); writer.addVideoStream(0, 0, ICodec.ID.CODEC_ID_MPEG4, screenBounds.width / 2, screenBounds.height / 2); long startTime = System.nanoTime(); while (running) { BufferedImage screen = getDesktopScreenshot(); BufferedImage bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR); writer.encodeVideo(0, bgrScreen, System.nanoTime() - startTime, TimeUnit.NANOSECONDS); try { Thread.sleep((long) (1000 / FRAME_RATE)); } catch (InterruptedException ex) { logger.error("Exception occured during video recording", ex); } if (!running) { writer.close(); try { if (destination != null) { FileUtils.moveFile(output, destination); } } catch (IOException e) { throw new IllegalStateException( "Can't move the temporary recorded content to the destination file.", e); } finally { output.delete(); } } } } }); thread.start(); }
From source file:com.ssn.ui.custom.component.SSNImageThumbnailControl.java
public SSNImageThumbnailControl getSsnImageThumbnailControl(String imagePath, int index) { //this.setLayout(); iF = 0;//from w w w . j a v a2 s . c o m BufferedImage thumbImg1 = null; this.index = index; BufferedImage image; String[] videoSupported = SSNConstants.SSN_VIDEO_FORMAT_SUPPORTED; final List<String> videoSupportedList = Arrays.asList(videoSupported); try { // add code to check file is video or image if video then write code to create thumbnail String fileExtention = imagePath.substring(imagePath.lastIndexOf(".") + 1, imagePath.length()); if (videoSupportedList.contains(fileExtention.toUpperCase())) { IMediaReader reader = null; try { if (true) { reader = ToolFactory.makeReader(imagePath); reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR); reader.addListener(new MediaListenerAdapter() { @Override public void onVideoPicture(IVideoPictureEvent event) { setVideoFrame(event.getImage()); iF++; } }); while (reader.readPacket() == null && iF == 0) ; thumbImg1 = SSNHelper.resizeImage(getVideoFrame(), 50, 50); } } catch (Throwable e) { e.printStackTrace(); } finally { if (reader != null) reader.close(); } } else { image = ImageIO.read(new File(imagePath)); thumbImg1 = SSNHelper.resizeImage(image, 50, 50); } } catch (IOException ex) { Logger.getLogger(SSNImageThumbnailControl.class.getName()).log(Level.SEVERE, null, ex); } ImageIcon imageIcon = new ImageIcon(thumbImg1); JLabel thumbnailLabel = new JLabel(imageIcon, SwingConstants.HORIZONTAL); JLabel closeLabel = new JLabel(new ImageIcon(getClass().getResource("/icon/remove-icon.png")), SwingConstants.HORIZONTAL); closeLabel.setFocusable(true); closeLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); this.add(thumbnailLabel); this.add(closeLabel); closeLabel.addMouseListener(this); this.setFocusable(true); this.setSize(new Dimension(50, 50)); this.setBackground(new Color(0, 0, 0, 1)); return this; }
From source file:ryerson.daspub.utility.FrameGrabber.java
/** * FrameGrabber constructor.//from ww w. j av a 2 s . co m * @param Input Absolute path to input file * @param Output Absolute path to output file */ public FrameGrabber(File Input, File Output) { input = Input; output = Output; // create a media reader for processing video IMediaReader reader = ToolFactory.makeReader(Input.getAbsolutePath()); // stipulate that we want BufferedImages created in BGR 24bit color space reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR); // note that DecodeAndCaptureFrames is derived from // MediaReader.ListenerAdapter and thus may be added as a listener // to the MediaReader. DecodeAndCaptureFrames implements // onVideoPicture(). reader.addListener(this); // read out the contents of the media file, note that nothing else // happens here. action happens in the onVideoPicture() method // which is called when complete video pictures are extracted from // the media source while (reader.readPacket() == null && CAPTURED_FRAMES < MAX_CAPTURED_FRAMES) { do { } while (false); } }
From source file:org.mrgeo.resources.tms.TileMapServiceResource.java
protected static Response createEmptyTile(final ImageResponseWriter writer, final int width, final int height) { // return an empty image final int dataType; if (writer.getResponseMimeType().equals("image/jpeg")) { dataType = BufferedImage.TYPE_3BYTE_BGR; } else {// w ww . j a v a 2 s . com // dataType = BufferedImage.TYPE_INT_ARGB; dataType = BufferedImage.TYPE_4BYTE_ABGR; } final BufferedImage bufImg = new BufferedImage(width, height, dataType); final Graphics2D g = bufImg.createGraphics(); g.setColor(new Color(0, 0, 0, 0)); g.fillRect(0, 0, width, height); g.dispose(); return writer.write(bufImg.getData()).build(); }
From source file:org.pentaho.reporting.engine.classic.core.layout.process.text.RichTextImageProducer.java
public Image createImagePlaceholder(final RenderableReplacedContentBox content) { final long bcw = ProcessUtility.computeBlockContextWidth(content); final long width = ReplacedContentUtil.computeWidth(content); final long height = ReplacedContentUtil.computeHeight(content, bcw, width); final int w = (int) Math.max(1, StrictGeomUtility.toExternalValue(width)); final int h = (int) Math.max(1, StrictGeomUtility.toExternalValue(height)); if (metaData.isFeatureSupported(OutputProcessorFeature.DIRECT_RICHTEXT_RENDERING)) { final Image img = processRenderableReplacedContent(content.getStyleSheet(), width, height, content.getContent().getRawObject()); if (img != null) { return img; }/*from w w w. j a v a 2 s. co m*/ // preserve layout as much as possible. return new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR).getScaledInstance(w, h, Image.SCALE_FAST); } return new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR).getScaledInstance(w, h, Image.SCALE_FAST); }
From source file:com.vaadin.testbench.screenshot.ImageUtil.java
/** * Extract magical image properties used by the getBlock function. * //from w w w . j a v a2s. c o m * @param image * a BufferedImage * @return an ImageProperties descriptor object */ public static final ImageProperties getImageProperties(final BufferedImage image) { final int imageType = image.getType(); ImageProperties p = new ImageProperties(); p.image = image; p.raster = image.getRaster(); p.alpha = imageType == TYPE_INT_ARGB || imageType == BufferedImage.TYPE_4BYTE_ABGR; boolean rgb = imageType == TYPE_INT_ARGB || imageType == TYPE_INT_RGB; boolean bgr = imageType == BufferedImage.TYPE_INT_BGR || imageType == BufferedImage.TYPE_3BYTE_BGR || imageType == BufferedImage.TYPE_4BYTE_ABGR; p.width = image.getWidth(); p.height = image.getHeight(); p.fallback = !(rgb || bgr); return p; }
From source file:org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap.java
private void createImageStream(PDDocument doc, BufferedImage bi) throws IOException { BufferedImage alphaImage = null; BufferedImage rgbImage = null; int width = bi.getWidth(); int height = bi.getHeight(); if (bi.getColorModel().hasAlpha()) { // extract the alpha information WritableRaster alphaRaster = bi.getAlphaRaster(); ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); alphaImage = new BufferedImage(cm, alphaRaster, false, null); // create a RGB image without alpha rgbImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = rgbImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.drawImage(bi, 0, 0, null);/*from w w w .j a v a2s . c o m*/ } else { rgbImage = bi; } java.io.OutputStream os = null; try { int numberOfComponents = rgbImage.getColorModel().getNumComponents(); if (numberOfComponents == 3) { setColorSpace(PDDeviceRGB.INSTANCE); } else { if (numberOfComponents == 1) { setColorSpace(new PDDeviceGray()); } else { throw new IllegalStateException(); } } byte[] outData = new byte[width * height * numberOfComponents]; rgbImage.getData().getDataElements(0, 0, width, height, outData); // add FlateDecode compression getPDStream().addCompression(); os = getCOSStream().createUnfilteredStream(); os.write(outData); COSDictionary dic = getCOSStream(); dic.setItem(COSName.FILTER, COSName.FLATE_DECODE); dic.setItem(COSName.SUBTYPE, COSName.IMAGE); dic.setItem(COSName.TYPE, COSName.XOBJECT); if (alphaImage != null) { PDPixelMap smask = new PDPixelMap(doc, alphaImage); dic.setItem(COSName.SMASK, smask); } setBitsPerComponent(8); setHeight(height); setWidth(width); } finally { os.close(); } }
From source file:core.service.RubricImageCachingService.java
/** * generates image_quantity images for current page the images are resized to image_width * image_height resolution * @param p page to take images for// www . ja v a 2s . c o m * @param dst_dir dir where to save resulting images * @return false if any error occurs */ protected boolean generateImages(Pages p, File dst_dir) { boolean succeed = true; List<Long> ids = pages_service.getAllActiveChildrenId(p.getId()); List<Wallpaper> wallpapers = wallpaper_service.getMainImages(ids, image_quantity); File src_dir = new File(wallpaper_service.getStorePath(), "full"); File src; File dst; BufferedImageHolder holder; BufferedImage rez; for (Wallpaper wallpaper : wallpapers) { src = new File(src_dir, wallpaper.getName()); dst = new File(dst_dir, wallpaper.getName()); if (src.exists()) { try { holder = ImageUtils.readImage(src); rez = new BufferedImage(image_width, image_height, BufferedImage.TYPE_3BYTE_BGR); ImageUtils.getScaledImageDimmension(holder.getImage(), rez); ImageUtils.writeImage(rez, 1, dst); } catch (IOException ex) { logger.error("error while creating image for rubric; ", ex); succeed = false; } } else { logger.error("error while creating image for rubric; " + p.getId() + "; " + p.getName() + "; " + src.getName()); succeed = false; } } return succeed; }
From source file:com.facerecog.rest.service.RecognitionService.java
private Mat convertBytesToImage(byte[] byteImage, int type, int width, int height) { int matType = -1; switch (type) { case BufferedImage.TYPE_3BYTE_BGR: matType = CV_8UC3;/*from w ww . ja va 2 s. co m*/ break; case BufferedImage.TYPE_BYTE_GRAY: matType = CV_8UC1; break; default: throw new IllegalArgumentException("Unrecognized type"); } Mat imageMat = new Mat(height, width, matType); imageMat.ptr().put(byteImage); if (matType != CV_8UC1) { Mat matGray = new Mat(); cvtColor(imageMat, matGray, CV_RGB2GRAY); imageMat = matGray; } return imageMat; }
From source file:common.utils.ImageUtils.java
/** * resize input image to new dinesions(only smaller) and save it to file * @param image input image for scaling * @param scale_factor factor for scaling image * @param rez writes resulting image to a file * @throws IOException/*w w w. j a v a2 s . c o m*/ */ public static void saveScaledImageWidth(BufferedImage image, double scale_factor, OutputStream rez) throws IOException { //long time_resize = System.currentTimeMillis(); if (scale_factor == 1) { writeImage(image, 1, rez); } else { int width = (int) (scale_factor * image.getWidth()); int height = (int) (scale_factor * image.getHeight()); //BufferedImage scaled_bi = new BufferedImage( image.getWidth(), image.getHeight(), image.getType() ); int type = image.getType(); BufferedImage scaled_bi; if (type == BufferedImage.TYPE_CUSTOM) { scaled_bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); } else { scaled_bi = new BufferedImage(width, height, type); } Graphics2D g2 = scaled_bi.createGraphics(); //g2.drawImage(image, at, null); g2.drawImage(image.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null); writeImage(scaled_bi, 1, rez); g2.dispose(); } //time_resize = System.currentTimeMillis() - time_resize; //System.out.print("time_resize=" + (time_resize) + "; "); }