二进制流转成图片

第一种方式:                        List<PictureInfo> pictureInfo=new ArrayList<PictureInfo>();
		                    int picToPdf=0;
		                  try {
			            PictureService pictureService=new PictureServiceImpl();
			            pictureInfo=pictureService.getImage(picToPdf);
			            System.out.println("------"+pictureInfo.size());
			        for(int i=1;i<pictureInfo.size();i++){
				InputStream in=null;
				PictureInfo pictureinfo=new PictureInfo();
				pictureinfo=pictureInfo.get(i);
				if(pictureinfo != null){
        			String contentA = new String(pictureinfo.getSignPic().getBytes((long)1, (int)pictureinfo.getSignPic().length()));
        			in = new ByteArrayInputStream(PdfToByte16Util.hexStringToByte(contentA));
        			BufferedImage image = ImageIO.read(in);
        			Image images = (Image)image;
第二种方式:                        	String photoPath=uploadimg.getPhotoPath();
					byte[] img=image2byte(photoPath);//读取photopath本地路径下图片,读出的是byte类型
					try {
						image=image.getInstance(img);//将byte类型的转成图片

					} catch (BadElementException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					images.add(image)


  public static byte[] image2byte(String path){
	    byte[] data = null;
	    FileImageInputStream input = null;
	    try {
	      input = new FileImageInputStream(new File(path));
	      ByteArrayOutputStream output = new ByteArrayOutputStream();
	      byte[] buf = new byte[1024];
	      int numBytesRead = 0;
	      while ((numBytesRead = input.read(buf)) != -1) {
	      output.write(buf, 0, numBytesRead);
	      }
	      data = output.toByteArray();
	      output.close();
	      input.close();
	    }
	    catch (FileNotFoundException ex1) {
	      ex1.printStackTrace();
	    }
	    catch (IOException ex1) {
	      ex1.printStackTrace();
	    }
	    return data;
	  }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值