List of usage examples for javax.imageio ImageIO read
public static BufferedImage read(ImageInputStream stream) throws IOException
From source file:net.launchpad.jabref.plugins.ZentralSearch.java
public boolean processQuery(String key, ImportInspector dialog, OutputPrinter status) { try {/*from w w w . j av a2s. c om*/ status.setStatus(Globals.lang("Searching for ") + key); BibtexDatabase bd = importZentralblattEntries(key, status); if (bd == null) { return false; } /* Add the entry to the inspection dialog */ int entryCount = bd.getEntryCount(); if (dialog instanceof ImportInspectionDialog) { ImportInspectionDialog d = (ImportInspectionDialog) dialog; d.setIconImage(ImageIO.read(getIcon())); d.setTitle(Globals.lang("Search results") + " " + Globals.lang("for") + ": " + key + " (" + entryCount + ")"); } status.setStatus("Adding fetched entries: " + entryCount); if (entryCount > 0) { int i = 0; for (BibtexEntry entry : bd.getEntries()) { i++; dialog.setProgress(i, entryCount); dialog.addEntry(entry); } } } catch (Exception e) { status.setStatus(Globals.lang("Error while fetching from Zentralblatt MATH") + ": " + e.getMessage()); log.error(e.getMessage(), e); } return true; }
From source file:task5.deneme.java
private void btn_chooseImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_chooseImageActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser fileChooser = new JFileChooser(userDir + "/Desktop"); int result = fileChooser.showOpenDialog(this); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); try {/*from ww w.j ava2 s . co m*/ img = ImageIO.read(selectedFile); getRGBs(); } catch (IOException ex) { Logger.getLogger(deneme.class.getName()).log(Level.SEVERE, null, ex); } } r = red.toArray(); g = green.toArray(); b = blue.toArray(); // // if(red.indexOf(0)==-1 || red.indexOf(255)==-1){ // red.sort(null); // System.out.println("Before Streching... Min and Max Value..." ); // System.out.println(red.get(0)+" "+red.get(red.size()-1)); // contrastR= red.get(red.size()-1)- red.get(0); // int fmin=red.get(0); // int fmax=red.get(red.size()-1); // for (int i = 0; i < red.size(); i++) { // int temp2=0; // if(((int)r[i])<=fmin) // temp2=0; // else if(fmin<=((int)r[i]) && ((int)r[i])<= fmax){ // double temp=((((int)r[i])- fmin)/(contrastR)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)r[i])>=fmax){ // temp2=255; // } // r[i]=temp2; // } // ArrayList<Integer> tempp = new ArrayList<>(); // for (Object r1 : r) { // tempp.add((int) r1); // } // tempp.sort(null); // System.out.println("After Stretching... Min and Max Value..."); // System.out.println(tempp.get(0) + " " + tempp.get(tempp.size() - 1)); // } // // // // // // if(green.indexOf(0)==-1 || green.indexOf(255)==-1){ // green.sort(null); // contrastG= green.get(green.size()-1)- green.get(0); // int fmin=green.get(0); // int fmax=green.get(green.size()-1); // for (int i = 0; i < green.size(); i++) { // int temp2=0; // if(((int)g[i])<=fmin) // temp2=0; // else if(fmin<=((int)g[i]) && ((int)g[i])<= fmax){ // double temp=((((int)g[i])- fmin)/(contrastG)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)g[i])>=fmax){ // temp2=255; // } // g[i]=temp2; // } // } // if(blue.indexOf(0)==-1 || blue.indexOf(255)==-1){ // blue.sort(null); // contrastB= blue.get(blue.size()-1)- blue.get(0); // int fmin=blue.get(0); // int fmax=blue.get(blue.size()-1); // for (int i = 0; i < blue.size(); i++) { // int temp2=0; // if(((int)b[i])<=fmin) // temp2=0; // else if(fmin<=((int)b[i]) && ((int)b[i])<= fmax){ // double temp=((((int)b[i])- fmin)/(contrastB)); // temp2=(int) Math.round((temp*255)); // } // else if(((int)b[i])>=fmax){ // temp2=255; // } // b[i]=temp2; // } // } display(); }
From source file:nu.yona.server.subscriptions.rest.UserPhotoController.java
private static byte[] getPngBytes(MultipartFile file) { try (InputStream inStream = file.getInputStream()) { BufferedImage image = ImageIO.read(inStream); if (image == null) { throw InvalidDataException.unsupportedPhotoFileType(); }//from w w w . j a v a 2 s . c om ByteArrayOutputStream pngBytes = new ByteArrayOutputStream(); ImageIO.write(image, "png", pngBytes); return pngBytes.toByteArray(); } catch (IOException e) { throw YonaException.unexpected(e); } }
From source file:com.teasoft.teavote.controller.ElectionInfoController.java
@RequestMapping(value = "api/teavote/election-info", method = RequestMethod.POST) @ResponseBody/*from ww w . j a v a 2 s. co m*/ public JSONResponse saveElectionInfo(@RequestParam("logo") MultipartFile file, @RequestParam("commissioner") String commissioner, @RequestParam("orgName") String orgName, @RequestParam("electionDate") String electionDate, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam("pollingStation") String pollingStation, @RequestParam("startTimeInMillis") String startTimeInMillis, @RequestParam("endTimeInMillis") String endTimeInMillis, HttpServletRequest request) throws Exception { JSONResponse jSONResponse = new JSONResponse(); //Candidate candidate = new Candidate(); Map<String, String> errorMessages = new HashMap<>(); if (!file.isEmpty()) { BufferedImage image = ImageIO.read(file.getInputStream()); Integer width = image.getWidth(); Integer height = image.getHeight(); if (Math.abs(width - height) > MAX_IMAGE_DIM_DIFF) { errorMessages.put("image", "Invalid Image Dimension - Max abs(Width - height) must be 50 or less"); } else { //Resize image BufferedImage originalImage = ImageIO.read(file.getInputStream()); int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizeImagePng = resizeImage(originalImage, type); ConfigLocation configLocation = new ConfigLocation(); //String rootPath = request.getSession().getServletContext().getRealPath("/"); File serverFile = new File(configLocation.getConfigPath() + File.separator + "teavote-logo.jpg"); switch (file.getContentType()) { case "image/png": ImageIO.write(resizeImagePng, "png", serverFile); break; case "image/jpeg": ImageIO.write(resizeImagePng, "jpg", serverFile); break; default: ImageIO.write(resizeImagePng, "png", serverFile); break; } } } else { // errorMessages.put("image", "File Empty"); } //Load properties Properties prop = appProp.getProperties(); ConfigLocation configLocation = new ConfigLocation(); prop.load(configLocation.getExternalProperties()); prop.setProperty("teavote.orgName", orgName); prop.setProperty("teavote.commissioner", commissioner); prop.setProperty("teavote.electionDate", electionDate); prop.setProperty("teavote.startTime", startTime); prop.setProperty("teavote.endTime", endTime); prop.setProperty("teavote.pollingStation", pollingStation); prop.setProperty("teavote.startTimeInMillis", startTimeInMillis); prop.setProperty("teavote.endTimeInMillis", endTimeInMillis); File f = new File(configLocation.getConfigPath() + File.separator + "application.properties"); OutputStream out = new FileOutputStream(f); DefaultPropertiesPersister p = new DefaultPropertiesPersister(); p.store(prop, out, "Header Comment"); if (errorMessages.isEmpty()) { return new JSONResponse(true, 0, null, Enums.JSONResponseMessage.SUCCESS.toString()); } return new JSONResponse(false, 0, errorMessages, Enums.JSONResponseMessage.SERVER_ERROR.toString()); }
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 . ja va 2 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:fr.mby.opa.picsimpl.service.BasicPictureService.java
@Override public Picture rotatePicture(final Long pictureId, final Integer angle) throws IOException { Assert.notNull(pictureId, "Picture Id not supplied !"); Assert.notNull(angle, "Rotating angle not supplied !"); Picture rotatedPicture = null;/* w w w . j a v a 2 s . c om*/ final Picture picture = this.pictureDao.loadFullPictureById(pictureId); if (picture != null) { final String filename = picture.getThumbnail().getFilename(); final byte[] contents = picture.getImage().getData(); try (ByteArrayInputStream bais = new ByteArrayInputStream(contents)) { final BufferedImage bufferedImage = ImageIO.read(bais); final BufferedImage rotatedImage = ImageHelper .toBufferedImage(ImageHelper.rotateWithHint(bufferedImage, angle)); final BinaryImage thumbnail = this.pictureFactory.buildThumbnail(rotatedImage, filename, BasicPictureService.THUMBNAIL_MAX_WIDTH, BasicPictureService.THUMBNAIL_MAX_HEIGHT, BasicPictureService.THUMBNAIL_FORMAT); final byte[] rotatedData = ImageHelper.toByteArray(rotatedImage, picture.getFormat()); picture.getImage().setData(rotatedData); picture.setHeight(rotatedImage.getHeight()); picture.setWidth(rotatedImage.getWidth()); picture.setSize(rotatedData.length); final String uniqueHash = this.generateHash(rotatedData); picture.setCurrentHash(uniqueHash); picture.setThumbnail(thumbnail); picture.setThumbnailFormat(thumbnail.getFormat()); picture.setThumbnailHeight(thumbnail.getHeight()); picture.setThumbnailWidth(thumbnail.getWidth()); picture.setThumbnailSize(thumbnail.getData().length); } rotatedPicture = this.pictureDao.updatePicture(picture); } return rotatedPicture; }
From source file:com.sketchy.image.ImageProcessingThread.java
public void run() { status = Status.RENDERING;/*from w w w . ja v a 2 s . c o m*/ try { progress = 5; DrawingSize drawingSize = DrawingSize.parse(renderedImageAttributes.getDrawingSize()); double dotsPerMM = 1 / renderedImageAttributes.getPenWidth(); statusMessage = "Loading Image"; progress = 10; File sourceImage = HttpServer .getUploadFile(ImageAttributes.getImageFilename(renderedImageAttributes.getSourceImageName())); BufferedImage bufferedImage = ImageIO.read(sourceImage); if (cancel) { throw new CancelledException(); } progress = 25; if ((renderedImageAttributes.getBrightness() != 50) || (renderedImageAttributes.getContrast() != 50)) { statusMessage = "Adjusting Contrast/Brightness"; MarvinImage image = new MarvinImage(bufferedImage); MarvinImagePlugin plugin = MarvinPluginLoader .loadImagePlugin("org.marvinproject.image.color.brightnessAndContrast.jar"); if (plugin == null) { throw new Exception("Error loading Marvin Brightness Plugin!"); } // Range is -127 to 127.. convert from 0 - 100 int brightnessValue = (int) (renderedImageAttributes.getBrightness() * 2.54) - 127; int contrastValue = (int) (renderedImageAttributes.getContrast() * 2.54) - 127; plugin.setAttribute("brightness", brightnessValue); plugin.setAttribute("contrast", contrastValue); plugin.process(image, image, null, MarvinImageMask.NULL_MASK, false); image.update(); bufferedImage = image.getBufferedImage(); } if (cancel) { throw new CancelledException(); } progress = 30; if ((renderedImageAttributes.isInvertImage())) { statusMessage = "Inverting Image"; MarvinImage image = new MarvinImage(bufferedImage); MarvinImagePlugin plugin = MarvinPluginLoader .loadImagePlugin("org.marvinproject.image.color.invert.jar"); if (plugin == null) { throw new Exception("Error loading Marvin Invert Image Plugin!"); } plugin.process(image, image, null, MarvinImageMask.NULL_MASK, false); image.update(); bufferedImage = image.getBufferedImage(); } if (cancel) { throw new CancelledException(); } progress = 35; if (renderedImageAttributes.getRotateOption() != RotateOption.ROTATE_NONE) { statusMessage = "Rotating Image"; bufferedImage = rotateImage(bufferedImage, renderedImageAttributes.getRotateOption()); } if (cancel) { throw new CancelledException(); } progress = 40; if (renderedImageAttributes.getFlipOption() != FlipOption.FLIP_NONE) { statusMessage = "Flipping Image"; bufferedImage = flipImage(bufferedImage, renderedImageAttributes.getFlipOption()); } if (cancel) { throw new CancelledException(); } progress = 50; if (renderedImageAttributes.getRenderOption() == RenderOption.RENDER_EDGE_DETECTION) { statusMessage = "Processing Edge Detection"; MarvinImage image = new MarvinImage(bufferedImage); MarvinImagePlugin plugin = MarvinPluginLoader .loadImagePlugin("org.marvinproject.image.edge.edgeDetector.jar"); if (plugin == null) { throw new Exception("Error loading Marvin EdgeDetector Plugin!"); } plugin.process(image, image, null, MarvinImageMask.NULL_MASK, false); image.update(); bufferedImage = image.getBufferedImage(); } int drawingWidth = (int) Math.ceil(drawingSize.getWidth() * dotsPerMM); int drawingHeight = (int) Math.ceil(drawingSize.getHeight() * dotsPerMM); if (cancel) { throw new CancelledException(); } progress = 55; statusMessage = "Scaling Image"; bufferedImage = resizeImage(bufferedImage, drawingWidth, drawingHeight, renderedImageAttributes.getCenterOption(), renderedImageAttributes.getScaleOption()); if (cancel) { throw new CancelledException(); } progress = 60; if (renderedImageAttributes.getRenderOption() == RenderOption.RENDER_HALFTONE) { statusMessage = "Processing Halftone"; MarvinImage image = new MarvinImage(bufferedImage); MarvinImagePlugin plugin = MarvinPluginLoader .loadImagePlugin("org.marvinproject.image.halftone.errorDiffusion.jar"); if (plugin == null) { throw new Exception("Error loading Marvin Halftone Plugin!"); } plugin.process(image, image, null, MarvinImageMask.NULL_MASK, false); image.update(); bufferedImage = image.getBufferedImage(); } if (cancel) { throw new CancelledException(); } progress = 65; if ((renderedImageAttributes.getThreshold() != 50) && (renderedImageAttributes.getRenderOption() != RenderOption.RENDER_HALFTONE)) { statusMessage = "Processing Threshold"; MarvinImage image = new MarvinImage(bufferedImage); MarvinImagePlugin plugin = MarvinPluginLoader .loadImagePlugin("org.marvinproject.image.color.thresholding.jar"); if (plugin == null) { throw new Exception("Error loading Marvin Threshold Plugin!"); } // Range is 0 to 256.. convert from 0 - 100 int thresholdValue = (256 - (int) (renderedImageAttributes.getThreshold() * 2.56)); plugin.setAttribute("threshold", thresholdValue); plugin.process(image, image, null, MarvinImageMask.NULL_MASK, false); image.update(); bufferedImage = image.getBufferedImage(); } if (cancel) { throw new CancelledException(); } statusMessage = "Saving Rendered Image"; File renderedFile = HttpServer.getUploadFile(renderedImageAttributes.getImageFilename()); renderedImageAttributes.setWidth(bufferedImage.getWidth()); renderedImageAttributes.setHeight(bufferedImage.getHeight()); progress = 70; SketchyImage sketchyImage = new SketchyImage(bufferedImage, dotsPerMM, dotsPerMM); if (cancel) { throw new CancelledException(); } progress = 80; SketchyImage.save(sketchyImage, renderedFile); File renderedDataFile = HttpServer.getUploadFile(renderedImageAttributes.getDataFilename()); FileUtils.writeStringToFile(renderedDataFile, renderedImageAttributes.toJson()); progress = 100; status = Status.COMPLETED; statusMessage = "Complete"; } catch (CancelledException e) { status = Status.CANCELLED; statusMessage = "Cancelled!"; } catch (Throwable t) { status = Status.ERROR; statusMessage = "Exception occured while processing Image!! " + t.getMessage(); throw new RuntimeException("Error Running ImageProcessingThread! " + t.toString()); } }
From source file:userInterface.DistrictAdminRole.MonitorNeighborhoodAreasJPanel.java
public void googleMaps() { Neighborhood area = (Neighborhood) areasComboBox.getSelectedItem(); String loc1 = area.getNeighborhoodName(); loc1 = loc1.replace(' ', '+'); String marker1 = loc1;/*from www. j a v a 2 s . c o m*/ BufferedImage image; try { image = ImageIO.read(new URL( "http://maps.googleapis.com/maps/api/staticmap?autoscale=1&size=400x400&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0xff0000%7Clabel:1%7C" + marker1)); mapLabel1.setIcon(new ImageIcon(image)); } catch (IOException ex) { Logger.getLogger(MonitorNeighborhoodAreasJPanel.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:bq.jpa.demo.datetype.service.EmployeeService.java
private byte[] readImage(String fileName) throws IOException { BufferedImage pngfile = ImageIO.read(getClass().getResourceAsStream(fileName)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(pngfile, "png", baos); baos.flush();/* w ww.j a va 2s.c om*/ return baos.toByteArray(); }
From source file:com.akman.excel.view.frmExportExcel.java
public BufferedImage getSignature() { Connection conn = Javaconnect.ConnecrDb(); PreparedStatement pst = null; ResultSet rs = null;// ww w. ja va2 s. com BufferedImage img = null; try { String sql = "SELECT MAX(ID), Image FROM ExcelData"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { byte[] blob = rs.getBytes("Image"); InputStream in = new ByteArrayInputStream(blob); img = ImageIO.read(in); } } catch (SQLException ex) { Logger.getLogger(frmSelectImage.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmExportExcel.class.getName()).log(Level.SEVERE, null, ex); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(pst); DbUtils.closeQuietly(conn); } return img; }