解析dcm文件生成jpg上传七牛云,及按比例的缩略图
所需jar包: dcm4che-core-3.3.8.jar dcm4che-image-3.3.8.jar dcm4che-imageio-3.3.8.jar dcm4che-tool-dcm2jpg-3.3.8.jar ij.jar /** * 输入一个dicom文件的绝对路径和名字 * 获取一个jpg文件 */ public static void uploadByObs(String filePath,String fileName) { try { DICOM dicom = new DICOM(); dicom.run(filePath); BufferedImage bi = (BufferedImage) dicom.getImage(); ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流 ImageIO.write(bi, "jpg", baos);//写入流中 byte[] bytes = baos.toByteArray();//转换成字节 BASE64Encoder encoder = new BASE64Encoder(); String png_base64 = encoder.encodeBuffer(bytes).trim();//转换成base64串 png_base64 = png_base64.replaceAll(" ", "").replaceAll(" ", "");//删除 Qiuyun.put64image(png_base64,fileName + ".jpg"); } catch (Exception e) { System.out.println("错误" + e.getMessage()); } } public static void uploadThumbnailImageByObs(String filePath,String fileName,int w, int h, String prevfix) { try { DICOM dicom = new DICOM(); dicom.run(filePath); BufferedImage bi = (BufferedImage) dicom.getImage(); ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流 ImageIO.write(bi, "jpg", baos);//写入流中 byte[] bytes = baos.toByteArray();//转换成字节 ByteArrayInputStream png_InputStream= new ByteArrayInputStream(bytes); BASE64Encoder encoder = new BASE64Encoder(); ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream();//io流 Thumbnails.of(png_InputStream).size(w,h).toOutputStream(fileOutputStream);//按比例缩小. byte[] thumbnailbytes = fileOutputStream.toByteArray();//转换成字节 String thumbnail_base64 = encoder.encodeBuffer(thumbnailbytes).trim();//转换成base64串 thumbnail_base64 = thumbnail_base64.replaceAll(" ", "").replaceAll(" ", "");//删除 ObsKit.put64image(thumbnail_base64,fileName + ".jpg" + prevfix); } catch (Exception e) { System.out.println("错误" + e.getMessage()); } }
上一篇:
IDEA上Java项目控制台中文乱码