Bladeren bron

解决专家头像png图片保存成JPG格式会变红的问题。

zzy.zhiyuan.foxmail 8 jaren geleden
bovenliggende
commit
76d425567b
1 gewijzigde bestanden met toevoegingen van 10 en 3 verwijderingen
  1. 10 3
      src/main/java/com/ekexiu/portal/service/ImageService.java

+ 10 - 3
src/main/java/com/ekexiu/portal/service/ImageService.java

303
	@Path("/head")
303
	@Path("/head")
304
	public void saveHeadPhoto(String id, String fn,int x,int y,int w,int h) throws JfwBaseException, SQLException, IOException {
304
	public void saveHeadPhoto(String id, String fn,int x,int y,int w,int h) throws JfwBaseException, SQLException, IOException {
305
		byte[] src = this.readTmpFile(fn);
305
		byte[] src = this.readTmpFile(fn);
306
		//png图片保存为JPG格式时透明底色会变红的问题
307
//		BufferedImage im = ImageIO.read(new ByteArrayInputStream(src));
308
//		BufferedImage newBufferedImage = new BufferedImage(im.getWidth(),im.getHeight(), BufferedImage.TYPE_INT_RGB);
309
//		newBufferedImage.createGraphics().drawImage(im, 0, 0, Color.WHITE, null);
310
//		ByteArrayOutputStream os = new ByteArrayOutputStream();
311
//		ImageIO.write(newBufferedImage, "jpg", os);
312
//		src = os.toByteArray();
306
		src = JpgUtil.read(src);
313
		src = JpgUtil.read(src);
307
		ByteArrayOutputStream os = new ByteArrayOutputStream();
308
		JpgUtil.cutByPerCent(new ByteArrayInputStream(src), os, x, y, w, h);
309
		src = os.toByteArray();
314
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
315
		JpgUtil.cutByPerCent(new ByteArrayInputStream(src), bos, x, y, w, h);
316
		src = bos.toByteArray();
310
//		byte[] li = this.zoomImage(src, this.largeHeadPhotoWidth, this.largeHeadPhotoHeight);
317
//		byte[] li = this.zoomImage(src, this.largeHeadPhotoWidth, this.largeHeadPhotoHeight);
311
		byte[] mi = this.zoomImage(src, this.middleHeadPhotoWidth, this.middleHeadPhotoHeight);
318
		byte[] mi = this.zoomImage(src, this.middleHeadPhotoWidth, this.middleHeadPhotoHeight);
312
		byte[] si = this.zoomImage(src, this.smallHeadPhotoWidth, this.smallHeadPhotoHeight);
319
		byte[] si = this.zoomImage(src, this.smallHeadPhotoWidth, this.smallHeadPhotoHeight);