package test;

import java.io.IOException;

import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class ImageUtils {

    /**
     * Decode string to image
     * @param imageString The string to decode
     * @return decoded image
     */
    public static BufferedImage decodeToImage(String imageString) {

        BufferedImage image = null;
        byte[] imageByte;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(imageString);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
            image = ImageIO.read(bis);
            bis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return image;
    }

    /**
     * Encode image to string
     * @param image The image to encode
     * @param type jpeg, bmp, ...
     * @return encoded string
     */
    public static String encodeToString(BufferedImage image, String type) {
        String imageString = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        try {
            ImageIO.write(image, type, bos);
            byte[] imageBytes = bos.toByteArray();

            BASE64Encoder encoder = new BASE64Encoder();
            imageString = encoder.encode(imageBytes);

            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imageString;
    }

    public static void main (String args[]) throws IOException {
        /* Test image to string and string to image start */
        BufferedImage img = ImageIO.read(new File("files/img/TestImage.png"));
        BufferedImage newImg;
        String imgstr;
        imgstr = encodeToString(img, "png");
        System.out.println(imgstr);
        newImg = decodeToImage(imgstr);
        ImageIO.write(newImg, "png", new File("files/img/CopyOfTestImage.png"));
        /* Test image to string and string to image finish */
    }
}
저작자 표시 비영리 변경 금지
신고
Creative Commons License


>sudo apt-get update
>sudo apt-get install nodejs

설치 후 안되길래 써치해봤더니 우분투 문제.

sudo apt-get install nodejs-legacy
추가해준다.

>sudo apt-get install npm

http://askubuntu.com/questions/235655/node-js-conflicts-sbin-node-vs-usr-bin-node 
 
저작자 표시 비영리 변경 금지
신고
Creative Commons License

이것은 비디오 정보를 구하는 예제

package com.javacodegeeks.xuggler.intro; import com.xuggle.xuggler.ICodec; import com.xuggle.xuggler.IContainer; import com.xuggle.xuggler.IStream; import com.xuggle.xuggler.IStreamCoder; public class VideoInfo { private static final String filename = "c:/myvideo.mp4"; public static void main(String[] args) { // first we create a Xuggler container object IContainer container = IContainer.make(); // we attempt to open up the container int result = container.open(filename, IContainer.Type.READ, null); // check if the operation was successful if (result<0) throw new RuntimeException("Failed to open media file"); // query how many streams the call to open found int numStreams = container.getNumStreams(); // query for the total duration long duration = container.getDuration(); // query for the file size long fileSize = container.getFileSize(); // query for the bit rate long bitRate = container.getBitRate(); System.out.println("Number of streams: " + numStreams); System.out.println("Duration (ms): " + duration); System.out.println("File Size (bytes): " + fileSize); System.out.println("Bit Rate: " + bitRate); // iterate through the streams to print their meta data for (int i=0; i<numStreams; i++) { // find the stream object IStream stream = container.getStream(i); // get the pre-configured decoder that can decode this stream; IStreamCoder coder = stream.getStreamCoder(); System.out.println("*** Start of Stream Info ***"); System.out.printf("stream %d: ", i); System.out.printf("type: %s; ", coder.getCodecType()); System.out.printf("codec: %s; ", coder.getCodecID()); System.out.printf("duration: %s; ", stream.getDuration()); System.out.printf("start time: %s; ", container.getStartTime()); System.out.printf("timebase: %d/%d; ", stream.getTimeBase().getNumerator(), stream.getTimeBase().getDenominator()); System.out.printf("coder tb: %d/%d; ", coder.getTimeBase().getNumerator(), coder.getTimeBase().getDenominator()); System.out.println(); if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) { System.out.printf("sample rate: %d; ", coder.getSampleRate()); System.out.printf("channels: %d; ", coder.getChannels()); System.out.printf("format: %s", coder.getSampleFormat()); } else if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) { System.out.printf("width: %d; ", coder.getWidth()); System.out.printf("height: %d; ", coder.getHeight()); System.out.printf("format: %s; ", coder.getPixelType()); System.out.printf("frame-rate: %5.2f; ", coder.getFrameRate().getDouble()); } System.out.println(); System.out.println("*** End of Stream Info ***"); } } }


http://www.javacodegeeks.com/2011/02/xuggler-tutorial-frames-capture-video.html
http://blog.knoldus.com/2012/11/26/extract-a-frame-image-from-video-in-scala/ 
저작자 표시 비영리 변경 금지
신고
Creative Commons License

티스토리 툴바