/** constructor */ public DanceQueuePanel() { // flow layout setLayout(new FlowLayout()); // uses buffer to draw arrows based on queues in an array myImage = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB); myBuffer = myImage.getGraphics(); // uses timer to queue buffer changes time = 0; timer = new Timer(5, new Listener()); timer.start(); setFocusable(true); // picks instructions based on song & level if (Danceoff.getSong() == -1 && Danceoff.getDifficulty() == 0) { arrows = new Arrow[] {new UpArrow(1000), new DownArrow(2000), new LeftArrow(3000)}; } // setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3), // "DanceQueuePanel")); // load images for arrows rightArrowImg = null; leftArrowImg = null; upArrowImg = null; downArrowImg = null; try { rightArrowImg = ImageIO.read(new File("arrowB right.png")); leftArrowImg = ImageIO.read(new File("arrowB left.png")); upArrowImg = ImageIO.read(new File("arrowB up copy.png")); downArrowImg = ImageIO.read(new File("arrowB down.png")); } catch (IOException e) { warn("YOU FAIL", e); System.exit(2); } }
private static double compareImage(String image1Path, String imageTrgtPath) { try { BufferedImage image1 = ImageIO.read(new File(image1Path)); BufferedImage imageTrgt = ImageIO.read(new File(imageTrgtPath)); int[] img1RGB = image1.getRGB(0, 0, image1.getWidth(), image1.getHeight(), null, 0, image1.getWidth()); int[] imgTrgtRGB = imageTrgt.getRGB( 0, 0, imageTrgt.getWidth(), imageTrgt.getHeight(), null, 0, imageTrgt.getWidth()); int nSize = img1RGB.length < imgTrgtRGB.length ? img1RGB.length : imgTrgtRGB.length; if (nSize == 0) { return 0; } double nSum = 0.0; for (int i = 0; i < nSize; i++) { nSum = nSum + (1 - Math.abs((double) (img1RGB[i] - imgTrgtRGB[i])) / Math.abs(img1RGB[i] < imgTrgtRGB[i] ? img1RGB[i] : imgTrgtRGB[i])); } return nSum / nSize; } catch (IOException e) { e.printStackTrace(); return 0; } }
public ActionPanel(vbhitController controller) { super(); this.controller = controller; this.instruction = new InstructionsMenu(this.controller); this.pausemenu = new PauseMenu(this.controller); this.savekeymappanel = new SaveKeyMapPanel(this.controller); this.setupmenu = new SetupMenu(this.controller); this.titlemenu = new TitleMenu(this.controller); this.reportmenu = new ReportMenu(this.controller); this.add(this.reportmenu); this.add(this.titlemenu); this.add(this.pausemenu); this.add(this.savekeymappanel); this.add(this.setupmenu); this.add(this.instruction); this.reportmenu.setVisible(false); this.titlemenu.setVisible(false); this.pausemenu.setVisible(false); this.savekeymappanel.setVisible(false); this.setupmenu.setVisible(false); this.instruction.setVisible(false); this.setBackground(null); this.ratio = (float) this.getSize().width / 1000; try { centerbackground = ImageIO.read(new File("src\\MVC\\imagecontainer\\background\\background2.jpg")); topleft = ImageIO.read(new File("src\\MVC\\imagecontainer\\background\\topleft.png")); topright = ImageIO.read(new File("src\\MVC\\imagecontainer\\background\\topright.png")); bottomleft = ImageIO.read(new File("src\\MVC\\imagecontainer\\background\\bottmleft.png")); bottomright = ImageIO.read(new File("src\\MVC\\imagecontainer\\background\\bottomright.png")); } catch (Exception e) { System.err.println("actionpanel image input fail in actionpanel"); } }
public Queen(ChessColor color, Integer x, Integer y) { this.pieceName = "Q"; this.x = x; this.y = y; this.color = color; if (color.isWhite()) { BufferedImage bi; try { File img = new File(whiteQueenFile); bi = ImageIO.read(img); image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB_PRE); Graphics g = image.getGraphics(); g.drawImage(bi.getScaledInstance(64, 64, Image.SCALE_SMOOTH), 0, 0, null); } catch (IOException e) { e.printStackTrace(); } } else { BufferedImage bi; try { File img = new File(blackQueenFile); bi = ImageIO.read(img); image = new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB_PRE); Graphics g = image.getGraphics(); g.drawImage(bi.getScaledInstance(64, 64, Image.SCALE_SMOOTH), 0, 0, null); } catch (IOException e) { e.printStackTrace(); } } }
public Game(Window w) { try { masa = ImageIO.read(new File("table.jpg")); } catch (IOException e) { System.out.println("Eroare imagine fundal"); } try { rBall = ImageIO.read(new File("redBall.gif")); } catch (IOException e) { System.out.println("Eroare imagine bila"); } try { bBall = ImageIO.read(new File("blueBall.gif")); } catch (IOException e) { System.out.println("Eroare imagine bila"); } try { cue = ImageIO.read(new File("cue.gif")); } catch (IOException e) { System.out.println("Eroare imagine bila"); } addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); setFocusable(true); Game.w = w; }
public UnitPanel(Paint p, SelecPanel panelPere, int height, int width, Fenetre f) { setBackground(COLOURBACK); this.setPreferredSize(new Dimension(width, height)); this.setOpaque(false); this.p = p; this.f = f; this.panelPere = panelPere; try { terriP1 = ImageIO.read(new File("./ressources/images/unit/BlueTerritoire.png")); terriP2 = ImageIO.read(new File("./ressources/images/unit/RedTerritoire.png")); } catch (IOException e) { e.printStackTrace(); } try { Image img = ImageIO.read(new File("./ressources/images/unit/CityBlue.png")); imgP1 = img; img = ImageIO.read(new File("./ressources/images/unit/CityRed.png")); imgP2 = img; } catch (IOException e) { e.printStackTrace(); } Zone p1 = new Zone(6, 4, imgP1); defTerri(p1, tailleTerritoire, terriP1); Zone p2 = new Zone(17, 8, imgP2); defTerri(p2, tailleTerritoire, terriP2); listCity.add(p1); listCity.add(p2); this.addMouseListener(this); this.addMouseMotionListener(this); }
/** loads the sprites to be used for the bots */ public static void loadSprites() { try { mainImageEast = ImageIO.read(new File("char/archer_east.png")); mainImageWest = ImageIO.read(new File("char/archer_west.png")); north = new BufferedImage[frameCount]; south = new BufferedImage[frameCount]; east = new BufferedImage[frameCount]; west = new BufferedImage[frameCount]; north_east = new BufferedImage[frameCount]; north_west = new BufferedImage[frameCount]; south_east = new BufferedImage[frameCount]; south_west = new BufferedImage[frameCount]; for (int i = 0; i < frameCount; i++) { north[i] = mainImageEast.getSubimage(0 * width, height * i, width, height); north_east[i] = mainImageEast.getSubimage(1 * width, height * i, width, height); east[i] = mainImageEast.getSubimage(2 * width, height * i, width, height); south_east[i] = mainImageEast.getSubimage(3 * width, height * i, width, height); south[i] = mainImageEast.getSubimage(4 * width, height * i, width, height); north_west[i] = mainImageWest.getSubimage(3 * width, height * i, width, height); west[i] = mainImageWest.getSubimage(2 * width, height * i, width, height); south_west[i] = mainImageWest.getSubimage(1 * width, height * i, width, height); } } catch (Exception e) { System.out.println("Spritesheet Not Found!"); } }
/** * 把图片印刷到图片上 * * @param pressImg -- 水印文件 * @param targetImg -- 目标文件 * @param x * @param y */ public static final void pressImage(String pressImg, String targetImg, int x, int y) { try { File _file = new File(targetImg); Image src = ImageIO.read(_file); int wideth = src.getWidth(null); int height = src.getHeight(null); BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics(); g.drawImage(src, 0, 0, wideth, height, null); // 水印文件 File _filebiao = new File(pressImg); Image src_biao = ImageIO.read(_filebiao); int wideth_biao = src_biao.getWidth(null); int height_biao = src_biao.getHeight(null); g.drawImage( src_biao, wideth - wideth_biao - x, height - height_biao - y, wideth_biao, height_biao, null); // / g.dispose(); FileOutputStream out = new FileOutputStream(targetImg); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(image); out.close(); } catch (Exception e) { e.printStackTrace(); } }
private static HtmlCommand build(final Matcher m, final ImgValign valign, final int vspace) { if (m.find() == false) { return new Text("(SYNTAX ERROR)"); } final String src = m.group(1); try { final File f = FileSystem.getInstance().getFile(src); if (f.exists() == false) { // Check if valid URL if (src.startsWith("http:") || src.startsWith("https:")) { final byte image[] = getFile(src); final BufferedImage read = ImageIO.read(new ByteArrayInputStream(image)); if (read == null) { return new Text("(Cannot decode: " + src + ")"); } return new Img(new TileImage(read, valign, vspace)); } return new Text("(File not found: " + f + ")"); } if (f.getName().endsWith(".svg")) { return new Img(new TileImageSvg(f)); } final BufferedImage read = ImageIO.read(f); if (read == null) { return new Text("(Cannot decode: " + f + ")"); } return new Img(new TileImage(ImageIO.read(f), valign, vspace)); } catch (IOException e) { return new Text("ERROR " + e.toString()); } }
private void init() { int pp = 0; for (int r = 0; r < 6; r++) { for (int g = 0; g < 6; g++) { for (int b = 0; b < 6; b++) { int rr = r * 255 / 5; int gg = g * 255 / 5; int bb = b * 255 / 5; int mid = (rr * 30 + gg * 59 + bb * 11) / 100; int r1 = (rr + mid * 1) / 2 * 230 / 255 + 10; int g1 = (gg + mid * 1) / 2 * 230 / 255 + 10; int b1 = (bb + mid * 1) / 2 * 230 / 255 + 10; this.colors[(pp++)] = (r1 << 16 | g1 << 8 | b1); } } } try { this.screen = new Screen( 160, 120, new SpriteSheet(ImageIO.read(Game.class.getResourceAsStream("/icons.png")))); this.lightScreen = new Screen( 160, 120, new SpriteSheet(ImageIO.read(Game.class.getResourceAsStream("/icons.png")))); } catch (IOException e) { e.printStackTrace(); } resetGame(); setMenu(new TitleMenu()); }
// CONSTRUCTOR public DrawRooms(int[][] arooms) { try { image1 = ImageIO.read(new File("tiger.gif")); image2 = ImageIO.read(new File("prisoner.gif")); image3 = ImageIO.read(new File("princess.jpg")); } catch (IOException e) {; } // Image image; // THIS WILL ASSIGN A REFERENCE TO ARRAY OF INTS CREATED IN GUI CLASS this.Arooms = arooms; // YOU NEED TO SET THE PREFERRED SIZE TO GET THE DISPLAY THE SIZE YOU WANT IT. setPreferredSize(new Dimension(620, 620)); // CREATE THREE IMAGEICONS E.G. THIS SHOWs HOW TO SCALE IT // create the imageicon // get an image object from it image1 = image1.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size image2 = image2.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size image3 = image3.getScaledInstance(28, 28, Image.SCALE_SMOOTH); // reduce its size // // setBackground(Color.yellow); }
/** * Constructor * * @param mainFrame */ public BrowserMenuBar(MainFrame mainFrame) { super("Controls"); this.mainFrame = mainFrame; this.folderChooser = new JFileChooser(); this.setFloatable(false); // Prepare listener and FileChooser Listener listener = new Listener(); folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); mainFrame.addIsolatedComponent(folderChooser); // Prepare buttons try { detectFacesButton = new JButton(new ImageIcon(ImageIO.read(RessourceLoader.getFile("detect.png")))); detectFacesButton.setEnabled(false); openFolderButton = new JButton(new ImageIcon(ImageIO.read(RessourceLoader.getFile("open.png")))); } catch (IOException e) { e.printStackTrace(); } this.add(openFolderButton); this.add(detectFacesButton); openFolderButton.addActionListener(listener); detectFacesButton.addActionListener(listener); this.addSeparator(); // Set tool tips openFolderButton.setToolTipText("Open Folder..."); detectFacesButton.setToolTipText("Run Face Detection"); openFolderButton.setText("Open Folder..."); detectFacesButton.setText("Run Face Detection"); }
@Override protected void initItems() { this.name = "Snow"; URL imgURL = getClass().getResource("R/images/Wall_Gray.png"); try { wallImages.add(ImageIO.read(imgURL)); } catch (IOException e) { e.printStackTrace(); } imgURL = getClass().getResource("R/images/GroundGravel_Sand.png"); try { floorImages.add(ImageIO.read(imgURL)); } catch (IOException e) { e.printStackTrace(); } imgURL = getClass().getResource("R/images/CrateDark_Brown.png"); try { boxImages.add(ImageIO.read(imgURL)); } catch (IOException e) { e.printStackTrace(); } imgURL = getClass().getResource("R/images/Crate_Red.png"); try { boxCompletedImages.add(ImageIO.read(imgURL)); } catch (IOException e) { e.printStackTrace(); } imgURL = getClass().getResource("R/images/EndPoint_Red.png"); try { targetImages.add(ImageIO.read(imgURL)); } catch (IOException e) { e.printStackTrace(); } }
public Card(String type, Color color, String name, int num, String imageName, String deckName) { myType = type; myName = name; myNum = num; this.imageName = imageName; this.deckName = deckName; if (color != null) myColor = color; if (color.equals(Color.BLUE)) col = "Blue"; else if (color.equals(Color.BLACK)) col = "Black"; else if (color.equals(Color.RED)) col = "Red"; else if (color.equals(Color.YELLOW)) col = "Yellow"; if (deckName.equals("Player")) { try { myImage = ImageIO.read(new File("Cards/" + col + "PlayerImages/" + myName + "Player.png")); } catch (IOException ex) { System.out.println("Cards/" + col + "PlayerImages/" + myName + "Player.png not found"); } } else if (deckName.equals("Infection")) { try { myImage = ImageIO.read(new File("Cards/" + col + "InfectionImages/" + myName + "Infection.png")); } catch (IOException ex) { System.out.println( "Cards/" + col + "InfectionImages/" + myName + "Infection.png not found"); } } }
@Test /** * 1. JaveCV Face Detect image in SequenceFile from S3:// 2. JaveCV Face Detect image in * SequenceFile from hdfs:// Before hdfs over HDFS is implemented, do $hadoop fs -cp * hdfs://<path>/tmp/lena.png.seq s3://ori-tmp/lena.png.seq Eclipse: * -Djava.library.path=/home/heq/hadoop-2.2.0/lib/native * * @throws Exception */ public void testJavaCVFaceDetectionFromS3HDFS() throws Exception { String inputURI = "file://" + new File(this.getClass().getResource("/lena.png").getFile()).getAbsolutePath(); String s3URI = "s3n://ori-tmp/lena.png.seq"; Util.writeToSequenceFile(inputURI, s3URI, new SnappyCodec()); byte[] pngbytes = Util.readSequenceFileFromS3(s3URI); BufferedImage rawimage = ImageIO.read(new ByteArrayInputStream(pngbytes)); List<int[]> faces = OpenCV.detectFace(rawimage); assertTrue(faces.size() == 1); String hdfsURI = hadoopMaster + "/tmp/lena.png.seq"; Util.writeToSequenceFile(inputURI, hdfsURI, new SnappyCodec()); pngbytes = Util.readSequenceFileFromHDFS(hdfsURI); rawimage = ImageIO.read(new ByteArrayInputStream(pngbytes)); faces = OpenCV.detectFace(rawimage); assertTrue(faces.size() == 1); }
/** * 图片水印 * * @param pressImg 水印图片 * @param targetImg 目标图片 * @param x 修正值 默认在中间 * @param y 修正值 默认在中间 * @param alpha 透明度 */ public static final void pressImage( String pressImg, String targetImg, int x, int y, float alpha) { try { File img = new File(targetImg); Image src = ImageIO.read(img); int wideth = src.getWidth(null); int height = src.getHeight(null); BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.drawImage(src, 0, 0, wideth, height, null); // 水印文件 Image src_biao = ImageIO.read(new File(pressImg)); int wideth_biao = src_biao.getWidth(null); int height_biao = src_biao.getHeight(null); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha)); g.drawImage( src_biao, (wideth - wideth_biao) / 2, (height - height_biao) / 2, wideth_biao, height_biao, null); // 水印文件结束 g.dispose(); ImageIO.write((BufferedImage) image, "jpg", img); } catch (Exception e) { e.printStackTrace(); } }
public BusAnimation(Bus b, Building startingBuilding) { bus = b; xDestination = xPos = Application.CityMap.findClosestRoad(startingBuilding).getX(); yDestination = yPos = Application.CityMap.findClosestRoad(startingBuilding).getY(); Application.CityMap.findClosestRoad(startingBuilding).setVehicle(this); this.setVisible(true); try { if (cityViewBusNorthImage == null || cityViewBusEastImage == null || cityViewBusSouthImage == null || cityViewBusWestImage == null) { cityViewBusNorthImage = ImageIO.read( CityViewApt.class.getResource("/icons/cityView/CityViewBusNorthImage.png")); cityViewBusEastImage = ImageIO.read(CityViewApt.class.getResource("/icons/cityView/CityViewBusEastImage.png")); cityViewBusSouthImage = ImageIO.read( CityViewApt.class.getResource("/icons/cityView/CityViewBusSouthImage.png")); cityViewBusWestImage = ImageIO.read(CityViewApt.class.getResource("/icons/cityView/CityViewBusWestImage.png")); imageToRender = cityViewBusNorthImage; } } catch (IOException e) { e.printStackTrace(); } }
/** * Testing TIFF capabilities. * * @throws IOException If an error occured while writting the image. */ @Test public void testTIFFWrite() throws IOException { assertTrue("Assertions should be enabled.", ImageWorker.class.desiredAssertionStatus()); // Get the image of the world with transparency. final ImageWorker worker = new ImageWorker(worldImage); show(worker, "Input file"); // ///////////////////////////////////////////////////////////////////// // tiff deflated untiled // ///////////////////////////////////////////////////////////////////// final File outFile = TestData.temp(this, "temp.tiff"); worker.writeTIFF(outFile, "Deflate", 0.75f, -1, -1); final ImageWorker readWorker = new ImageWorker(ImageIO.read(outFile)); show(readWorker, "Tiff untiled"); // ///////////////////////////////////////////////////////////////////// // tiff deflated compressed tiled // ///////////////////////////////////////////////////////////////////// worker.setImage(worldImage); worker.writeTIFF(outFile, "Deflate", 0.75f, 32, 32); readWorker.setImage(ImageIO.read(outFile)); show(readWorker, "Tiff jpeg compressed, tiled"); outFile.delete(); }
/** Create a picture by reading in a .png, .gif, or .jpg from the given filename or URL name. */ public Picture(String filename) { this.filename = filename; try { // try to read from file in working directory File file = new File(filename); if (file.isFile()) { image = ImageIO.read(file); } // now try to read from file in same directory as this .class file else { URL url = getClass().getResource(filename); if (url == null) { url = new URL(filename); } image = ImageIO.read(url); } } catch (IOException e) { // e.printStackTrace(); throw new RuntimeException("Could not open file: " + filename); } // check that image was read in if (image == null) { throw new RuntimeException("Invalid image file: " + filename); } }
/** * Convert a source to a BufferedImage. Source supported: * File,BufferedImage,InputStream,URL,ImageInputStream, byte[] * * @param imageType the ImageType to use * @param source source to generate BufferedImage from * @return Enhanced BufferedImage * @throws NullPointerException _ * @throws IOException _ * @throws UnsupportedOperationException throws this is the source is of unsupported type */ public static <T> BufferedImage convertImageType(final ImageType imageType, final T source) throws NullPointerException, IOException, UnsupportedOperationException { if (verifyNotNull(imageType, source)) { BufferedImage target = null; if (source instanceof File) { target = convert(ImageIO.read((File) source), imageType); } else if (source instanceof BufferedImage) { target = convert((BufferedImage) source, imageType); } else if (source instanceof InputStream) { target = convert(ImageIO.read((InputStream) source), imageType); } else if (source instanceof URL) { target = convert(ImageIO.read((URL) source), imageType); } else if (source instanceof ImageInputStream) { target = convert(ImageIO.read((ImageInputStream) source), imageType); } else if (source instanceof byte[]) { final InputStream streamOfInput = new ByteArrayInputStream((byte[]) source); target = convert(ImageIO.read(streamOfInput), imageType); } else { throw new UnsupportedOperationException("%s is not supported. Read JavaDoc."); } if (verifyNotNull(target)) { LOGGER.info( String.format( "Returning requested converted object<%s> as target", target.getClass().getName())); return target; } throw new NullPointerException("Return value was null."); } throw new NullPointerException("Nilled param detected. Please verify your params!"); }
public void loadTileTexture() { AssetManager assetManager = HexScapeCore.getInstance().getHexScapeJme3Application().getAssetManager(); File commonFolder = new File(AssetService.COMMON_ASSET_FOLDER, TILES_FOLDER_NAME); File gameFolder = new File( new File(AssetService.ASSET_FOLDER, ConfigurationService.getInstance().getGameFolder()), TILES_FOLDER_NAME); File commonFile = new File(commonFolder, TEXTURES_FILE_NAME); File gameFile = new File(gameFolder, TEXTURES_FILE_NAME); BufferedImage bimg = null; try { if (gameFile.exists() && gameFile.isFile() && gameFile.canRead()) { tileTexture = assetManager.loadTexture(gameFile.getPath()); bimg = ImageIO.read(new File(gameFile.getPath())); } else if (commonFile.exists() && commonFile.isFile() && commonFile.canRead()) { tileTexture = assetManager.loadTexture(commonFile.getPath()); bimg = ImageIO.read(new File(gameFile.getPath())); } else { String resourceLocation = "model/texture/defaultTileTexture.bmp"; tileTexture = assetManager.loadTexture(resourceLocation); bimg = ImageIO.read(ClassLoader.getSystemResourceAsStream(resourceLocation)); } int width = bimg.getWidth(); int height = bimg.getHeight(); number = width / height; } catch (IOException e) { throw new RuntimeException("unable to load texture", e); } }
@Test public void testImagesResizeJpg() { new PlayBuilder().build(); File folder = new File(Play.frameworkPath, "/framework/test-src/play/libs"); File source = new File(folder, "winie.jpg"); File result = new File(source.getParent(), "winie_testResult.jpg"); Images.resize(source, result, 1536, 2048); try { BufferedImage buffSrc = ImageIO.read(source); BufferedImage buffDest = ImageIO.read(result); assertEquals(buffSrc.getColorModel().hasAlpha(), buffDest.getColorModel().hasAlpha()); assertEquals(buffSrc.getColorModel().getPixelSize(), buffDest.getColorModel().getPixelSize()); assertEquals( buffSrc.getColorModel().getTransferType(), buffDest.getColorModel().getTransferType()); assertEquals( buffSrc.getColorModel().getTransparency(), buffDest.getColorModel().getTransparency()); } catch (IOException e) { fail("cannot compare the 2 images"); } finally { result.delete(); } }
private void setup() throws IOException, UnsupportedAudioFileException, LineUnavailableException { startSounds(); tracker = new MediaTracker(this); fishImages[0] = ImageIO.read(getClass().getResourceAsStream("fish1.gif")); tracker.addImage(fishImages[0], 0); fishImages[1] = ImageIO.read(getClass().getResourceAsStream("fish2.gif")); tracker.addImage(fishImages[1], 0); aquariumImage = ImageIO.read(getClass().getResourceAsStream("tank.png")); tracker.addImage(aquariumImage, 0); try { tracker.waitForID(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } setSize(aquariumImage.getWidth(this), aquariumImage.getHeight(this)); setResizable(true); setVisible(true); memoryImage = createImage(getSize().width, getSize().height); memoryGraphics = memoryImage.getGraphics(); }
public Karte(Frontend frontend, D_Karte daten) { this.frontend = frontend; this.daten = daten; String pfadBild = "daten//felder"; String pfadRessource = "daten//ressourcen"; String pfadEinheit = "daten//einheiten"; String pfadStadt = "daten//stadt"; try { bildFeldGewaehlt = ImageIO.read(new File(pfadBild, "gewaehlt.png")); bildFeldMarkiert = ImageIO.read(new File(pfadBild, "markiert.png")); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } dateienEinlesen(pfadBild, bildFeld); dateienEinlesen(pfadRessource, bildRessource); dateienEinlesen(pfadEinheit, bildEinheit); dateienEinlesen(pfadStadt, bildStadt); int spielfeldGroesse = frontend.getSpielfeldGroesse(); int zoomfaktor = frontend.getZoomfaktor(); int offset = spielfeldGroesse * zoomfaktor / 100; setLayout(null); setPreferredSize(new Dimension(getGroesseX() * offset, getGroesseY() * offset)); felder = new Feld[getGroesseX() + 1][getGroesseY() + 1]; for (int i = 1; i <= getGroesseX(); i++) { for (int j = 1; j <= getGroesseY(); j++) { Feld f = new Feld(frontend, i, j); felder[i][j] = f; add(f); } } }
/** * Loads an image from the supplied input stream. Supports formats supported by {@link ImageIO} * but not {@link FastImageIO}. */ protected static BufferedImage loadImage(InputStream iis) throws IOException { BufferedImage image; if (iis instanceof ImageInputStream) { image = ImageIO.read(iis); } else { // if we don't already have an image input stream, create a memory cache image input // stream to avoid causing freakout if we're used in a sandbox because ImageIO // otherwise use FileCacheImageInputStream which tries to create a temp file MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(iis); image = ImageIO.read(mciis); try { // this doesn't close the underlying stream mciis.close(); } catch (IOException ioe) { // ImageInputStreamImpl.close() throws an IOException if it's already closed; // there's no way to find out if it's already closed or not, so we have to check // the exception message to determine if this is actually warning worthy if (!"closed".equals(ioe.getMessage())) { log.warning("Failure closing image input '" + iis + "'.", ioe); } } } // finally close our input stream StreamUtil.close(iis); return image; }
public static BufferedImage encodeImage(String filename, int[] primes) { /* encodes a and b in the image using a sequence. * We are assuming that the image would be big enough * to hold the 16 bits */ BufferedImage img, newimg = null; int[] a = convertToBinary(primes[0], 8); int[] b = convertToBinary(primes[1], 8); int[] a_b = copyBits(a, b); // copy all bits into one array try { img = ImageIO.read(new File(imagePath + filename)); for (int i = 0; i < a_b.length; i++) { int p = img.getRGB(i, i); int[] bin = convertToBinary(p, 32); bin[0] = a_b[i]; int d = convertToDigit(bin, 32); img.setRGB(i, i, d); } ImageIO.write(img, "png", new File(imagePath + "new_" + filename)); newimg = ImageIO.read(new File(imagePath + "new_" + filename)); } catch (IOException e) { System.out.println("ERROR WRITING IMAGE...\n" + e.toString()); System.exit(1); } return newimg; }
private BufferedImage getImageIcon(String fileName) throws KettleException { InputStream inputStream = null; try { BufferedImage image = ImageIO.read(new File(fileName)); if (image == null) { image = ImageIO.read(new File("/" + fileName)); } if (image == null) { inputStream = getClass().getResourceAsStream(fileName); if (inputStream == null) { inputStream = getClass().getResourceAsStream("/" + fileName); } if (inputStream == null) { throw new KettleException("Unable to load image from file : '" + fileName + "'"); } image = ImageIO.read(inputStream); } WaitingImageObserver observer = new WaitingImageObserver(image); observer.waitImageLoaded(); return image; } catch (Throwable e) { throw new KettleException("Unable to load image from file : '" + fileName + "'", e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { throw new KettleException("Unable to close image reading stream", e); } } } }
public Rect(int x, int y, Color color, int width, int height, String bokstav_) { this.x = x; this.y = y; this.width = width; this.height = height; this.color = color; this.bokstav = bokstav_; this.alive = false; // ... Initiate Images try { image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("Untitled-10.png")); } catch (IOException ex) { } try { alive_image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("Untitled-12.png")); } catch (IOException ex) { } try { dead_image = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream("Untitled-11.png")); } catch (IOException ex) { } }
public static void main(String[] args) throws IOException { File path = new File("Java\\Emulator\\src\\main\\com\\nikonhacker\\gui\\images\\viewfinder_lcd"); // load source images BufferedImage image = ImageIO.read(new File(path, "off.png")); // create the new image, canvas size is the max. of both image sizes int w = image.getWidth(); int h = image.getHeight(); BufferedImage result = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); // paint both images, preserving the alpha channels Graphics g = result.getGraphics(); g.drawImage(image, 0, 0, null); String input = "0x00 0x00 0x06 0x3D 0x0B 0xDF 0xD0 0x02 0x7A 0xFF 0x07 0xD3 0xD3 0xD4 0x00"; String[] values = input.trim().split("[\\s,]+"); int byteNumber = 0; for (String value : values) { if (byteNumber > 0 && byteNumber < 14) { // Ignore byte 0 and 14 try { int bValue = Format.parseUnsigned(value); for (int bitNumber = 0; bitNumber < 8; bitNumber++) { if (Format.isBitSet(bValue, bitNumber)) { File overlayFile = new File(path, byteNumber + "_" + bitNumber + ".png"); if (!overlayFile.exists()) { System.err.println("Missing file: " + overlayFile.getName()); } else { BufferedImage overlay = ImageIO.read(overlayFile); if (overlay.getWidth() != w || overlay.getHeight() != h) { System.err.println( "Wrong file size for " + overlayFile.getName() + ": " + overlay.getWidth() + "x" + overlay.getHeight() + " instead of " + w + "x" + h); } else { g.drawImage(overlay, 0, 0, null); } } } } } catch (ParsingException e) { System.err.println("Cannot parse value: " + value); } } byteNumber += 1; } // Save as new image ImageIO.write(result, "PNG", new File(path, "result1.png")); }
/** * Loads the tileset defined in the constructor into a JPanel which it then returns. Makes no * assumptions about height or width, which means it needs to read an extra 64 tiles at worst (32 * down to check height and 32 across for width), since the maximum height/width is 32 tiles. */ public JPanel loadTileset() { int height = MAX_TILESET_SIZE; int width = MAX_TILESET_SIZE; boolean maxHeight = false; boolean maxWidth = false; // find width int j = 0; while (!maxWidth) { try { File f = new File(tileDir + "/" + j + "_" + 0 + ".png"); ImageIO.read(f); } catch (IOException e) { width = j; maxWidth = true; } j += TILE_SIZE; } // find height int i = 0; while (!maxHeight) { try { File f = new File(tileDir + "/" + 0 + "_" + i + ".png"); ImageIO.read(f); } catch (IOException e) { height = i; maxHeight = true; } i += TILE_SIZE; } JPanel tileDisplay = new JPanel(); tileDisplay.setLayout(new GridLayout(height / TILE_SIZE, width / TILE_SIZE)); tileDisplay.setMinimumSize(new Dimension(width, height)); tileDisplay.setPreferredSize(new Dimension(width, height)); tileDisplay.setMaximumSize(new Dimension(width, height)); for (i = 0; i < height; i += TILE_SIZE) { for (j = 0; j < width; j += TILE_SIZE) { String fPath = tileDir + "/" + j + "_" + i; try { int[] mov = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; Image icon = getTile(tileDir, j, i, 1); Tile tile = new Tile(new ImageIcon(icon), "palette", 0, 0, mov, "none", false, "" + j + "_" + i); tile.addMouseListener(new PaletteButtonListener()); tile.setMaximumSize(new Dimension(TILE_SIZE, TILE_SIZE)); tile.setPreferredSize(new Dimension(TILE_SIZE, TILE_SIZE)); tile.setMinimumSize(new Dimension(TILE_SIZE, TILE_SIZE)); tileDisplay.add(tile); } catch (IOException e) { } } } return tileDisplay; }