List of usage examples for java.awt.image BufferedImage getSubimage
public BufferedImage getSubimage(int x, int y, int w, int h)
From source file:service.AdService.java
public void create(Boolean isAutherized, Long catId, String email, String phone, String price, MultipartFile previews[], String name, String desc, Long booleanIds[], String booleanVals[], Long stringIds[], String stringVals[], Long numIds[], String snumVals[], Long dateIds[], Date dateVals[], Long selIds[], Long selVals[], Long multyIds[], String multyVals[], Date dateFrom, Date dateTo, Long localIds[]) throws IOException { Boolean newUser = false;/*from w w w. j ava 2 s . c o m*/ if (catId != null) { Category cat = catDao.find(catId); if (cat != null) { if (isAutherized || (!isAutherized && email != null && !email.equals(""))) { PhoneEditor phe = new PhoneEditor(); phone = phe.getPhone(phone); addError(phe.error); if ((phone == null || phone.equals("")) && (email == null || email.equals(""))) { addError( " email ? "); } User user = userService.getUserByMail(email); if (!isAutherized && user == null) { user = userService.registerStandardUser(email); newUser = true; List<String> userErrors = userService.getErrors(); if (!userErrors.isEmpty()) { for (String er : userErrors) { addError("user_service: " + er + "; "); } } } Ad ad = new Ad(); ad.setInsertDate(new Date()); ad.setShowCount((long) 0); ad.setStatus(Ad.NEW); ad.setDateFrom(dateFrom); ad.setDateTo(dateTo); ad.setEmail(email); ad.setPhone(phone); ad.setAuthor(user); ad.setCat(cat); Set<Locality> locals = new HashSet(); /*if (region != null) { if (region.isAllRussia()) { locals.addAll(locDao.getAll()); } else { locals.addAll(region.getLocalities()); } }*/ if (localIds != null && localIds.length > 0) { locals.addAll(locDao.getLocs(localIds)); } else { addError(" ? "); } ad.setLocalities(locals); ad.setName(name); ad.setDescription(desc); ad.setPrice(getNumFromString(price, true)); ad.setValues(new HashSet()); if (validate(ad) && getErrors().isEmpty()) { adDao.save(ad); List<Long> reqParamIds = catDao.getRequiredParamsIds(catId); List<Parametr> catParams = paramDao.getParamsFromCat(catId); int i = 0; ArrayList<String> paramValsErrs = new ArrayList(); // ? ?? ? ? ? ??, ?, ? ? //? ad ArrayList<ParametrValue> list4Save = new ArrayList(); // if (booleanIds != null) { if (booleanVals == null) { booleanVals = new String[booleanIds.length]; } while (i < booleanIds.length) { Parametr p = paramDao.find(booleanIds[i]); if (catParams.contains(p) && Parametr.BOOL == p.getParamType()) { Long val = ParametrValue.NO; String sval = ""; if (booleanVals[i] != null) { val = ParametrValue.YES; sval = ""; } ParametrValue pv = new ParametrValue(); pv.setAd(ad); pv.setParametr(p); pv.setSelectVal(val); pv.setStringVal(sval); if (validate(pv)) { list4Save.add(pv); } } i++; } } if (stringVals != null && stringVals.length > 0) { i = 0; while (i < stringIds.length) { Long paramId = stringIds[i]; Parametr p = paramDao.find(paramId); if (catParams.contains(p) && Parametr.TEXT == p.getParamType()) { String val = stringVals[i]; if (val != null && !val.equals("")) { if (reqParamIds.contains(paramId)) { reqParamIds.remove(paramId); } ParametrValue pv = new ParametrValue(); pv.setAd(ad); pv.setParametr(p); pv.setStringVal(val); if (validate(pv)) { list4Save.add(pv); } } } i++; } } if (snumVals != null && snumVals.length > 0) { i = 0; while (i < numIds.length) { Long paramId = numIds[i]; Parametr p = paramDao.find(paramId); if (catParams.contains(p) && Parametr.NUM == p.getParamType()) { String sval = snumVals[i]; if (sval != null && !sval.equals("")) { Double val = getNumFromString(sval, true); if (reqParamIds.contains(paramId)) { reqParamIds.remove(paramId); } ParametrValue pv = new ParametrValue(); pv.setAd(ad); pv.setParametr(p); pv.setNumVal(val); pv.setStringVal(StringAdapter.getString(val)); if (validate(pv)) { list4Save.add(pv); } } } i++; } if (!getErrors().isEmpty()) { for (String e : getErrors()) { paramValsErrs.add(e); } } } if (dateVals != null && dateVals.length > 0) { i = 0; while (i < dateIds.length) { Long paramId = dateIds[i]; Parametr p = paramDao.find(paramId); if (catParams.contains(p) && Parametr.DATE == p.getParamType()) { Date val = dateVals[i]; if (val != null) { if (reqParamIds.contains(paramId)) { reqParamIds.remove(paramId); } ParametrValue pv = new ParametrValue(); pv.setAd(ad); pv.setParametr(p); pv.setDateVal(val); pv.setStringVal(DateAdapter.formatByDate(val, DateAdapter.SMALL_FORMAT)); if (validate(pv)) { list4Save.add(pv); } } } i++; } } if (selVals != null && selVals.length > 0) { i = 0; while (i < selIds.length) { Long paramId = selIds[i]; Parametr p = paramDao.find(paramId); if (catParams.contains(p) && Parametr.SELECTING == p.getParamType()) { Long val = selVals[i]; if (val != null && !val.equals(0L)) { if (reqParamIds.contains(paramId)) { reqParamIds.remove(paramId); } ParametrValue pv = new ParametrValue(); pv.setAd(ad); pv.setParametr(p); pv.setSelectVal(val); pv.setStringVal(paramSelDao.find(val).getName()); if (validate(pv)) { list4Save.add(pv); } } } i++; } } //? ? //TO DO (??) if (multyVals != null && multyVals.length > 0) { for (String rawVal : multyVals) { String idValArr[] = rawVal.split("_"); if (idValArr.length == 2) { String strId = idValArr[0]; String strVal = idValArr[1]; Long paramId = Long.valueOf(strId); Long val = Long.valueOf(strVal); Parametr p = paramDao.find(paramId); if (catParams.contains(p) && Parametr.MULTISELECTING == p.getParamType()) { if (reqParamIds.contains(paramId) && val != null) { reqParamIds.remove(paramId); } ParametrValue pv = new ParametrValue(); pv.setAd(ad); pv.setParametr(p); pv.setSelectVal(val); pv.setStringVal(paramSelDao.find(val).getName()); if (validate(pv)) { list4Save.add(pv); } } } } } //? ? ? ? if (!reqParamIds.isEmpty() || !paramValsErrs.isEmpty()) { for (Long id : reqParamIds) { addError(" " + paramDao.find(id).getName() + "; "); } //? adDao.delete(ad); } else { for (ParametrValue pv : list4Save) { paramValueDao.save(pv); } File file = new File("/usr/local/seller/preview/" + ad.getId() + "/"); if (file.exists()) { for (File f : file.listFiles()) { f.delete(); } file.delete(); } file.mkdirs(); if (previews != null && previews.length > 0) { i = 0; while (i < 10 && i < previews.length) { MultipartFile prev = previews[i]; if (prev != null && 0L < prev.getSize()) { if (prev.getSize() <= (long) 3 * 1024 * 1024) { File f = new File( "/usr/local/seller/preview/" + ad.getId() + "/supPreview"); if (f.exists()) { f.delete(); } prev.transferTo(f); //to do ? - ?? try { BufferedImage bi = ImageIO.read(f); BigDecimal x = BigDecimal.valueOf(0); BigDecimal y = BigDecimal.valueOf(0); BigDecimal h = BigDecimal.valueOf(bi.getHeight()); BigDecimal w = BigDecimal.valueOf(bi.getWidth()); if (h.compareTo(w) > 0) { y = (h.subtract(w)).divide(BigDecimal.valueOf(2), RoundingMode.HALF_UP); h = w; } else if (h.compareTo(w) < 0) { x = (w.subtract(h)).divide(BigDecimal.valueOf(2), RoundingMode.HALF_UP); w = h; } bi = bi.getSubimage(x.intValue(), y.intValue(), w.intValue(), h.intValue()); f.delete(); f = new File("/usr/local/seller/preview/" + ad.getId() + "/" + i); ImageIO.write(bi, "png", f); } catch (Exception e) { addError( "? ? " + prev.getName() + /*"; s="+prev.getSize()+"; t="+prev.getContentType()+"; l="+previews.length+*/ "; " + StringAdapter.getStackTraceException(e)); } } else { addError(" " + prev.getName() + " , ? 3 ."); } } i++; } } if (newUser) { userService.notifyAboutRegistration(email); } } } /* else { addError("user:" + user.getId() + " " + user.getName()); }*/ } else { addError( "? ?? email"); } } else { addError("? ? " + catId + " ."); } } else { addError("? "); } }
From source file:org.geowebcache.service.wms.WMSTileFuser.java
protected void renderCanvas() throws OutsideCoverageException, GeoWebCacheException, IOException, Exception { // Now we loop over all the relevant tiles and write them to the canvas, // Starting at the bottom, moving to the right and up // Bottom row of tiles, in tile coordinates long starty = srcRectangle[1]; // gridy is the tile row index for (long gridy = starty; gridy <= srcRectangle[3]; gridy++) { int tiley = 0; int canvasy = (int) (srcRectangle[3] - gridy) * gridSubset.getTileHeight(); int tileHeight = gridSubset.getTileHeight(); if (canvOfs.top > 0) { // Add padding canvasy += canvOfs.top;/* ww w . j a va 2 s . c om*/ } else { // Top tile is cut off if (gridy == srcRectangle[3]) { // This one starts at the top, so canvasy remains 0 tileHeight = tileHeight + canvOfs.top; tiley = -canvOfs.top; } else { // Offset that the first tile contributed, // rather, we subtract what it did not contribute canvasy += canvOfs.top; } } if (gridy == srcRectangle[1] && canvOfs.bottom < 0) { // Check whether we only use part of the first tiles (bottom row) // Offset is negative, slice the bottom off the tile tileHeight += canvOfs.bottom; } long startx = srcRectangle[0]; for (long gridx = startx; gridx <= srcRectangle[2]; gridx++) { long[] gridLoc = { gridx, gridy, srcIdx }; ConveyorTile tile = new ConveyorTile(sb, layer.getName(), gridSubset.getName(), gridLoc, srcFormat, fullParameters, null, null); // Check whether this tile is to be rendered at all try { layer.applyRequestFilters(tile); } catch (RequestFilterException e) { log.debug(e.getMessage(), e); continue; } layer.getTile(tile); // Selection of the resource input stream Resource blob = tile.getBlob(); // Extraction of the image associated with the defined MimeType String formatName = srcFormat.getMimeType(); BufferedImage tileImg = decoderMap.decode(formatName, blob, decoderMap.isAggressiveInputStreamSupported(formatName), null); int tilex = 0; int canvasx = (int) (gridx - startx) * gridSubset.getTileWidth(); int tileWidth = gridSubset.getTileWidth(); if (canvOfs.left > 0) { // Add padding canvasx += canvOfs.left; } else { // Leftmost tile is cut off if (gridx == srcRectangle[0]) { // This one starts to the left top, so canvasx remains 0 tileWidth = tileWidth + canvOfs.left; tilex = -canvOfs.left; } else { // Offset that the first tile contributed, // rather, we subtract what it did not contribute canvasx += canvOfs.left; } } if (gridx == srcRectangle[2] && canvOfs.right < 0) { // Check whether we only use part of the first tiles (bottom row) // Offset is negative, slice the bottom off the tile tileWidth = tileWidth + canvOfs.right; } // TODO We should really ensure we can never get here if (tileWidth == 0 || tileHeight == 0) { log.debug("tileWidth: " + tileWidth + " tileHeight: " + tileHeight); continue; } // Cut down the tile to the part we want if (tileWidth != gridSubset.getTileWidth() || tileHeight != gridSubset.getTileHeight()) { log.debug("tileImg.getSubimage(" + tilex + "," + tiley + "," + tileWidth + "," + tileHeight + ")"); tileImg = tileImg.getSubimage(tilex, tiley, tileWidth, tileHeight); } // Render the tile on the big canvas log.debug("drawImage(subtile," + canvasx + "," + canvasy + ",null) " + Arrays.toString(gridLoc)); gfx.drawImage(tileImg, canvasx, canvasy, null); // imageObserver } } gfx.dispose(); }
From source file:Controller.ProviderController.java
@RequestMapping(value = "/UploadImage", method = RequestMethod.POST) public @ResponseBody String uploadProviderImage(@RequestParam("providerImage") MultipartFile providerImage, @RequestParam("providerID") int providerID, HttpSession session) { try {//from w w w. ja v a2s . c o m String path = System.getProperty("catalina.base"); File folderPackage = new File(path + "/webapps/Images/Provider/" + providerID); if (!folderPackage.exists()) { folderPackage.mkdirs(); } String extension = FilenameUtils.getExtension(providerImage.getOriginalFilename()); String name = "provider." + extension; String name2 = "avatar." + extension; // get Bytes and crop byte[] imageInByte = providerImage.getBytes(); InputStream in = new ByteArrayInputStream(imageInByte); BufferedImage bImageFromConvert = ImageIO.read(in); // create a cropped image from the original image BufferedImage croppedImage = bImageFromConvert.getSubimage(0, 0, 100, 100); // // then convert BufferedImage to byte array to save // ByteArrayOutputStream baos = new ByteArrayOutputStream(); // ImageIO.write(croppedImage, extension, baos); // baos.flush(); // imageInByte = baos.toByteArray(); // baos.close(); ImageIO.write(croppedImage, extension, new File(folderPackage, name2)); FileCopyUtils.copy(providerImage.getBytes(), new FileOutputStream(new File(folderPackage, name))); String image = "Images/Provider/" + providerID + "/" + name; AccountSession account = (AccountSession) session.getAttribute("account"); account.setImage(image); session.setAttribute("account", account); providerService.updateProviderImage(providerID, image); return image; } catch (Exception e) { String content = "Function: ProviderController - uploadProviderImage\n" + "***Input***\n" + "providerID: " + providerID + "\n" + "**********\n" + "****Error****\n" + e.getMessage() + "\n" + "**********"; errorService.logBugWithAccount(content, session, e); return "{\"result\": \"error\"}"; } }
From source file:com.htmlhifive.pitalium.core.selenium.PtlWebDriver.java
/** * ??????????????????//w ww . j ava2 s . c o m * * @param captureTop ??? * @param captureLeft ??? * @param windowHeight viewport??? * @param windowWidth viewport?? * @param currentScale ?? * @param img ? * @return ????? */ protected BufferedImage trimOverlap(double captureTop, double captureLeft, long windowHeight, long windowWidth, double currentScale, BufferedImage img) { LOG.trace("(TrimOverlap) image[w: {}, h:{}], top: {}, left: {}, windowWidth: {}, windowHeight: {}", img.getWidth(), img.getHeight(), captureTop, captureLeft, windowWidth, windowHeight); BufferedImage image = img; // ?????????????????? long calculatedRightValue = Math.round((captureLeft + windowWidth) * currentScale); long actualRightValue = Math.round(captureLeft * currentScale) + img.getWidth(); int trimWidth = calculatedRightValue < actualRightValue ? (int) (actualRightValue - calculatedRightValue) : 0; // ???????????????? long calculatedBottomValue = Math.round((captureTop + windowHeight) * currentScale); long actualBottomValue = Math.round(captureTop * currentScale) + img.getHeight(); int trimHeight = calculatedBottomValue < actualBottomValue ? (int) (actualBottomValue - calculatedBottomValue) : 0; // ????????????? LOG.trace("(TrimOverlap) right(calc: {}, actual: {}), bottom(calc: {}, actual: {})", calculatedRightValue, actualRightValue, calculatedBottomValue, actualBottomValue); if (trimWidth > 0 || trimHeight > 0) { image = image.getSubimage(0, 0, image.getWidth() - trimWidth, image.getHeight() - trimHeight); } return image; }
From source file:DefaultGraphics2D.java
/** * Draws as much of the specified area of the specified image as is currently * available, scaling it on the fly to fit inside the specified area of the * destination drawable surface. Transparent pixels do not affect whatever * pixels are already there./* w w w .j av a 2s . co m*/ * <p> * This method returns immediately in all cases, even if the image area to be * drawn has not yet been scaled, dithered, and converted for the current * output device. If the current output representation is not yet complete * then <code>drawImage</code> returns <code>false</code>. As more of the * image becomes available, the process that draws the image notifies the * specified image observer. * <p> * This method always uses the unscaled version of the image to render the * scaled rectangle and performs the required scaling on the fly. It does not * use a cached, scaled version of the image for this operation. Scaling of * the image from source to destination is performed such that the first * coordinate of the source rectangle is mapped to the first coordinate of the * destination rectangle, and the second source coordinate is mapped to the * second destination coordinate. The subimage is scaled and flipped as needed * to preserve those mappings. * * @param img * the specified image to be drawn * @param dx1 * the <i>x</i> coordinate of the first corner of the destination * rectangle. * @param dy1 * the <i>y</i> coordinate of the first corner of the destination * rectangle. * @param dx2 * the <i>x</i> coordinate of the second corner of the destination * rectangle. * @param dy2 * the <i>y</i> coordinate of the second corner of the destination * rectangle. * @param sx1 * the <i>x</i> coordinate of the first corner of the source * rectangle. * @param sy1 * the <i>y</i> coordinate of the first corner of the source * rectangle. * @param sx2 * the <i>x</i> coordinate of the second corner of the source * rectangle. * @param sy2 * the <i>y</i> coordinate of the second corner of the source * rectangle. * @param observer * object to be notified as more of the image is scaled and * converted. * @see java.awt.Image * @see java.awt.image.ImageObserver * @see java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, * int, int, int) * @since JDK1.1 */ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { BufferedImage src = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = src.createGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); src = src.getSubimage(sx1, sy1, sx2 - sx1, sy2 - sy1); return drawImage(src, dx1, dy1, dx2 - dx1, dy2 - dy1, observer); }
From source file:org.iish.visualmets.services.ImageTransformation.java
public BufferedImage CropImage(BufferedImage img, String crop) { BufferedImage clipped = null; boolean coordinates_okay = false; if (!crop.trim().equals("")) { coordinates_okay = true;/*from w ww . java 2s.c o m*/ int[] coordinates = { 0, 0, img.getWidth(), img.getHeight() }; // split crop value in parts String[] crop_coordinates = crop.split(","); // if still okay, check if each part is a integer if (coordinates_okay) { for (int i = 0; i < crop_coordinates.length && i < 4; i++) { if (!crop_coordinates[i].trim().equals("")) { if (!Pattern.matches("^-?\\d*$", crop_coordinates[i].trim())) { coordinates_okay = false; } else { coordinates[i] = parseInt(crop_coordinates[i].trim()); } } } } // als coordinaten negatief, dan vanuit gaan dat het van de 'andere' kant is if (coordinates_okay) { if (coordinates[0] < 0) { coordinates[0] = img.getWidth() + coordinates[0]; } if (coordinates[1] < 0) { coordinates[1] = img.getHeight() + coordinates[1]; } if (coordinates[2] < 0) { coordinates[2] = img.getWidth() + coordinates[2]; } if (coordinates[3] < 0) { coordinates[3] = img.getHeight() + coordinates[3]; } } // alle coordinaten moeten op dit moment positieve getallen binnen de image grootte/breedte zijn if (coordinates_okay) { if (coordinates[0] > img.getWidth() || coordinates[0] < 0) { coordinates_okay = false; } if (coordinates[1] > img.getHeight() || coordinates[1] < 0) { coordinates_okay = false; } if (coordinates[2] > img.getWidth() || coordinates[2] < 0) { coordinates_okay = false; } if (coordinates[3] > img.getHeight() || coordinates[3] < 0) { coordinates_okay = false; } } // controleer of de linker/boven waarde kleiner is dan de rechter/onder coordinaat if (coordinates_okay) { if (coordinates[0] >= coordinates[2]) { coordinates_okay = false; } if (coordinates[1] >= coordinates[3]) { coordinates_okay = false; } } if (coordinates_okay) { // if still okay, then get cropped image try { int w = coordinates[2] - coordinates[0]; int h = coordinates[3] - coordinates[1]; clipped = img.getSubimage(coordinates[0], coordinates[1], w, h); } catch (RasterFormatException rfe) { System.out.println("raster format error: " + rfe.getMessage()); coordinates_okay = false; } } } if (!coordinates_okay) { clipped = img; } return clipped; }
From source file:forge.toolbox.FSkin.java
private static void setImage(final FSkinProp s0, final BufferedImage bim) { tempCoords = s0.getCoords();//from www .ja v a 2 s . com x0 = tempCoords[0]; y0 = tempCoords[1]; w0 = tempCoords[2]; h0 = tempCoords[3]; SkinImage.setImage(s0, bim.getSubimage(x0, y0, w0, h0)); }
From source file:forge.toolbox.FSkin.java
/** * Loads a "light" version of FSkin, just enough for the splash screen: * skin name. Generates custom skin settings, fonts, and backgrounds. * * * @param skinName//from ww w. j a va2 s .c om * the skin name */ public static void loadLight(final String skinName, final boolean onInit) { if (onInit) { // No need for this method to be loaded while on the EDT. FThreads.assertExecutedByEdt(false); if (allSkins == null) { //initialize allSkins = new ArrayList<>(); final List<String> skinDirectoryNames = getSkinDirectoryNames(); for (String skinDirectoryName : skinDirectoryNames) { allSkins.add(WordUtils.capitalize(skinDirectoryName.replace('_', ' '))); } Collections.sort(allSkins); } } currentSkinIndex = allSkins.indexOf(skinName); // Non-default (preferred) skin name and dir. preferredName = skinName.toLowerCase().replace(' ', '_'); preferredDir = ForgeConstants.SKINS_DIR + preferredName + "/"; if (onInit) { final File f = new File(preferredDir + ForgeConstants.SPLASH_BG_FILE); if (!f.exists()) { if (skinName.equals("default")) { throw new RuntimeException( String.format("Cannot find default skin at %s", f.getAbsolutePath())); } loadLight("default", true); return; } final BufferedImage img; try { img = ImageIO.read(f); final int h = img.getHeight(); final int w = img.getWidth(); SkinIcon.setIcon(FSkinProp.BG_SPLASH, img.getSubimage(0, 0, w, h - 100)); UIManager.put("ProgressBar.background", getColorFromPixel(img.getRGB(25, h - 75))); UIManager.put("ProgressBar.selectionBackground", getColorFromPixel(img.getRGB(75, h - 75))); UIManager.put("ProgressBar.foreground", getColorFromPixel(img.getRGB(25, h - 25))); UIManager.put("ProgressBar.selectionForeground", getColorFromPixel(img.getRGB(75, h - 25))); UIManager.put("ProgressBar.border", new LineBorder(Color.BLACK, 0)); } catch (final IOException e) { e.printStackTrace(); } loaded = true; } }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public String cropAndSaveProviderImage(String data, int providerID, FileMeta imageMeta) throws IOException { JsonObject jsonObject = gson.fromJson(data, JsonObject.class); // get data from json int positionX = jsonObject.get("positionX").getAsInt(); int positionY = jsonObject.get("positionY").getAsInt(); int imageWidth = jsonObject.get("width").getAsInt(); int imageHeight = jsonObject.get("height").getAsInt(); int cropWidth = jsonObject.get("cropWidth").getAsInt(); int cropHeight = jsonObject.get("cropHeight").getAsInt(); // transform crop into current crop byte[] imageInByte = imageMeta.getBytes(); InputStream in = new ByteArrayInputStream(imageInByte); BufferedImage bImageFromConvert = ImageIO.read(in); int currentImageWidth = bImageFromConvert.getWidth(); int currentImageHeight = bImageFromConvert.getHeight(); int newPositionX = currentImageWidth * positionX / imageWidth; int newPositionY = currentImageHeight * positionY / imageHeight; int widthRatio = currentImageWidth * cropWidth / imageWidth; int heightRatio = currentImageHeight * cropHeight / imageHeight; // then crop//from w w w .ja v a 2 s. c o m BufferedImage croppedImage = bImageFromConvert.getSubimage(newPositionX, newPositionY, widthRatio, heightRatio); // get name to save String extension = FilenameUtils.getExtension(imageMeta.getFileName()); String name = "provider." + extension; String path = System.getProperty("catalina.base"); File folderPackage = new File(path + "/webapps/Images/Provider/" + providerID); if (!folderPackage.exists()) { folderPackage.mkdirs(); } ImageIO.write(croppedImage, extension, new File(folderPackage, name)); String image = "Images/Provider/" + providerID + "/" + name; providerDAO.updateProviderImage(providerID, image); return image; }
From source file:com.htmlhifive.pitalium.core.selenium.PtlWebDriver.java
/** * ????????????????//from ww w . j a va 2 s.co m * * @param image ? * @param params * @return ??? */ private BufferedImage cropScreenshotImage(BufferedImage image, ScreenshotParams params) { RectangleArea targetArea = params.getTarget().getArea(); RectangleArea floorTargetArea = targetArea.round(); LOG.debug("[CropScreenshot] image[w: {}, h: {}], target: {} ({})", image.getWidth(), image.getHeight(), floorTargetArea, targetArea); // Don't crop image when the target element is "body" if (params.getTarget().isBody()) { int width = image.getWidth(); if (width < floorTargetArea.getX() + floorTargetArea.getWidth()) { width -= (int) floorTargetArea.getX(); } else { width = (int) floorTargetArea.getWidth(); } int height = image.getHeight(); if (height < floorTargetArea.getY() + floorTargetArea.getHeight()) { height -= (int) floorTargetArea.getY(); } else { height = (int) floorTargetArea.getHeight(); } params.getTarget() .setArea(new RectangleArea(floorTargetArea.getX(), floorTargetArea.getY(), width, height)); LOG.trace("[CropScreenshot] Did not crop image (element is body). Image area: {}", params.getTarget().getArea()); return image; } // (width + x) ? (height + y) ???????? int maxCropWidth = (int) Math.min(floorTargetArea.getX() + floorTargetArea.getWidth(), image.getWidth()); int maxCropHeight = (int) Math.min(floorTargetArea.getY() + floorTargetArea.getHeight(), image.getHeight()); LOG.trace("[CropScreenshot] ({})", new RectangleArea((int) floorTargetArea.getX(), (int) floorTargetArea.getY(), maxCropWidth - (int) floorTargetArea.getX(), maxCropHeight - (int) floorTargetArea.getY())); BufferedImage targetImage = image.getSubimage((int) floorTargetArea.getX(), (int) floorTargetArea.getY(), maxCropWidth - (int) floorTargetArea.getX(), maxCropHeight - (int) floorTargetArea.getY()); double deltaX = -floorTargetArea.getX(); double deltaY = -floorTargetArea.getY(); params.getTarget().setArea(new RectangleArea(0d, 0d, targetImage.getWidth(), targetImage.getHeight())); LOG.trace("[CropScreenshot] new area: {}", params.getTarget().getArea()); LOG.trace("[CropScreenshot] Move excludes. (deltaX: {}, deltaY: {})", deltaX, deltaY); for (ScreenAreaWrapper wrapper : params.getExcludes()) { wrapper.setArea(wrapper.getArea().move(deltaX, deltaY)); } return targetImage; }