กรอง APNG ผ่าน Java
สร้างแอป Java ของคุณเองเพื่อกรองไฟล์ APNG โดยใช้ API ฝั่งเซิร์ฟเวอร์
วิธีการกรองไฟล์ APNG โดยใช้ Java
แม้แต่ภาพที่สมบูรณ์แบบที่สุดก็สามารถปรับปรุงเพิ่มเติมหรือแปลงเป็นผลงานศิลปะที่แตกต่างและมีเอกลักษณ์โดยสิ้นเชิงได้ ใช้ฟิลเตอร์เพื่อให้ได้เอฟเฟกต์ภาพที่หลากหลาย ตัวอย่างเช่น คุณสามารถทำให้ภาพคมชัดขึ้น หรือในทางกลับกัน เพิ่มความเบลอ ปรับให้เรียบ หรือกำจัดสัญญาณรบกวนสีได้ ฟิลเตอร์ยังมีประโยชน์อันล้ำค่าเมื่อคุณต้องการสร้างความเป็นเอกลักษณ์ให้กับภาพของคุณ เพื่อให้บรรลุเป้าหมายนี้ ให้ใช้เอฟเฟกต์ที่ต้องการหรือรวมเอฟเฟกต์ต่างๆ วิธีการนี้ช่วยให้คุณสามารถปรับแต่งการไล่ระดับสี กำจัดสัญญาณรบกวน และเพิ่มความคมชัดของขอบของวัตถุในภาพถ่ายไปพร้อมๆ กัน เพื่อกรองไฟล์ APNG เราจะใช้ Aspose.Imaging for Java API ซึ่งเป็น API การแปลงและการแปลงรูปภาพที่มีคุณลักษณะหลากหลาย มีประสิทธิภาพ และใช้งานง่ายสำหรับแพลตฟอร์ม Java คุณสามารถดาวน์โหลดเวอร์ชันล่าสุดได้โดยตรงจาก Maven และติดตั้งภายใน Maven ของคุณ - ตามโครงการโดยเพิ่มการกำหนดค่าต่อไปนี้ใน pom.xml
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>version of aspose-imaging API</version>
<classifier>jdk16</classifier>
</dependency>
ขั้นตอนในการกรอง APNGs ผ่าน Java
คุณต้องมี aspose-imaging-version-jdk16.jar เพื่อลองใช้เวิร์กโฟลว์ต่อไปนี้ในสภาพแวดล้อมของคุณเอง
- โหลดไฟล์ APNG ด้วยวิธี Image.Load
- กรองภาพ;
- บันทึกภาพที่บีบอัดลงในแผ่นดิสก์ในรูปแบบที่รองรับโดย Aspose.Imaging
ความต้องการของระบบ
Aspose.Imaging สำหรับ Java ได้รับการสนับสนุนในระบบปฏิบัติการหลักทั้งหมด เพียงตรวจสอบให้แน่ใจว่าคุณมีข้อกำหนดเบื้องต้นดังต่อไปนี้
- ติดตั้ง JDK 1.6 หรือสูงกว่า
กรองภาพ APNG - Java
import com.aspose.imaging.IMultipageImage; | |
import com.aspose.imaging.Image; | |
import com.aspose.imaging.RasterImage; | |
import com.aspose.imaging.imageoptions.PngOptions; | |
import java.io.File; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.function.Consumer; | |
medianfilter(); | |
public static void smallRectangularfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/SmallRectangularFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new SmallRectangularFilterOptions()); | |
}, "smallrectangular"); | |
} | |
public static void bigRectangularfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/BigRectangularFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new BigRectangularFilterOptions()); | |
}, "bigrectangular"); | |
} | |
public static void sharpenfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/SharpenFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new SharpenFilterOptions()); | |
}, "sharpen"); | |
} | |
public static void motionWienerfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/MotionWienerFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new MotionWienerFilterOptions(20, 2, 0)); | |
}, "motionwiener"); | |
} | |
public static void bilateralSmoothingfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/BilateralSmoothingFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new BilateralSmoothingFilterOptions()); | |
}, "bilateralsmoothing"); | |
} | |
public static void gaussBlurfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/GaussianBlurFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new GaussianBlurFilterOptions(5, 4)); | |
}, "gaussblur"); | |
} | |
public static void gaussWienerfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/GaussWienerFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new GaussWienerFilterOptions(5, 5)); | |
}, "gausswiener"); | |
} | |
public static void medianfilter() | |
{ | |
filterImages(image -> | |
{ | |
// https://apireference.aspose.com/imaging/java/com.aspose.imaging.imagefilters.filteroptions/MedianFilterOptions | |
Rectangle filterRect = new Rectangle(image.getWidth() / 6, image.getHeight() / 6, image.getWidth() * 2 / 3, image.getHeight() * 2 / 3); | |
image.filter(filterRect, new MedianFilterOptions(20)); | |
}, "median"); | |
} | |
static String templatesFolder = "D:\\"; | |
public static void filterImages(Consumer<RasterImage> doFilter, String filterName) | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", "dicom", | |
"jp2", "j2k", "tga", "webp", "tif", "gif", "ico"); | |
List<String> vectorFormats = Arrays.asList("svg", "otg", "odg", "eps", "wmf", "emf", "wmz", "emz", "cmx", "cdr"); | |
List<String> allFormats = new LinkedList<>(rasterFormats); | |
allFormats.addAll(vectorFormats); | |
allFormats.forEach( | |
formatExt -> | |
{ | |
String inputFile = templatesFolder + "template." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + String.format("%s_%s.png", filterName, formatExt); | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
doFilter.accept(image); | |
//If image is multipage save each page to png to demonstrate results | |
if (image instanceof IMultipageImage && ((IMultipageImage) image).getPageCount() > 1) | |
{ | |
IMultipageImage multiPage = (IMultipageImage) image; | |
final int pageCount = multiPage.getPageCount(); | |
final Image[] pages = multiPage.getPages(); | |
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) | |
{ | |
String fileName = String.format("%s_page%d_%s.png", filterName, pageIndex, formatExt); | |
pages[pageIndex].save(fileName, new PngOptions()); | |
} | |
} | |
else | |
{ | |
image.save(outputFile, new PngOptions()); | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
); | |
} | |
private static String rasterizeVectorImage(String formatExt, String inputFile) | |
{ | |
String outputFile = templatesFolder + "rasterized."+ formatExt + ".png"; | |
try (Image image = Image.load(inputFile)) | |
{ | |
image.save(outputFile, new PngOptions()); | |
} | |
return outputFile; | |
} |
เกี่ยวกับ Aspose.Imaging สำหรับ Java API
Aspose.Imaging API เป็นโซลูชันการประมวลผลรูปภาพเพื่อสร้าง แก้ไข วาดหรือแปลงรูปภาพ (ภาพถ่าย) ภายในแอปพลิเคชัน นำเสนอ: การประมวลผลภาพข้ามแพลตฟอร์ม รวมถึงแต่ไม่จำกัดเพียงการแปลงระหว่างรูปแบบภาพต่างๆ (รวมถึงการประมวลผลภาพแบบหลายหน้าหรือหลายเฟรมแบบเดียวกัน) การปรับเปลี่ยน เช่น การวาด การทำงานกับภาพกราฟิกดั้งเดิม การแปลงภาพ (ปรับขนาด ครอบตัด พลิกและหมุน , ไบนารี, ระดับสีเทา, ปรับ), คุณสมบัติการจัดการภาพขั้นสูง (การกรอง, การแยกสี, การปิดบัง, การเดสก์) และกลยุทธ์การปรับหน่วยความจำให้เหมาะสม เป็นไลบรารีแบบสแตนด์อโลนและไม่ขึ้นกับซอฟต์แวร์ใด ๆ สำหรับการทำงานของรูปภาพ คุณสามารถเพิ่มคุณสมบัติการแปลงรูปภาพประสิทธิภาพสูงด้วย API ดั้งเดิมภายในโปรเจ็กต์ได้อย่างง่ายดาย สิ่งเหล่านี้เป็น API ภายในองค์กรที่เป็นส่วนตัว 100% และอิมเมจได้รับการประมวลผลที่เซิร์ฟเวอร์ของคุณกรอง APNG ผ่านแอปออนไลน์
กรองเอกสาร APNG โดยไปที่ เว็บไซต์ Live Demos การสาธิตสดมีประโยชน์ดังต่อไปนี้
APNG คืออะไร APNG รูปแบบไฟล์
ไฟล์ที่มีนามสกุล .apng (Animated Portable Network Graphics) เป็นรูปแบบกราฟิกแรสเตอร์และเป็นส่วนขยายที่ไม่เป็นทางการของ Portable Network Graphic (PNG ) ประกอบด้วยหลายเฟรม (แต่ละภาพ PNG) ที่แสดงลำดับภาพเคลื่อนไหว สิ่งนี้ให้การแสดงภาพที่คล้ายกับไฟล์ GIF ไฟล์ APNG รองรับภาพ 24 บิตและความโปร่งใส 8 บิต APNG เข้ากันได้กับไฟล์ GIF ที่ไม่ใช่ภาพเคลื่อนไหว ไฟล์ APNG ใช้นามสกุล .png เดียวกัน และสามารถเปิดได้โดยแอปพลิเคชันต่างๆ เช่น Mozilla Firefox, Chrome ที่รองรับ APNG, แอป iMessage สำหรับ iOS 10
อ่านเพิ่มเติมรูปแบบตัวกรองอื่นๆ ที่รองรับ
เมื่อใช้ Java เราสามารถกรองรูปแบบต่างๆ ได้อย่างง่ายดายรวมถึง