List of usage examples for java.awt Graphics drawImage
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer);
From source file:IconLine.java
public void paintIcon(Component c, Graphics g, int x, int y) { int dx = 0;/*w ww. j a v a 2 s. c o m*/ for (int i = 0; i < vImages.size(); i++) { Image image = (Image) vImages.get(i); g.drawImage(image, x + dx, y, c); dx += image.getWidth(c) + iSpace; } }
From source file:com.frostwire.gui.library.LibraryCoverArt.java
@Override public void paint(Graphics g) { super.paint(g); g.drawImage(background, 0, 0, null); }
From source file:br.com.renatoccosta.regexrenamer.view.FrmAbout.java
@Override protected JRootPane createRootPane() { final ImageIcon imageIcon = new ImageIcon(getClass().getResource("/background.png")); return new JRootPane() { Image image = imageIcon.getImage(); {/* w w w . ja v a 2 s. co m*/ setOpaque(false); } @Override protected void paintComponent(Graphics g) { g.drawImage(image, 0, 0, this); super.paintComponent(g); } }; }
From source file:ScreenCapture.java
public void paintComponent(Graphics g) { super.paintComponent(g); if (image != null) g.drawImage(image, 0, 0, this); if (startPoint.x != endPoint.x || startPoint.y != endPoint.y) { int x1 = (startPoint.x < endPoint.x) ? startPoint.x : endPoint.x; int y1 = (startPoint.y < endPoint.y) ? startPoint.y : endPoint.y; int x2 = (startPoint.x > endPoint.x) ? startPoint.x : endPoint.x; int y2 = (startPoint.y > endPoint.y) ? startPoint.y : endPoint.y; selectedRectangle.x = x1;//w ww . j a v a2s . c o m selectedRectangle.y = y1; selectedRectangle.width = (x2 - x1) + 1; selectedRectangle.height = (y2 - y1) + 1; Graphics2D g2d = (Graphics2D) g; g2d.draw(selectedRectangle); } }
From source file:MyCanvas.java
public void paint(Graphics g) { if (getSize().width <= 0 || getSize().height <= 0) return;/*from w ww . j ava2 s . c o m*/ Graphics2D g2 = createDemoGraphics2D(g); draw(g2); g2.dispose(); if (offImg != null && isShowing()) { g.drawImage(offImg, 0, 0, this); } }
From source file:SlidePuzzle.java
public void paint(Graphics g) { if (m_fAllLoaded) { Rectangle r = g.getClipRect(); g.clearRect(r.x, r.y, r.width, r.height); g.drawImage(logo, 0, 0, null); } else//from w w w .j a va 2s . c o m g.drawString("Loading images...", 10, 20); }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactoryTest.java
@Test public void testCreateFromImageINT_ARGB() throws IOException { // workaround Open JDK bug // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758 if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) { return;/* ww w .j a va2s. co m*/ } PDDocument document = new PDDocument(); BufferedImage image = ImageIO.read(JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg")); // create an ARGB image int width = image.getWidth(); int height = image.getHeight(); BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics ag = argbImage.getGraphics(); ag.drawImage(image, 0, 0, null); ag.dispose(); for (int x = 0; x < argbImage.getWidth(); ++x) { for (int y = 0; y < argbImage.getHeight(); ++y) { argbImage.setRGB(x, y, (argbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24)); } } PDImageXObject ximage = JPEGFactory.createFromImage(argbImage); validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName()); assertNotNull(ximage.getSoftMask()); validate(ximage.getSoftMask(), 8, width, height, "jpg", PDDeviceGray.INSTANCE.getName()); assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10); doWritePDF(document, ximage, testResultsDir, "jpeg-intargb.pdf"); }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactoryTest.java
@Test public void testCreateFromImage4BYTE_ABGR() throws IOException { // workaround Open JDK bug // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758 if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) { return;//from w w w . j av a2s .c o m } PDDocument document = new PDDocument(); BufferedImage image = ImageIO.read(JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg")); // create an ARGB image int width = image.getWidth(); int height = image.getHeight(); BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics ag = argbImage.getGraphics(); ag.drawImage(image, 0, 0, null); ag.dispose(); for (int x = 0; x < argbImage.getWidth(); ++x) { for (int y = 0; y < argbImage.getHeight(); ++y) { argbImage.setRGB(x, y, (argbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24)); } } PDImageXObject ximage = JPEGFactory.createFromImage(argbImage); validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName()); assertNotNull(ximage.getSoftMask()); validate(ximage.getSoftMask(), 8, width, height, "jpg", PDDeviceGray.INSTANCE.getName()); assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10); doWritePDF(document, ximage, testResultsDir, "jpeg-4bargb.pdf"); }
From source file:GrabandFade.java
/** * continually draw image, then decrease color components of all pixels * contained in the originalPixelArray array until color components are all * 0/* ww w. j a v a 2 s. co m*/ */ public void paint(Graphics g) { int value; int alpha, sourceRed, sourceGreen, sourceBlue; if (newImage != null) { g.drawImage(newImage, 0, 0, this); // redraw image // if image isn't faded to black, continue if (imageLoaded == false) { imageLoaded = true; for (int x = 0; x < width; x += 1) for (int y = 0; y < height; y += 1) { // find the color components value = originalPixelArray[x * height + y]; alpha = (value >> 24) & 0x000000ff; sourceRed = (value >> 16) & 0x000000ff; sourceGreen = (value >> 8) & 0x000000ff; sourceBlue = value & 0x000000ff; // subtract index from each red component if (sourceRed > index) { sourceRed -= index; imageLoaded = false; } else sourceRed = 0; // subtract index from each green component if (sourceGreen > index) { sourceGreen -= index; imageLoaded = false; } else sourceGreen = 0; // subtract index from each blue component if (sourceBlue > index) { sourceBlue -= index; imageLoaded = false; } else sourceBlue = 0; /* * when we pack new color components into integer we * make sure the alpha (transparency) value represents * opaque */ value = (alpha << 24); value += (sourceRed << 16); value += (sourceGreen << 8); value += sourceBlue; // fill pixel array originalPixelArray[x * height + y] = value; } mis.newPixels(); //send pixels to ImageConsumer } } }
From source file:com.ace.erp.controller.sys.company.OrganizationController.java
@RequestMapping(value = "/company/uploadLogo", method = RequestMethod.POST) @ResponseBody//from www.j av a2 s . c o m public Response uploadLogo(@CurrentUser User user, String srcImageFile, int x, int y, int destWidth, int destHeight, int srcShowWidth, int srcShowHeight, HttpServletRequest request) { try { String path = request.getSession().getServletContext().getRealPath("/"); String contextPath = request.getContextPath(); Image img; ImageFilter cropFilter; //String srcFileName = FilenameUtils.getName(srcImageFile); String srcFileName = StringUtils.isNotBlank(contextPath) ? srcImageFile.replaceFirst(contextPath, "") : srcImageFile; // ??? File srcFile = new File(path + "/" + srcFileName); BufferedImage bi = ImageIO.read(srcFile); //?????????? int srcWidth = bi.getWidth(); // ? int srcHeight = bi.getHeight(); // ? if (srcShowWidth == 0) srcShowWidth = srcWidth; if (srcShowHeight == 0) srcShowHeight = srcHeight; if (srcShowWidth >= destWidth && srcShowHeight >= destHeight) { //??? Image image = bi.getScaledInstance(srcShowWidth, srcShowHeight, Image.SCALE_DEFAULT); cropFilter = new CropImageFilter(x, y, destWidth, destHeight); img = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(image.getSource(), cropFilter)); BufferedImage tag = new BufferedImage(destWidth, destHeight, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(img, 0, 0, null); // ?? g.dispose(); String ext = FilenameUtils.getExtension(srcImageFile); //path += HEADER_PIC; //User loginUser = SystemUtil.getLoginUser(request.getSession()); //String fileName = user.getOrganizationList().get(0).getId()+""; File destImageFile = new File(path + "/" + System.currentTimeMillis() + ".jpg"); // ImageIO.write(tag, ext, destImageFile); //loginUser.setPicPath(SystemConst.SYSTEM_CONTEXT_PATH_VALUE + HEADER_PIC + "/" + fileName); //userService.update(loginUser); // srcFile.delete(); return new Response(new ResponseHeader(200, 20)); } } catch (Exception e) { e.printStackTrace(); } return null; }