List of usage examples for java.awt Graphics2D drawImage
public abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer);
From source file:net.geoprism.dashboard.DashboardMap.java
/** * Builds an image layer of all the layers in a SavedMap. * /*w w w . j av a 2s. com*/ * @mapWidth * @mapHeight */ private BufferedImage getLegendExportCanvas(int mapWidth, int mapHeight) { int padding = 2; BufferedImage base = null; Graphics mapBaseGraphic = null; Color innerBackgroundColor = Color.darkGray; Color outerBorderColor = Color.black; int legendTopPlacement = 0; int legendLeftPlacement = 0; int widestLegend = 0; int legendXPosition = 0; int legendYPosition = 0; List<? extends DashboardLayer> layers = this.getAllHasLayer().getAll(); try { base = new BufferedImage(mapWidth, mapHeight, BufferedImage.TYPE_INT_ARGB); mapBaseGraphic = base.getGraphics(); mapBaseGraphic.drawImage(base, 0, 0, null); // Generates map overlays and combines them into a single map image for (DashboardLayer layer : layers) { if (layer.getDisplayInLegend()) { Graphics2D titleBaseGraphic = null; Graphics2D iconGraphic = null; String requestURL = getLegendURL(layer); try { // handle color graphics and categories BufferedImage titleBase = getLegendTitleImage(layer); titleBaseGraphic = titleBase.createGraphics(); int paddedTitleWidth = titleBase.getWidth(); int paddedTitleHeight = titleBase.getHeight(); BufferedImage icon = getImageFromGeoserver(requestURL); int iconHeight = icon.getHeight(); int iconWidth = icon.getWidth(); int paddedIconWidth = iconWidth + (padding * 2); int paddedIconHeight = iconHeight + (padding * 2); int fullWidth = paddedIconWidth + paddedTitleWidth; int fullHeight; if (paddedIconHeight >= paddedTitleHeight) { fullHeight = paddedIconHeight; } else { fullHeight = paddedTitleHeight; } DashboardLegend legend = layer.getDashboardLegend(); if (legend.getGroupedInLegend()) { if (legendTopPlacement + fullHeight >= mapHeight) { legendLeftPlacement = widestLegend + legendLeftPlacement + padding; legendTopPlacement = 0; // reset so 2nd column legends start at the top row } legendXPosition = legendLeftPlacement + padding; legendYPosition = legendTopPlacement + padding; } else { legendXPosition = (int) Math.round((double) legend.getLegendXPosition()); legendYPosition = (int) Math.round((double) legend.getLegendYPosition()); } BufferedImage legendBase = new BufferedImage(fullWidth + (padding * 2), fullHeight + (padding * 2), BufferedImage.TYPE_INT_ARGB); Graphics2D legendBaseGraphic = legendBase.createGraphics(); legendBaseGraphic.setColor(innerBackgroundColor); legendBaseGraphic.fillRect(0, 0, fullWidth, fullHeight); legendBaseGraphic.setColor(outerBorderColor); legendBaseGraphic.setStroke(new BasicStroke(5)); legendBaseGraphic.drawRect(0, 0, fullWidth, fullHeight); legendBaseGraphic.drawImage(icon, padding, padding, paddedIconWidth, paddedIconHeight, null); legendBaseGraphic.drawImage(titleBase, paddedIconWidth + (padding * 2), (fullHeight / 2) - (paddedTitleHeight / 2), paddedTitleWidth, paddedTitleHeight, null); mapBaseGraphic.drawImage(legendBase, legendXPosition, legendYPosition, fullWidth, fullHeight, null); if (legend.getGroupedInLegend()) { legendTopPlacement = legendTopPlacement + fullHeight + padding; } if (fullWidth > widestLegend) { widestLegend = fullWidth; } } finally { if (titleBaseGraphic != null) { titleBaseGraphic.dispose(); } if (iconGraphic != null) { iconGraphic.dispose(); } } } } } finally { mapBaseGraphic.dispose(); } return base; }
From source file:lucee.runtime.img.Image.java
public void resizeImage(int width, int height, int interpolation) throws ExpressionException { Object ip;/*from w w w .j a v a 2s . com*/ if (interpolation == IPC_NEAREST) ip = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR; else if (interpolation == IPC_BICUBIC) ip = RenderingHints.VALUE_INTERPOLATION_BICUBIC; else if (interpolation == IPC_BILINEAR) ip = RenderingHints.VALUE_INTERPOLATION_BILINEAR; else throw new ExpressionException("invalid interpoltion definition"); BufferedImage dst = new BufferedImage(width, height, image().getType()); Graphics2D graphics = dst.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, ip); graphics.drawImage(image(), 0, 0, width, height, null); graphics.dispose(); image(dst); }
From source file:lucee.runtime.img.Image.java
/** * Convenience method that returns a scaled instance of the * provided {@code BufferedImage}./*from w w w. java2 s. c o m*/ * * @param img the original image to be scaled * @param targetWidth the desired width of the scaled instance, * in pixels * @param targetHeight the desired height of the scaled instance, * in pixels * @param hint one of the rendering hints that corresponds to * {@code RenderingHints.KEY_INTERPOLATION} (e.g. * {@code RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR}, * {@code RenderingHints.VALUE_INTERPOLATION_BILINEAR}, * {@code RenderingHints.VALUE_INTERPOLATION_BICUBIC}) * @param higherQuality if true, this method will use a multi-step * scaling technique that provides higher quality than the usual * one-step technique (only useful in downscaling cases, where * {@code targetWidth} or {@code targetHeight} is * smaller than the original dimensions, and generally only when * the {@code BILINEAR} hint is specified) * @return a scaled version of the original {@code BufferedImage} */ private BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight, Object hint, boolean higherQuality) { // functionality not supported in java 1.4 int transparency = Transparency.OPAQUE; try { transparency = img.getTransparency(); } catch (Throwable t) { } int type = (transparency == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage ret = img; int w, h; if (higherQuality) { // Use multi-step technique: start with original size, then // scale down in multiple passes with drawImage() // until the target size is reached w = img.getWidth(); h = img.getHeight(); } else { // Use one-step technique: scale directly from original // size to target size with a single drawImage() call w = targetWidth; h = targetHeight; } do { if (higherQuality && w > targetWidth) { w /= 2; if (w < targetWidth) { w = targetWidth; } } if (higherQuality && h > targetHeight) { h /= 2; if (h < targetHeight) { h = targetHeight; } } BufferedImage tmp = new BufferedImage(w, h, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); g2.drawImage(ret, 0, 0, w, h, null); g2.dispose(); ret = tmp; } while (w != targetWidth || h != targetHeight); return ret; }
From source file:wsserver.EKF1TimerSessionBean.java
private static BufferedImage resizeImage(BufferedImage originalImage, int type) { BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null); g.dispose();//from w ww . j a v a 2 s . c o m return resizedImage; }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw the TV and HD logos onto the image * * @param movie The source movie/*from www. ja v a 2 s . c om*/ * @param bi The image to draw on * @param imageType * @param beforeMainOverlay * @return The new image with the added logos */ @SuppressWarnings("deprecation") protected BufferedImage drawLogos(Movie movie, BufferedImage bi, String imageType, boolean beforeMainOverlay) { BufferedImage newBi = bi; // Issue 1937: Overlay configuration XML if (xmlOverlay) { for (LogoOverlay layer : overlayLayers) { if (layer.isBefore() != beforeMainOverlay) { continue; } boolean flag = false; List<StateOverlay> states = new ArrayList<>(); for (String name : layer.getNames()) { String value = Movie.UNKNOWN; if (checkLogoEnabled(name)) { if ("set".equalsIgnoreCase(name)) { value = ((THUMBNAIL.equalsIgnoreCase(imageType) || BANNER.equalsIgnoreCase(imageType) || FOOTER.equalsIgnoreCase(imageType)) && movie.isSetMaster()) ? countSetLogo ? Integer.toString(movie.getSetSize()) : TRUE : countSetLogo ? "0" : FALSE; } else if ("TV".equalsIgnoreCase(name)) { value = movie.isTVShow() ? TRUE : FALSE; } else if ("HD".equalsIgnoreCase(name)) { value = movie.isHD() ? highdefDiff ? movie.isHD1080() ? "hd1080" : "hd720" : "hd" : FALSE; } else if (SUBTITLE.equalsIgnoreCase(name) || "ST".equalsIgnoreCase(name)) { value = (StringTools.isNotValidString(movie.getSubtitles()) || "NO".equalsIgnoreCase(movie.getSubtitles())) ? FALSE : (blockSubTitle ? movie.getSubtitles() : TRUE); } else if (LANGUAGE.equalsIgnoreCase(name)) { value = movie.getLanguage(); } else if (RATING.equalsIgnoreCase(name)) { value = ((!movie.isTVShow() && !movie.isSetMaster()) || (movie.isTVShow() && movie.isSetMaster())) ? Integer.toString(realRating ? movie.getRating() : (int) (Math.floor(movie.getRating() / 10) * 10)) : Movie.UNKNOWN; } else if (VIDEOSOURCE.equalsIgnoreCase(name) || SOURCE.equalsIgnoreCase(name) || "VS".equalsIgnoreCase(name)) { value = movie.getVideoSource(); } else if ("videoout".equalsIgnoreCase(name) || "out".equalsIgnoreCase(name) || "VO".equalsIgnoreCase(name)) { value = movie.getVideoOutput(); } else if (VIDEOCODEC.equalsIgnoreCase(name) || VCODEC.equalsIgnoreCase(name) || "VC".equalsIgnoreCase(name)) { value = movie.getVideoCodec(); } else if (AUDIOCODEC.equalsIgnoreCase(name) || ACODEC.equalsIgnoreCase(name) || "AC".equalsIgnoreCase(name)) { value = movie.getAudioCodec(); if (!blockAudioCodec) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } pos = value.indexOf(" ("); if (pos > -1) { value = value.substring(0, pos); } } else { while (value.contains(" (") && value.indexOf(" (") < value.indexOf(')')) { value = value.substring(0, value.indexOf(" (")) + value.substring(value.indexOf(')') + 1); } } } else if (AUDIOLANG.equalsIgnoreCase(name) || ALANG.equalsIgnoreCase(name) || "AL".equalsIgnoreCase(name)) { value = ""; for (String tmp : movie.getAudioCodec().split(Movie.SPACE_SLASH_SPACE)) { if (tmp.contains(" (") && tmp.indexOf(" (") < tmp.indexOf(')')) { tmp = tmp.substring(tmp.indexOf(" (") + 2, tmp.indexOf(')')); } else { tmp = Movie.UNKNOWN; } if (!blockAudioLang) { value = tmp; break; } if (StringUtils.isNotBlank(value)) { value += Movie.SPACE_SLASH_SPACE; } value += tmp; } if (StringTools.isNotValidString(value)) { value = Movie.UNKNOWN; } } else if (name.equalsIgnoreCase(AUDIOCHANNELS) || name.equalsIgnoreCase(CHANNELS)) { value = movie.getAudioChannels(); if (!blockAudioChannels) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } } } else if (CONTAINER.equalsIgnoreCase(name)) { value = movie.getContainer(); } else if (ASPECT.equalsIgnoreCase(name)) { value = movie.getAspectRatio(); } else if ("fps".equalsIgnoreCase(name)) { value = Float.toString(movie.getFps()); } else if (CERTIFICATION.equalsIgnoreCase(name)) { value = movie.getCertification(); } else if (WATCHED.equalsIgnoreCase(name)) { if (imageType.equalsIgnoreCase(VIDEOIMAGE)) { value = movie.getFiles().toArray(new MovieFile[movie.getFiles().size()])[viIndex] .isWatched() ? TRUE : FALSE; } else if (movie.isTVShow() && blockWatched) { StringBuilder sbWatched = new StringBuilder(); boolean first = true; for (MovieFile mf : movie.getFiles()) { if (first) { first = false; } else { sbWatched.append(Movie.SPACE_SLASH_SPACE); } sbWatched.append(mf.isWatched() ? TRUE : FALSE); } value = sbWatched.toString(); } else { value = movie.isWatched() ? TRUE : FALSE; } } else if (EPISODE.equalsIgnoreCase(name)) { if (movie.isTVShow()) { if (blockEpisode) { StringBuilder sbEpisode = new StringBuilder(); boolean first = true; int firstPart, lastPart; for (MovieFile mf : movie.getFiles()) { firstPart = mf.getFirstPart(); lastPart = mf.getLastPart(); for (int part = firstPart; part <= lastPart; part++) { if (first) { first = false; } else { sbEpisode.append(Movie.SPACE_SLASH_SPACE); } sbEpisode.append(part); } } value = sbEpisode.toString(); } else { value = Integer.toString(movie.getFiles().size()); } } } else if ("top250".equalsIgnoreCase(name)) { value = movie.getTop250() > 0 ? TRUE : FALSE; } else if (KEYWORDS.equalsIgnoreCase(name)) { value = movie.getBaseFilename().toLowerCase(); } else if (COUNTRY.equalsIgnoreCase(name)) { value = movie.getCountriesAsString(); if (!blockCountry) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } } } else if (COMPANY.equalsIgnoreCase(name)) { value = movie.getCompany(); if (!blockCompany) { int pos = value.indexOf(Movie.SPACE_SLASH_SPACE); if (pos > -1) { value = value.substring(0, pos); } } } else if (AWARD.equalsIgnoreCase(name)) { value = ""; int awardCount = 0; Map<String, Integer> awards = new HashMap<>(); if (!movie.isSetMaster()) { for (AwardEvent awardEvent : movie.getAwards()) { for (Award award : awardEvent.getAwards()) { if (award.getWon() > 0) { if (blockAward) { awards.put((awardEventName ? (awardEvent.getName() + " - ") : "") + award.getName(), award.getWon()); } else if (countAward) { awardCount++; } else { value = TRUE; break; } } } if (!blockAward && !countAward && StringTools.isValidString(value)) { break; } } } if (blockAward) { ValueComparator bvc = new ValueComparator(awards); Map<String, Integer> sortedAwards = new TreeMap<>(bvc); sortedAwards.putAll(awards); StringBuilder sbAwards = new StringBuilder(); boolean first = value.isEmpty(); // Append the separator only if the "value" is not empty for (String award : sortedAwards.keySet()) { if (first) { first = false; } else { sbAwards.append(Movie.SPACE_SLASH_SPACE); } sbAwards.append(award); } value += sbAwards.toString(); } value = (StringTools.isNotValidString(value) && !countAward) ? blockAward ? Movie.UNKNOWN : FALSE : countAward ? Integer.toString(awardCount) : value; } else { value = PropertiesUtil.getProperty(name, Movie.UNKNOWN); } } StateOverlay state = new StateOverlay(layer.getLeft(), layer.getTop(), layer.getAlign(), layer.getValign(), layer.getWidth(), layer.getHeight(), value); states.add(state); } for (int inx = 0; inx < layer.getNames().size(); inx++) { String name = layer.getNames().get(inx); String value = states.get(inx).getValue(); String filename = Movie.UNKNOWN; if (checkLogoEnabled(name)) { if (!blockLanguage && LANGUAGE.equalsIgnoreCase(name) && StringTools.isValidString(value)) { filename = "languages/English.png"; } String[] values = value.split(Movie.SPACE_SLASH_SPACE); for (String splitValue : values) { value = splitValue; for (ImageOverlay img : layer.getImages()) { if (img.getName().equalsIgnoreCase(name)) { boolean accept = false; if (img.getValues().size() == 1 && cmpOverlayValue(name, img.getValue(), value)) { accept = true; } else if (img.getValues().size() > 1) { accept = true; for (int i = 0; i < layer.getNames().size(); i++) { accept = accept && cmpOverlayValue(layer.getNames().get(i), img.getValues().get(i), states.get(i).getValue()); if (!accept) { break; } } } if (!accept) { continue; } File imageFile = new File(overlayResources + img.getFilename()); if (imageFile.exists()) { if (StringTools.isNotValidString(filename)) { filename = img.getFilename(); } else { filename += Movie.SPACE_SLASH_SPACE + img.getFilename(); } } break; } } } flag = flag || StringTools.isValidString(filename); } states.get(inx).setFilename(filename); } if (!flag) { continue; } if (!layer.getPositions().isEmpty()) { for (ConditionOverlay cond : layer.getPositions()) { flag = true; for (int i = 0; i < layer.getNames().size(); i++) { String name = layer.getNames().get(i); String condition = cond.getValues().get(i); String value = states.get(i).getValue(); flag = flag && cmpOverlayValue(name, condition, value); if (!flag) { break; } } if (flag) { for (int i = 0; i < layer.getNames().size(); i++) { PositionOverlay pos = cond.getPositions().get(i); states.get(i).setLeft(pos.getLeft()); states.get(i).setTop(pos.getTop()); states.get(i).setAlign(pos.getAlign()); states.get(i).setValign(pos.getValign()); } break; } } } for (int i = 0; i < layer.getNames().size(); i++) { StateOverlay state = states.get(i); String name = layer.getNames().get(i); if (!blockLanguage && LANGUAGE.equalsIgnoreCase(name)) { newBi = drawLanguage(movie, newBi, getOverlayX(newBi.getWidth(), 62, state.getLeft(), state.getAlign()), getOverlayY(newBi.getHeight(), 40, state.getTop(), state.getValign())); continue; } String filename = state.getFilename(); if (StringTools.isNotValidString(filename)) { continue; } if (((blockAudioCodec && ((AUDIOCODEC.equalsIgnoreCase(name) || ACODEC.equalsIgnoreCase(name) || "AC".equalsIgnoreCase(name)))) || (blockAudioChannels && (AUDIOCHANNELS.equalsIgnoreCase(name) || CHANNELS.equalsIgnoreCase(name))) || (blockAudioLang && (AUDIOLANG.equalsIgnoreCase(name) || ALANG.equalsIgnoreCase(name) || "AL".equalsIgnoreCase(name))) || (blockCountry && COUNTRY.equalsIgnoreCase(name)) || (blockCompany && COMPANY.equalsIgnoreCase(name)) || (blockAward && AWARD.equalsIgnoreCase(name)) || (blockWatched && WATCHED.equalsIgnoreCase(name)) || (blockEpisode && EPISODE.equalsIgnoreCase(name)) || (blockSubTitle && SUBTITLE.equalsIgnoreCase(name)) || (blockLanguage && LANGUAGE.equalsIgnoreCase(name))) && (overlayBlocks.get(name) != null)) { newBi = drawBlock(movie, newBi, name, filename, state.getLeft(), state.getAlign(), state.getWidth(), state.getTop(), state.getValign(), state.getHeight()); continue; } try { BufferedImage biSet = GraphicTools.loadJPEGImage(overlayResources + filename); Graphics2D g2d = newBi.createGraphics(); g2d.drawImage(biSet, getOverlayX(newBi.getWidth(), biSet.getWidth(), state.getLeft(), state.getAlign()), getOverlayY(newBi.getHeight(), biSet.getHeight(), state.getTop(), state.getValign()), state.getWidth().matches(D_PLUS) ? Integer.parseInt(state.getWidth()) : biSet.getWidth(), state.getHeight().matches(D_PLUS) ? Integer.parseInt(state.getHeight()) : biSet.getHeight(), null); g2d.dispose(); } catch (FileNotFoundException ex) { LOG.warn("Failed to load {} {}, please ensure it is valid", overlayResources, filename); } catch (IOException ex) { LOG.warn( "Failed drawing overlay to image file: Please check that {} is in the resources directory.", filename); } if ("set".equalsIgnoreCase(name)) { newBi = drawSetSize(movie, newBi); } } } } else if (beforeMainOverlay) { if (addHDLogo) { newBi = drawLogoHD(movie, newBi, addTVLogo); } if (addTVLogo) { newBi = drawLogoTV(movie, newBi, addHDLogo); } if (addLanguage) { newBi = drawLanguage(movie, newBi, 1, 1); } if (addSubTitle) { newBi = drawSubTitle(movie, newBi); } // Should only really happen on set's thumbnails. if (imageType.equalsIgnoreCase(THUMBNAIL) && movie.isSetMaster()) { // Draw the set logo if requested. if (addSetLogo) { newBi = drawSet(movie, newBi); LOG.debug("Drew set logo on {}", movie.getTitle()); } newBi = drawSetSize(movie, newBi); } } return newBi; }
From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java
private void drawFromOffscreenBuffer(Graphics2D g, Image sourceImage, Rectangle sourceArea, Rectangle targetArea) {/*w ww.ja va 2 s . c o m*/ // copying from the image (here, gScreen is the Graphics // object for the onscreen window) do { int returnCode = offscreenBuffer.validate(getGraphicsConfiguration()); if (returnCode == VolatileImage.IMAGE_RESTORED) { // Contents need to be restored drawOffscreenImage(sourceImage); // restore contents } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) { // old vImg doesn't work with new GraphicsConfig; re-create it offscreenBuffer = null; drawOffscreenImage(sourceImage); } int sx0, sx1, sy0, sy1, tx0, tx1, ty0, ty1; sx0 = sourceArea.x; // sx1 = sourceArea.x + sourceArea.width; sy0 = sourceArea.y; // sy1 = sourceArea.y + sourceArea.height; tx0 = targetArea.x; // tx1 = targetArea.x + targetArea.width; ty0 = targetArea.y; // ty1 = targetArea.y + targetArea.height; g.drawImage(offscreenBuffer.getSnapshot().getSubimage(sx0, sy0, sourceArea.width, sourceArea.height), tx0, ty0, targetArea.width, targetArea.height, null); } while (offscreenBuffer.contentsLost()); }
From source file:FirstStatMain.java
private Image scaledImage(byte[] img, int w, int h) { BufferedImage sizechange = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); try {/* w w w . j a v a2 s . c om*/ Graphics2D g2d = sizechange.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); ByteArrayInputStream input = new ByteArrayInputStream(img); BufferedImage bfg = ImageIO.read(input); g2d.drawImage(bfg, 0, 0, w, h, null); g2d.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, e); } return sizechange; }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
private BufferedImage drawBlock(IMovieBasicInformation movie, BufferedImage bi, String name, String files, int left, String align, String width, int top, String valign, String height) { int currentFilenameNumber = 0; if (StringTools.isValidString(files)) { String[] filenames = files.split(Movie.SPACE_SLASH_SPACE); try {//from w w w. ja v a 2 s . c o m Graphics2D g2d = bi.createGraphics(); BufferedImage biSet = GraphicTools .loadJPEGImage(overlayResources + filenames[currentFilenameNumber]); List<String> uniqueFiles = new ArrayList<>(); uniqueFiles.add(filenames[0]); int lWidth = width.matches(D_PLUS) ? Integer.parseInt(width) : biSet.getWidth(); int lHeight = height.matches(D_PLUS) ? Integer.parseInt(height) : biSet.getHeight(); LogosBlock block = overlayBlocks.get(name); int cols = block.getCols(); int rows = block.getRows(); boolean clones = block.isClones(); if (filenames.length > 1) { if (cols == 0 && rows == 0) { cols = (int) Math.sqrt(filenames.length); rows = (filenames.length / cols); } else if (cols == 0) { cols = (filenames.length / rows); } else if (rows == 0) { rows = (filenames.length / cols); } if (block.isSize()) { lWidth = (lWidth / cols); lHeight = (lHeight / rows); } } int maxWidth = lWidth; int maxHeight = lHeight; g2d.drawImage(biSet, getOverlayX(bi.getWidth(), lWidth, left, align), getOverlayY(bi.getHeight(), lHeight, top, valign), lWidth, lHeight, null); if (filenames.length > 1) { int col = 0; int row = 0; int offsetX = block.isDir() ? lWidth : 0; int offsetY = block.isDir() ? 0 : lHeight; for (int i = 1; i < filenames.length; i++) { if (!clones) { if (uniqueFiles.contains(filenames[i])) { continue; } uniqueFiles.add(filenames[i]); } if (block.isDir()) { col++; if (block.getCols() > 0 && col >= cols) { col = 0; row++; if (block.getRows() > 0 && row >= rows) { break; } } } else { row++; if (block.getRows() > 0 && row >= rows) { row = 0; col++; if (block.getCols() > 0 && col >= cols) { break; } } } currentFilenameNumber = i; biSet = GraphicTools.loadJPEGImage(overlayResources + filenames[currentFilenameNumber]); if (block.isSize() || width.equalsIgnoreCase(EQUAL) || width.matches(D_PLUS)) { offsetX = (left > 0 ? 1 : -1) * col * (lWidth + block.gethMargin()); } else if (width.equalsIgnoreCase(AUTO)) { lWidth = biSet.getWidth(); offsetX = block.isDir() ? col == 0 ? 0 : offsetX : row == 0 ? (offsetX + maxWidth) : offsetX; } if (block.isSize() || height.equalsIgnoreCase(EQUAL) || height.matches(D_PLUS)) { offsetY = (top > 0 ? 1 : -1) * row * (lHeight + block.getvMargin()); } else if (height.equalsIgnoreCase(AUTO)) { lHeight = biSet.getHeight(); offsetY = block.isDir() ? col == 0 ? (offsetY + maxHeight) : offsetY : row == 0 ? 0 : offsetY; } g2d.drawImage(biSet, getOverlayX(bi.getWidth(), lWidth, left + offsetX, align), getOverlayY(bi.getHeight(), lHeight, top + offsetY, valign), lWidth, lHeight, null); if (!block.isSize() && width.equalsIgnoreCase(AUTO)) { if (block.isDir()) { offsetX += (left > 0 ? 1 : -1) * lWidth; } else { maxWidth = (maxWidth < lWidth || row == 0) ? lWidth : maxWidth; } } if (!block.isSize() && height.equalsIgnoreCase(AUTO)) { if (block.isDir()) { maxHeight = (maxHeight < lHeight || col == 0) ? lHeight : maxHeight; } else { offsetY += (top > 0 ? 1 : -1) * lHeight; } } } } g2d.dispose(); } catch (FileNotFoundException ex) { LOG.warn("Failed to load {}{}, please ensure it is valid", overlayResources, filenames[currentFilenameNumber]); } catch (IOException ex) { LOG.warn("Failed drawing overlay block logo ({}) to thumbnail file: {}", filenames[currentFilenameNumber], movie.getBaseName()); } } return bi; }
From source file:org.clipsmonitor.core.MonitorGenMap.java
/** * Metodo per il disegno della scena utilizzando i valori in stringhe della * mappa.le mappe sono di due tipologie per cui devono essere riempite in * maniera distinta. Per prima cosa viene eseguito il controllo su quale * matrice bisogna costruire./*from w w w. j av a2s .c om*/ * * @param g : per effettuare il draw del pannello * @param MapWidth : larghezza in pixel del pannello della mappa * @param MapHeight : altezza in pixel del pannello della mappa */ public void drawScene(Graphics2D g, float MapWidth, float MapHeight) { BufferedImage[][] icons = makeIconMatrix(); //aggiorno le dimensioni della finestra MapWidth = MapWidth; MapHeight = MapHeight; //calcolo la larghezza delle celle CellWidth = (MapWidth - 20) / NumCellX; CellHeight = (MapHeight - 20) / NumCellY; //verifico chi delle due dimensioni minore e setto quella maggiore uguale a quella minore // per rendere le celle quadrate if (CellWidth > CellHeight) { CellWidth = CellHeight; } else { CellHeight = CellWidth; } //calcolo le coordinate di inizio della scena partendo a disegnare //dall'angolo in alto a sinistra della nostra scena float x0 = (MapWidth - CellWidth * NumCellX) / 2; float y0 = (MapHeight - CellHeight * NumCellY) / 2; //setto colore delle scritte g.setColor(Color.BLACK); //doppio ciclo sulla matrice for (int i = 0; i < NumCellX; i++) { for (int j = 0; j < NumCellY; j++) { //calcolo la posizione x,y dell'angolo in alto a sinistra della //cella corrente int x = (int) (x0 + i * CellWidth); int y = (int) (y0 + j * CellHeight); //se la cella non vuota, allora disegno l'immagine corrispondente if (!scene[i][j].equals("")) { //disegno l'immagine corretta usando la stringa che definisce la chiave per l'hashmap g.drawImage(icons[i][j], x, y, (int) (CellWidth - 1), (int) (CellHeight - 1), null); } //traccio il rettangolo della cella g.drawRect(x, y, (int) (CellWidth - 1), (int) (CellHeight - 1)); } } }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw a frame around the image; color depends on resolution if wanted * * @param movie/*ww w. j a v a 2 s .com*/ * @param bi * @return */ private BufferedImage drawFrame(Movie movie, BufferedImage bi) { BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D newGraphics = newImg.createGraphics(); newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cornerRadius2 = 0; if (!movie.isHD()) { String[] colorSD = frameColorSD.split("/"); int[] lengthSD = new int[colorSD.length]; for (int i = 0; i < colorSD.length; i++) { lengthSD[i] = Integer.parseInt(colorSD[i]); } newGraphics.setPaint(new Color(lengthSD[0], lengthSD[1], lengthSD[2])); } else if (highdefDiff) { if (movie.isHD()) { // Otherwise use the 720p String[] color720 = frameColor720.split("/"); int[] length720 = new int[color720.length]; for (int i = 0; i < color720.length; i++) { length720[i] = Integer.parseInt(color720[i]); } newGraphics.setPaint(new Color(length720[0], length720[1], length720[2])); } if (movie.isHD1080()) { String[] color1080 = frameColor1080.split("/"); int[] length1080 = new int[color1080.length]; for (int i = 0; i < color1080.length; i++) { length1080[i] = Integer.parseInt(color1080[i]); } newGraphics.setPaint(new Color(length1080[0], length1080[1], length1080[2])); } } else { // We don't care, so use the default HD logo. String[] colorHD = frameColorHD.split("/"); int[] lengthHD = new int[colorHD.length]; for (int i = 0; i < colorHD.length; i++) { lengthHD[i] = Integer.parseInt(colorHD[i]); } newGraphics.setPaint(new Color(lengthHD[0], lengthHD[1], lengthHD[2])); } if (roundCorners) { cornerRadius2 = cornerRadius; } RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(), rcqFactor * cornerRadius2, rcqFactor * cornerRadius2); newGraphics.setClip(rect); // image fitted into border newGraphics.drawImage(bi, (int) (rcqFactor * frameSize - 1), (int) (rcqFactor * frameSize - 1), (int) (bi.getWidth() - (rcqFactor * frameSize * 2) + 2), (int) (bi.getHeight() - (rcqFactor * frameSize * 2) + 2), null); BasicStroke s4 = new BasicStroke(rcqFactor * frameSize * 2); newGraphics.setStroke(s4); newGraphics.draw(rect); newGraphics.dispose(); return newImg; }