/** 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);
   }
 }
  /** 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!");
    }
  }
  /**
   * Gets pixel data of an <code>IIOImage</code> object.
   *
   * @param image an <code>IIOImage</code> object
   * @return a byte buffer of pixel data
   * @throws Exception
   */
  public static ByteBuffer getImageByteBuffer(IIOImage image) throws IOException {
    // Set up the writeParam
    TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
    tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);

    // Get tif writer and set output to file
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(TIFF_FORMAT);
    ImageWriter writer = writers.next();

    if (writer == null) {
      throw new RuntimeException(
          "Need to install JAI Image I/O package.\nhttps://jai-imageio.dev.java.net");
    }

    // Get the stream metadata
    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(tiffWriteParam);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream);
    writer.setOutput(ios);
    writer.write(
        streamMetadata, new IIOImage(image.getRenderedImage(), null, null), tiffWriteParam);
    //        writer.write(image.getRenderedImage());
    writer.dispose();
    //        ImageIO.write(image.getRenderedImage(), "tiff", ios); // this can be used in lieu of
    // writer
    ios.seek(0);
    BufferedImage bi = ImageIO.read(ios);
    return convertImageData(bi);
  }
  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;
  }
  /**
   * Gets a list of <code>IIOImage</code> objects for an image file.
   *
   * @param imageFile input image file. It can be any of the supported formats, including TIFF,
   *     JPEG, GIF, PNG, BMP, JPEG, and PDF if GPL Ghostscript is installed
   * @return a list of <code>IIOImage</code> objects
   * @throws Exception
   */
  public static List<IIOImage> getIIOImageList(File imageFile) throws IOException {
    File workingTiffFile = null;

    ImageReader reader = null;
    ImageInputStream iis = null;

    try {
      // convert PDF to TIFF
      if (imageFile.getName().toLowerCase().endsWith(".pdf")) {
        workingTiffFile = PdfUtilities.convertPdf2Tiff(imageFile);
        imageFile = workingTiffFile;
      }

      List<IIOImage> iioImageList = new ArrayList<IIOImage>();

      String imageFileName = imageFile.getName();
      String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);
      if (imageFormat.matches("(pbm|pgm|ppm)")) {
        imageFormat = "pnm";
      } else if (imageFormat.equals("jp2")) {
        imageFormat = "jpeg2000";
      }
      Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat);
      reader = readers.next();

      if (reader == null) {
        throw new RuntimeException(
            "Need to install JAI Image I/O package.\nhttps://jai-imageio.dev.java.net");
      }

      iis = ImageIO.createImageInputStream(imageFile);
      reader.setInput(iis);

      int imageTotal = reader.getNumImages(true);

      for (int i = 0; i < imageTotal; i++) {
        //                IIOImage oimage = new IIOImage(reader.read(i), null,
        // reader.getImageMetadata(i));
        IIOImage oimage = reader.readAll(i, reader.getDefaultReadParam());
        iioImageList.add(oimage);
      }

      return iioImageList;
    } finally {
      try {
        if (iis != null) {
          iis.close();
        }
        if (reader != null) {
          reader.dispose();
        }
      } catch (Exception e) {
        // ignore
      }
      if (workingTiffFile != null && workingTiffFile.exists()) {
        workingTiffFile.delete();
      }
    }
  }
  /**
   * 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;
  }
 /**
  * Takes a filepath to a tileset folder, x, y coordinates and a scale and returns the desired
  * tile.
  */
 public static Image getTile(String filepath, int x, int y, int scale) throws IOException {
   // System.out.println(filepath+"/"+x+"_"+y);
   try {
     return scaleImage(ImageIO.read(new File(filepath + "/" + x + "_" + y + ".png")), scale);
   } catch (IOException e) {
     return scaleImage(ImageIO.read(new File(filepath + "/" + x + "_" + y)), scale);
   }
 }
Exemple #8
0
 public void save(File file) throws IOException {
   if (file.getName().endsWith(".gif")) {
     ImageIO.write(_i, "png", file);
   } else if (file.getName().endsWith(".jpg")) {
     ImageIO.write(_i, "jpg", file);
   } else {
     if (!file.getName().endsWith(".png")) {
       file = new File(file.toString() + ".png");
     }
     ImageIO.write(_i, "png", file);
   }
 }
