Skip to content

Commit 8c2aa30

Browse files
author
Evgeniy Sidenko
committed
Updated up to the version 23.12
1 parent b682c5e commit 8c2aa30

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

Examples/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.aspose</groupId>
55
<artifactId>imaging-java-examples</artifactId>
6-
<version>23.11</version>
6+
<version>23.12</version>
77
<packaging>jar</packaging>
88
<properties>
99
<maven.compiler.source>1.8</maven.compiler.source>
@@ -15,14 +15,14 @@
1515
<dependency>
1616
<groupId>com.aspose</groupId>
1717
<artifactId>aspose-imaging</artifactId>
18-
<version>23.11</version>
18+
<version>23.12</version>
1919
<classifier>jdk16</classifier>
2020
<type>jar</type>
2121
</dependency>
2222
<dependency>
2323
<groupId>com.aspose</groupId>
2424
<artifactId>aspose-imaging</artifactId>
25-
<version>23.11</version>
25+
<version>23.12</version>
2626
<classifier>javadoc</classifier>
2727
<type>jar</type>
2828
</dependency>

Examples/src/main/java/com/aspose/imaging/examples/ConvertingImages/AddAlphaBlendingForImage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.aspose.imaging.RasterImage;
66
import com.aspose.imaging.examples.Logger;
77
import com.aspose.imaging.examples.Utils;
8+
import com.aspose.imaging.fileformats.png.PngColorType;
9+
import com.aspose.imaging.imageoptions.PngOptions;
810

911
public class AddAlphaBlendingForImage
1012
{
@@ -22,7 +24,9 @@ public static void main(String[] args)
2224
Point center = new Point((background.getWidth() - overlay.getWidth()) / 2,
2325
(background.getHeight() - overlay.getHeight()) / 2);
2426
background.blend(center, overlay, overlay.getBounds(), (byte) 127);
25-
background.save(outDir + "/blended.png");
27+
background.save(outDir + "/blended.png", new PngOptions() {{
28+
setColorType(PngColorType.TruecolorWithAlpha);
29+
}});
2630
}
2731
}
2832
Utils.deleteFile(outDir + "/blended.png");
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.aspose.imaging.examples.ModifyingImages.removebackground;
2+
3+
import com.aspose.imaging.examples.Logger;
4+
import com.aspose.imaging.examples.Utils;
5+
import com.aspose.imaging.*;
6+
import com.aspose.imaging.fileformats.png.PngColorType;
7+
import com.aspose.imaging.imageoptions.PngOptions;
8+
import com.aspose.imaging.imageoptions.VectorRasterizationOptions;
9+
import java.io.File;
10+
public class RemoveBackgroundVectors
11+
{
12+
public static void main(String[] args)
13+
{
14+
Logger.startExample();
15+
16+
// The path to the documents' directory.
17+
String dataDir = Utils.getSharedDataDir() + "RemoveBackground/";
18+
String outDir = Utils.getOutDir("RemoveBackground");
19+
String[] fileNames = { "golfer.emf" };
20+
RemoveBackgroundSettings[] rbs = new RemoveBackgroundSettings[] {
21+
new RemoveBackgroundSettings()
22+
{{
23+
setDetectionLevel(30);
24+
}},
25+
new RemoveBackgroundSettings()
26+
{{
27+
setBounds(new RectangleF(0, 1000, 5000, 4000));
28+
}},
29+
new RemoveBackgroundSettings()
30+
{{
31+
setDetectionLevel(10);
32+
}},
33+
new RemoveBackgroundSettings(),
34+
new RemoveBackgroundSettings(),
35+
new RemoveBackgroundSettings(),
36+
new RemoveBackgroundSettings()
37+
{{
38+
setColor1(Color.getBlue());
39+
}},
40+
new RemoveBackgroundSettings()
41+
};
42+
43+
for (int i = 0; i < fileNames.length; i++)
44+
{
45+
removeBackgroundExample(fileNames[i], rbs[i], dataDir, outDir);
46+
}
47+
48+
Logger.endExample();
49+
}
50+
51+
private static void removeBackgroundExample(String fileName, RemoveBackgroundSettings settings, String dataDir, String outFilePath)
52+
{
53+
String inputFilePath = dataDir + fileName;
54+
File outDir = new File(outFilePath);
55+
if (!outDir.exists())
56+
{
57+
outDir.mkdirs();
58+
}
59+
60+
final String outputFile = outFilePath + File.separator + fileName + ".png";
61+
try (Image image = Image.load(inputFilePath))
62+
{
63+
VectorRasterizationOptions vectorOpt = new VectorRasterizationOptions();
64+
vectorOpt.setBackgroundColor(Color.getTransparent());
65+
vectorOpt.setPageSize(Size.to_SizeF(image.getSize()));
66+
PngOptions options = new PngOptions();
67+
options.setColorType(PngColorType.TruecolorWithAlpha);
68+
options.setVectorRasterizationOptions(vectorOpt);
69+
70+
if (image instanceof VectorImage)
71+
{
72+
((VectorImage)image).removeBackground(settings);
73+
}
74+
75+
image.save(outputFile, options);
76+
}
77+
78+
Utils.deleteFile(outputFile);
79+
}
80+
}

Examples/src/main/java/com/aspose/imaging/examples/RunExamples.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.aspose.imaging.examples.ModifyingImages.jpeg.ReadSpecificEXIFTagsInformation;
3939
import com.aspose.imaging.examples.ModifyingImages.multipage.MultipageFromImages;
4040
import com.aspose.imaging.examples.ModifyingImages.removebackground.GraphCutAutoMasking;
41+
import com.aspose.imaging.examples.ModifyingImages.removebackground.RemoveBackgroundVectors;
4142
import com.aspose.imaging.examples.ModifyingImages.tga.ConvertToTGA;
4243
import com.aspose.imaging.examples.ModifyingImages.tiff.CreateGraphicsPathFromPathTiffResourcesAndViceVersa;
4344
import com.aspose.imaging.examples.ModifyingImages.tiff.ExportTiffBatchMode;
@@ -113,9 +114,10 @@ public static void main(String[] args) throws IOException, InterruptedException,
113114
//// =====================================================
114115

115116
Logger.println("Running modifying and converting images tests:");
117+
RemoveBackgroundVectors.main(args);
118+
AddAlphaBlendingForImage.main(args);
116119
RemoveWatermarkFilter.main(args);
117120
MagicWandToolTest.main(args);
118-
AddAlphaBlendingForImage.main(args);
119121
BigTiffLoadExample.main(args);
120122
KeepTransparencyWhenIndexingPngImage.main(args);
121123
SpecifyFont.main(args);
68.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)