jpg合成gif

master
luffy9412 7 years ago
parent 036bde16c2
commit 117f7bef7c
  1. 28
      core/src/main/java/org/pqh/gif/PixivUtil.java

@ -17,7 +17,6 @@ import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@ -46,7 +45,7 @@ public class PixivUtil implements LogManger{
BufferedOutputStream bos = null;
ZipFile zipFile = null;
String imageUrl=baseUrl+illust_id;
String path=null;
String path;
try {
log.info("图片链接:"+imageUrl);
Connection.Response response=Jsoup.connect(imageUrl).cookie("PHPSESSID",phpsessid).execute();
@ -91,7 +90,8 @@ public class PixivUtil implements LogManger{
while ((count = is.read(buf)) > -1) {
bos.write(buf, 0, count);
}
bos.close();
is.close();
ImageIO.write(ImageIO.read(imgFile),"png",new File(imgPath.replace("jpg","png")));
}
@ -114,15 +114,7 @@ public class PixivUtil implements LogManger{
e.printStackTrace();
}finally {
try {
if(bos != null){
bos.close();
}
if(fos != null) {
fos.close();
}
if(is != null){
is.close();
}
if(zipFile != null){
zipFile.close();
}
@ -153,6 +145,7 @@ public class PixivUtil implements LogManger{
*/
public static void jpgToGif(String gifName,String jpgPath,JsonNode node){
AnimatedGifEncoder animatedGifEncoder=new AnimatedGifEncoder();
OutputStream outputStream= null;
InputStream inputStream=null;
File file=new File(jpgPath);
@ -180,8 +173,8 @@ public class PixivUtil implements LogManger{
//把帧添加进去合成
animatedGifEncoder.addFrame(image);
animatedGifEncoder.setDelay(delay);
log.info(gifName+":正在合成第"+((index+1)+"帧"));
inputStream.close();
}
//添加完所有帧开始合成
animatedGifEncoder.finish();
@ -197,17 +190,10 @@ public class PixivUtil implements LogManger{
if(outputStream!=null){
outputStream.close();
}
if(inputStream!=null){
inputStream.close();
}
FileUtils.deleteDirectory(file);
while (!FileUtils.deleteQuietly(file)){
TimeUnit.SECONDS.sleep(1);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

Loading…
Cancel
Save