Exemple #9
0
  // *********************************************************************************
  public static void main(String[] args) throws IOException {
    // read into BufferedImage
    BufferedImage image = ImageIO.read(file); // File, InputStream, or URL

    // read pixels into an array
    pictureArray = readIntoArray(image);

    image = depleteRed(pictureArray, image);

    // write to file
    ImageIO.write(image, "jpg", new File("new.jpg"));
  }
  /**
   * Creates a list of TIFF image files from an image file. It basically converts images of other
   * formats to TIFF format, or a multi-page TIFF image to multiple TIFF image files.
   *
   * @param imageFile input image file
   * @param index an index of the page; -1 means all pages, as in a multi-page TIFF image
   * @return a list of TIFF image files
   * @throws Exception
   */
  public static List<File> createTiffFiles(File imageFile, int index) throws IOException {
    List<File> tiffFiles = new ArrayList<File>();

    String imageFileName = imageFile.getName();
    String imageFormat = imageFileName.substring(imageFileName.lastIndexOf('.') + 1);

    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(imageFormat);
    ImageReader reader = readers.next();

    if (reader == null) {
      throw new RuntimeException(
          "Need to install JAI Image I/O package.\nhttps://jai-imageio.dev.java.net");
    }

    ImageInputStream iis = ImageIO.createImageInputStream(imageFile);
    reader.setInput(iis);
    // Read the stream metadata
    //        IIOMetadata streamMetadata = reader.getStreamMetadata();

    // Set up the writeParam
    TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
    tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);

    // Get tif writer and set output to file
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(TIFF_FORMAT);
    ImageWriter writer = writers.next();

    // Read the stream metadata
    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(tiffWriteParam);

    int imageTotal = reader.getNumImages(true);

    for (int i = 0; i < imageTotal; i++) {
      // all if index == -1; otherwise, only index-th
      if (index == -1 || i == index) {
        //                BufferedImage bi = reader.read(i);
        //                IIOImage oimage = new IIOImage(bi, null, reader.getImageMetadata(i));
        IIOImage oimage = reader.readAll(i, reader.getDefaultReadParam());
        File tiffFile = File.createTempFile(OUTPUT_FILE_NAME, TIFF_EXT);
        ImageOutputStream ios = ImageIO.createImageOutputStream(tiffFile);
        writer.setOutput(ios);
        writer.write(streamMetadata, oimage, tiffWriteParam);
        ios.close();
        tiffFiles.add(tiffFile);
      }
    }
    writer.dispose();
    reader.dispose();

    return tiffFiles;
  }
Exemple #11
0
 /**
  * Returns the specified image.
  *
  * @param url image url
  * @return image
  */
 public static Image get(final URL url) {
   try {
     return ImageIO.read(url);
   } catch (final IOException ex) {
     throw Util.notExpected(ex);
   }
 }
Exemple #12
0
 /*======== public void save() ==========
 Inputs:  String filename
 Returns:
 saves the bufferedImage as a png file with the given filename
 ====================*/
 public void save(String filename) {
   try {
     File fn = new File(filename);
     ImageIO.write(bi, "png", fn);
   } catch (IOException e) {
   }
 }
