Ray da Costa

« Encontro Agil 2009 | Home | java no iPhone »

Transformar Imagem + Texto + File Destransformar etc

de raydacosta | Sexta, 11 de Setembro de 2009

public class Image64 {

public static String imagemToString(String url) throws FileNotFoundException, IOException{
BASE64Encoder e = new BASE64Encoder();
FileImageInputStream in = new FileImageInputStream(new File(url));
int size = (int) in.length();
byte[] b = new byte[size];
in.read(b);
in.close();
ByteBuffer bb = ByteBuffer.wrap(b);
String s = e.encode(bb);
System.out.println(s.length());
return s;
}

public static byte[] stringToImagemByte(String imagem) throws FileNotFoundException, IOException{
BASE64Decoder d = new BASE64Decoder();
byte[] b = d.decodeBuffer(imagem);
return b;
}

public static void stringToImagemFile(String imagem, String url) throws FileNotFoundException, IOException{
BASE64Decoder d = new BASE64Decoder();
byte[] b = d.decodeBuffer(imagem);
FileOutputStream img = new FileOutputStream(new File(url));
img.write(b);
img.flush();
img.close();
}

}

Categorias: Java |  | Enviar por e-mail  | Hits para esta publicação: 164

Deixe uma resposta.