Exemple #13
0
  public void readImg(String in) {
    try {
      character = ImageIO.read(new File(in));
    } catch (IOException e) {

    }
  }
 public PanImage1() {
   try {
     image = ImageIO.read(new File("WALLPAPER02.jpg"));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
    public VideoTrack(PullSourceStream stream) throws ResourceUnavailableException {
      super();

      this.stream = stream;
      // set format

      // read first frame to determine format
      final Buffer buffer = new Buffer();
      readFrame(buffer);
      if (buffer.isDiscard() || buffer.isEOM())
        throw new ResourceUnavailableException("Unable to read first frame");
      // TODO: catch runtime exception too?

      // parse jpeg
      final java.awt.Image image;
      try {
        image =
            ImageIO.read(
                new ByteArrayInputStream(
                    (byte[]) buffer.getData(), buffer.getOffset(), buffer.getLength()));
      } catch (IOException e) {
        logger.log(Level.WARNING, "" + e, e);
        throw new ResourceUnavailableException("Error reading image: " + e);
      }

      if (image == null) {
        logger.log(Level.WARNING, "Failed to read image (ImageIO.read returned null).");
        throw new ResourceUnavailableException();
      }

      if (frameContentType.equals("image/jpeg"))
        format =
            new JPEGFormat(
                new Dimension(image.getWidth(null), image.getHeight(null)),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                -1.f,
                Format.NOT_SPECIFIED,
                Format.NOT_SPECIFIED);
      else if (frameContentType.equals("image/gif"))
        format =
            new GIFFormat(
                new Dimension(image.getWidth(null), image.getHeight(null)),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                -1.f);
      else if (frameContentType.equals("image/png"))
        format =
            new PNGFormat(
                new Dimension(image.getWidth(null), image.getHeight(null)),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                -1.f);
      else
        throw new ResourceUnavailableException(
            "Unsupported frame content type: " + frameContentType);
      // TODO: this discards first image. save and return first time
      // readFrame is called.

    }
 public void init() throws Exception {
   table = ImageIO.read(new File("image/board.jpg"));
   black = ImageIO.read(new File("image/black.gif"));
   white = ImageIO.read(new File("image/white.gif"));
   selected = ImageIO.read(new File("image/selected.gif"));
   // 把每个元素赋为"╋",用于在控制台画出棋盘
   for (int i = 0; i < BOARD_SIZE; i++) {
     for (int j = 0; j < BOARD_SIZE; j++) {
       board[i][j] = "╋";
     }
   }
   chessBoard.setPreferredSize(new Dimension(TABLE_WIDTH, TABLE_HETGHT));
   chessBoard.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           // 将用户鼠标事件的座标转换成棋子数组的座标。
           int xPos = (int) ((e.getX() - X_OFFSET) / RATE);
           int yPos = (int) ((e.getY() - Y_OFFSET) / RATE);
           board[xPos][yPos] = "●";
           /*
           电脑随机生成2个整数,作为电脑下棋的座标,赋给board数组。
           还涉及:
           1.如果下棋的点已经棋子,不能重复下棋。
           2.每次下棋后,需要扫描谁赢了
           */
           chessBoard.repaint();
         }
         // 当鼠标退出棋盘区后,复位选中点座标
         public void mouseExited(MouseEvent e) {
           selectedX = -1;
           selectedY = -1;
           chessBoard.repaint();
         }
       });
   chessBoard.addMouseMotionListener(
       new MouseMotionAdapter() {
         // 当鼠标移动时,改变选中点的座标
         public void mouseMoved(MouseEvent e) {
           selectedX = (e.getX() - X_OFFSET) / RATE;
           selectedY = (e.getY() - Y_OFFSET) / RATE;
           chessBoard.repaint();
         }
       });
   f.add(chessBoard);
   f.pack();
   f.setVisible(true);
 }
  public PanImage2() {
    try {
      image2 = ImageIO.read(new File("Initial.D.full.501729.jpg"));

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemple #18
0
  /**
   * Write a BufferedImage to a File.
   *
   * @param image image to be written
   * @param fileName name of file to be created
   * @exception IOException if an error occurs during writing
   */
  public static void writeImage(BufferedImage image, String fileName) throws IOException {
    if (fileName == null) return;

    int offset = fileName.lastIndexOf(".");
    String type = offset == -1 ? "png" : fileName.substring(offset + 1);

    ImageIO.write(image, type, new File(fileName));
  }
Exemple #19
0
  public ImageIODecoder(String formatName) {
    super();
    this.formatName = formatName;

    if (!ImageIO.getImageReadersByFormatName(formatName).hasNext()) {
      throw new RuntimeException("No ImageIO reader found for " + formatName);
    }
  }
  public void initialize() {

    // openLevelFile images:
    try {
      boxSpriteSheet = ImageIO.read(new File("ItemContainer.png"));
      coinSpriteSheet = ImageIO.read(new File("Coin.png"));
    } catch (Exception e) {
    }

    if (openLevelFile == false) {
      try {
        loadLevel(initLevel);
      } catch (Exception e) {
        System.out.println(e);
      }
    } else {
      loadLevel(FileOpenDialog("Open ..."));
    }

    // create tile layer:
    renderTileLayer();

    // create bg layer:
    backgroundLayer = new VolatileImage[backgroundImage.length];

    // render layer:
    for (int i = 0; i < backgroundImage.length; i++) {
      renderBackgroundLayer(0);
      renderBackgroundLayer(1);
    }

    // create hardware accellerated rendering layer:
    renderImage =
        this.getGraphicsConfiguration()
            .createCompatibleVolatileImage(
                loadedLevel.getWidth() * 16,
                loadedLevel.getHeight() * 16,
                Transparency.TRANSLUCENT);
    Graphics2D g2d = renderImage.createGraphics();
    g2d.setComposite(AlphaComposite.Src);

    // Clear the image.
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, renderImage.getWidth(), renderImage.getHeight());
    g2d.setBackground(new Color(0, 0, 0, 0));
  }
 public void save(String filename, String type) {
   try {
     ImageIO.write(img, type, new File(filename + "." + type));
     System.out.println("Saving under " + filename + "." + type);
   } catch (Exception e) {
     System.out.println("Kann Datei " + filename + "." + type + " nicht anlegen");
   }
 }
  public PanImage3() {
    try {
      image3 = ImageIO.read(new File("sleeping_dogs_2012_video_game-wallpaper-1024x768.jpg"));

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /** Open a file and load the image. */
  public void openFile() {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    String[] extensions = ImageIO.getReaderFileSuffixes();
    chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions));
    int r = chooser.showOpenDialog(this);
    if (r != JFileChooser.APPROVE_OPTION) return;

    try {
      Image img = ImageIO.read(chooser.getSelectedFile());
      image =
          new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
      image.getGraphics().drawImage(img, 0, 0, null);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(this, e);
    }
    repaint();
  }
 protected byte[] toImageData(final BufferedImage image) {
   try {
     final ByteArrayOutputStream out = new ByteArrayOutputStream();
     ImageIO.write(image, this.format, out);
     return out.toByteArray();
   } catch (IOException e) {
     throw new WicketRuntimeException("Unable to convert dynamic image to stream", e);
   }
 }
  public static boolean compressPic(String srcFilePath, String descFilePath) {
    File file = null;
    BufferedImage src = null;
    FileOutputStream out = null;
    ImageWriter imgWrier;
    ImageWriteParam imgWriteParams;

    // 指定写图片的方式为 jpg
    imgWrier = ImageIO.getImageWritersByFormatName("jpg").next();
    imgWriteParams = new javax.imageio.plugins.jpeg.JPEGImageWriteParam(null);
    // 要使用压缩,必须指定压缩方式为MODE_EXPLICIT
    imgWriteParams.setCompressionMode(imgWriteParams.MODE_EXPLICIT);
    // 这里指定压缩的程度,参数qality是取值0~1范围内,
    imgWriteParams.setCompressionQuality((float) 0.1);
    imgWriteParams.setProgressiveMode(imgWriteParams.MODE_DISABLED);
    ColorModel colorModel = ColorModel.getRGBdefault();
    // 指定压缩时使用的色彩模式
    imgWriteParams.setDestinationType(
        new javax.imageio.ImageTypeSpecifier(
            colorModel, colorModel.createCompatibleSampleModel(16, 16)));

    try {
      if (StringUtils.isBlank(srcFilePath)) {
        return false;
      } else {
        file = new File(srcFilePath);
        src = ImageIO.read(file);
        out = new FileOutputStream(descFilePath);

        imgWrier.reset();
        // 必须先指定 out值,才能调用write方法, ImageOutputStream可以通过任何 OutputStream构造
        imgWrier.setOutput(ImageIO.createImageOutputStream(out));
        // 调用write方法,就可以向输入流写图片
        imgWrier.write(null, new IIOImage(src, null, null), imgWriteParams);
        out.flush();
        out.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
  public static List<File> createTiffFiles(List<IIOImage> imageList, int index, int dpiX, int dpiY)
      throws IOException {
    List<File> tiffFiles = new ArrayList<File>();

    // Set up the writeParam
    TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
    tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_DISABLED);

    // Get tif writer and set output to file
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(TIFF_FORMAT);
    ImageWriter writer = writers.next();

    if (writer == null) {
      throw new RuntimeException(
          "Need to install JAI Image I/O package.\nhttps://jai-imageio.dev.java.net");
    }

    // Get the stream metadata
    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(tiffWriteParam);

    // all if index == -1; otherwise, only index-th
    for (IIOImage oimage : (index == -1 ? imageList : imageList.subList(index, index + 1))) {
      if (dpiX != 0 && dpiY != 0) {
        // Get the default image metadata.
        ImageTypeSpecifier imageType =
            ImageTypeSpecifier.createFromRenderedImage(oimage.getRenderedImage());
        IIOMetadata imageMetadata = writer.getDefaultImageMetadata(imageType, null);
        imageMetadata = setDPIViaAPI(imageMetadata, dpiX, dpiY);
        oimage.setMetadata(imageMetadata);
      }

      File tiffFile = File.createTempFile(OUTPUT_FILE_NAME, TIFF_EXT);
      ImageOutputStream ios = ImageIO.createImageOutputStream(tiffFile);
      writer.setOutput(ios);
      writer.write(streamMetadata, oimage, tiffWriteParam);
      ios.close();
      tiffFiles.add(tiffFile);
    }
    writer.dispose();

    return tiffFiles;
  }
  private void Timer(ActionEvent evt) {
    // TODO Auto-generated method stub
    try {
      int minBus = 110;
      int maxBus = 120;
      double minAfkLat = 42.302;
      double maxAfkLat = 42.304;
      System.out.println("Timer");
      timer.stop();
      MapMarker init = new MapMarker(theLatitude, theLongitude);
      String theMapURIAsString =
          (String) MapLookup.getMap(theLatitude, theLongitude, init).substring(0, 87);
      int testint2 = 0;
      for (Listener l : theListeners) {
        // if(l.Latitude != 9999 && Float.parseFloat(l.BusID.split("#")[1]) < maxBus &&
        // Float.parseFloat(l.BusID.split("#")[1]) > minBus)    //Bussar beroende på buss nummer
        // if(l.Latitude != 9999 && l.Latitude > minAfkLat && l.Latitude < maxAfkLat)
        // //Possible afk busses
        // if(l.Latitude != 9999 && ( l.Latitude < minAfkLat || l.Latitude > maxAfkLat))
        // //Exclude afk busses
        if (l.Latitude != 9999.0) // All busses
        {
          theMapURIAsString += "|";
          theMapURIAsString += Float.toString(l.Latitude) + "," + Float.toString(l.Longitude);
        }
      }
      theMapURIAsString += "&sensor=false&key=AIzaSyBR_wUAQ3iPM2e8WeoQIUw9c3xLJPRGZL8";
      // System.out.println("HEIR COWMES F****R\n" + theMapURIAsString + "\nFUCKER IS COMMEN");

      String[] GetRidOfinitMarker = theMapURIAsString.split("42.358543,-71.096178\\|");
      // String[] GetRidOfinitMarker = theMapURIAsString.split("42.303113,-71.109925\\|"); //afk
      // bussar
      String GottenRidOfinitMarker = GetRidOfinitMarker[0] + GetRidOfinitMarker[1];

      String test = theMapURIAsString.split("&markers=")[1];
      String[] testa = test.split("\\|");
      // for(String v : testa)System.out.println(v);  //alla inkomna positioner
      // Retrieve map from Google Maps.
      // URL theMapURI = new URL(theMapURIAsString);
      URL theMapURI = new URL(GottenRidOfinitMarker); // URL Utan init marker
      theMap = ImageIO.read(theMapURI.openStream());

      // Create map image scaled to size of the application window size.
      imagePanel1.setImage(
          theMap.getScaledInstance(
              imagePanel1.getWidth(), imagePanel1.getHeight(), Image.SCALE_AREA_AVERAGING));

      // Display map image.
      imagePanel1.repaint();
    } catch (Exception ex) {
      timer.start();
    }
    timer.start();
  }
 public void paintComponent(Graphics g) {
   if (paint) {
     try {
       Rectangle vis = getVisibleRect();
       File fi = ImageLoader.getFile("images/inventoryback.png");
       BufferedImage bg = ImageIO.read(fi.toURL());
       g.drawImage(bg, vis.x, vis.y, null);
     } catch (Exception e) {
     }
   }
 }
Exemple #29
0
  // Запись временного файла - картинки по определенному пути ( с указанием имени и типа )
  public File writeImageToFile(BufferedImage bi_src, String s_type, String s_path, String s_name)
      throws IOException {
    if ((s_type == null) || ((s_type.indexOf("png") == -1) && (s_type.indexOf("jpg") == -1))) {
      s_type = "jpg";
    }

    File res_file = new File(s_path + s_name + "." + s_type);
    ImageIO.write(bi_src, s_type, res_file);

    return res_file;
  }
Exemple #30
0
 public static void main(String[] args) throws Exception {
   Robot robot = new Robot(args[0]);
   BufferedImage oimg = robot.cam.capture(true);
   // BufferedImage img = maslab.camera.ImageUtil.convertImage(oimg, BufferedImage.TYPE_INT_RGB);
   BufferedImage img =
       new BufferedImage(oimg.getWidth(), oimg.getHeight(), BufferedImage.TYPE_INT_RGB);
   for (int y = 0; y < oimg.getHeight(); ++y) {
     for (int x = 0; x < oimg.getWidth(); ++x) {
       img.setRGB(x, y, oimg.getRGB(x, y));
     }
   }
   BufferedImage blurred = gaussianBlur(img);
   ImageIO.write(blurred, "bmp", new File("gaussian.bmp"));
   BufferedImage xe = sobelX(blurred);
   ImageIO.write(xe, "bmp", new File("sobelx.bmp"));
   BufferedImage ye = sobelY(blurred);
   ImageIO.write(ye, "bmp", new File("sobely.bmp"));
   BufferedImage edges = addMagnitudes(xe, ye);
   BufferedImage dst = edges;
   ImageIO.write(dst, "bmp", new File("edges.bmp"));
 }