Java के माध्यम से पृष्ठभूमि को CDR में बदलें
सर्वर-साइड API का उपयोग करके CDR फ़ाइलों में पृष्ठभूमि बदलने के लिए अपने स्वयं के Java ऐप्स बनाएं।
Java का उपयोग करके CDR फ़ाइलों में पृष्ठभूमि कैसे बदलें
अक्सर, आदर्श छवि प्राप्त करने के लिए पृष्ठभूमि बदलने की आवश्यकता होती है। वांछित CDR प्रारूप छवि प्रभाव प्राप्त करने के लिए, अग्रभूमि वस्तुओं को शेष चित्र से अलग किया जाना चाहिए। यदि पृष्ठभूमि एक समान हो तो स्वचालित वस्तु का पता लगाना संभव है। यदि फोटो की पृष्ठभूमि असमान है या वस्तु को अलग करना चुनौतीपूर्ण है, तो छवि को पहले से चिह्नित करने की सिफारिश की जाती है। इसमें फोटो के भीतर आयताकार क्षेत्रों की पहचान करना शामिल है जहां इच्छित वस्तुएं रहती हैं और उनके प्रकार निर्दिष्ट करना शामिल है। यह क्लाउड एपीआई की ऑब्जेक्ट पहचान सुविधा के माध्यम से मैन्युअल रूप से या स्वचालित रूप से किया जा सकता है। ऑब्जेक्ट चयन और मूल पृष्ठभूमि को हटाने के बाद, एक नई पृष्ठभूमि लागू की जा सकती है या पारदर्शिता लागू की जा सकती है। CDR फ़ाइलों में पृष्ठभूमि बदलने के लिए, हम इसका उपयोग करेंगे Aspose.Imaging for Java API जो एक सुविधा संपन्न, शक्तिशाली और जावा प्लेटफॉर्म के लिए छवि हेरफेर और रूपांतरण एपीआई का उपयोग करने में आसान है। आप इसका नवीनतम संस्करण सीधे Maven से डाउनलोड कर सकते हैं और इसे अपने मावेन में इंस्टॉल कर सकते हैं -आधारित परियोजना pom.xml में निम्नलिखित विन्यास जोड़कर।
रिपॉजिटरी
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
निर्भरता
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-imaging</artifactId>
<version>version of aspose-imaging API</version>
<classifier>jdk16</classifier>
</dependency>
Java के माध्यम से CDRs में पृष्ठभूमि बदलने के चरण
अपने स्वयं के वातावरण में निम्नलिखित वर्कफ़्लो को आज़माने के लिए आपको aspose-imaging-version-jdk16.jar की आवश्यकता होगी।
- CDR फ़ाइलें Image.load विधि से लोड करें
- पृष्ठभूमि बदलें;
- Aspose द्वारा समर्थित डिस्क में छवि सहेजें। इमेजिंग प्रारूप
सिस्टम आवश्यकताएं
Aspose.Imaging for Java सभी प्रमुख ऑपरेटिंग सिस्टम पर समर्थित है। बस सुनिश्चित करें कि आपके पास निम्नलिखित पूर्वापेक्षाएँ हैं।
- JDK 1.6 या उच्चतर स्थापित है।
CDR छवियों में पृष्ठभूमि बदलें - Java
import com.aspose.imaging.*; | |
import com.aspose.imaging.fileformats.png.PngColorType; | |
import com.aspose.imaging.imageoptions.PngOptions; | |
import com.aspose.imaging.masking.IMaskingSession; | |
import com.aspose.imaging.masking.ImageMasking; | |
import com.aspose.imaging.masking.options.*; | |
import com.aspose.imaging.masking.result.MaskingResult; | |
import com.aspose.imaging.sources.FileCreateSource; | |
import java.io.File; | |
import java.util.Arrays; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.function.Consumer; | |
//Most common example to demonstrate background change/remove tool | |
removeBackgroundGenericExample(); | |
// Folder that contains images to process | |
static final String templatesFolder = "c:\\Data\\"; | |
public static void removeBackgroundProcessingWithManualRectangles() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
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(new Consumer<String>() | |
{ | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + "remove_background_manual_rectangles." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
maskingOptions.setFeatheringRadius(2); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
AutoMaskingArgs maskingArgs = new AutoMaskingArgs(); | |
maskingArgs.setObjectsRectangles(new Rectangle[] | |
{ | |
// girl's bound box | |
new Rectangle(87, 47, 123, 308), | |
// boy's bound box | |
new Rectangle(180, 24, 126, 224) | |
}); | |
maskingOptions.setArgs(maskingArgs); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
IMaskingSession maskingSession = new ImageMasking(image) | |
.createSession(maskingOptions); | |
try | |
{ | |
// first run of segmentation | |
maskingSession.decompose().dispose(); | |
AutoMaskingArgs argsWithUserMarkers = new AutoMaskingArgs(); | |
argsWithUserMarkers.setObjectsPoints(new Point[][] | |
{ | |
// background markers | |
null, | |
// foreground markers | |
new UserMarker() | |
// boy's head | |
.addPoint(218, 48, 10) | |
// girl's head | |
.addPoint(399, 66, 10) | |
// girs's body | |
.addPoint(158, 141, 10) | |
.addPoint(158, 209, 20) | |
.addPoint(115, 225, 5) | |
.getPoints() | |
}); | |
try (MaskingResult maskingResult = maskingSession | |
.improveDecomposition(argsWithUserMarkers)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
finally | |
{ | |
maskingSession.dispose(); | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
public static void removeBackgroundAutoProcessingWithAssumedObjects() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
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(new Consumer<String>() { | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder | |
+ "remove_background_auto_assumed_objects." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
final LinkedList<AssumedObjectData> assumedObjects = new LinkedList<>(); | |
// girl's bound box | |
assumedObjects.add( | |
new AssumedObjectData(DetectedObjectType.Human, | |
new Rectangle(87, 47, 123, 308))); | |
// boy's bound box | |
assumedObjects.add( | |
new AssumedObjectData(DetectedObjectType.Human, | |
new Rectangle(180, 24, 126, 224))); | |
maskingOptions.setAssumedObjects(assumedObjects); | |
maskingOptions.setCalculateDefaultStrokes(true); | |
maskingOptions.setFeatheringRadius(1); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
maskingOptions.setBackgroundReplacementColor(Color.getGreen()); | |
try (MaskingResult maskingResult = new ImageMasking(image) | |
.decompose(maskingOptions)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
public static void removeBackgroundAutoProcessing() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
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(new Consumer<String>() { | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + "remove_background_auto." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
maskingOptions.setFeatheringRadius(1); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
maskingOptions.setBackgroundReplacementColor(Color.getGreen()); | |
try (MaskingResult maskingResult = new ImageMasking(image) | |
.decompose(maskingOptions)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
//Remove rasterized vector image | |
if (isVectorFormat) | |
{ | |
new File(inputFile).delete(); | |
} | |
} | |
}); | |
} | |
public static void removeBackgroundGenericExample() | |
{ | |
List<String> rasterFormats = Arrays.asList("jpg", "png", "bmp", "apng", | |
"dicom", "jp2", "j2k", "tga", "webp", "tif", "gif"); | |
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(new Consumer<String>() { | |
@Override | |
public void accept(String formatExt) | |
{ | |
String inputFile = templatesFolder + "couple." + formatExt; | |
boolean isVectorFormat = vectorFormats.contains(formatExt); | |
//Need to rasterize vector formats before background remove | |
if (isVectorFormat) | |
{ | |
inputFile = rasterizeVectorImage(formatExt, inputFile); | |
} | |
String outputFile = templatesFolder + "remove_background." + formatExt; | |
System.out.println("Processing " + formatExt); | |
try (RasterImage image = (RasterImage) Image.load(inputFile)) | |
{ | |
//Additional code examples can be found at | |
//https://docs.aspose.com/imaging/java/remove-background-from-images/#graph-cut-auto-masking-using-imagingcloud-api | |
AutoMaskingGraphCutOptions maskingOptions = new AutoMaskingGraphCutOptions(); | |
maskingOptions.setCalculateDefaultStrokes(true); | |
maskingOptions.setFeatheringRadius(1); | |
maskingOptions.setMethod(SegmentationMethod.GraphCut); | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
pngOptions.setSource(new FileCreateSource(outputFile, false)); | |
maskingOptions.setExportOptions(pngOptions); | |
maskingOptions.setBackgroundReplacementColor(Color.getGreen()); | |
try (MaskingResult maskingResult = new ImageMasking(image) | |
.decompose(maskingOptions)) | |
{ | |
try (Image resultImage = maskingResult.get_Item(1).getImage()) | |
{ | |
resultImage.save(); | |
} | |
} | |
} | |
//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; | |
} | |
class UserMarker | |
{ | |
private final List<Point> list = new LinkedList<>(); | |
public UserMarker addPoint(int left, int top, int radius) | |
{ | |
for (int y = top - radius; y <= top + radius; y++) | |
{ | |
for (int x = left - radius; x <= left + radius; x++) | |
{ | |
this.list.add(new Point(x, y)); | |
} | |
} | |
return this; | |
} | |
public Point[] getPoints() | |
{ | |
return this.list.toArray(new Point[0]); | |
} | |
} |
Aspose.Imaging for Java API . के बारे में
Aspose.Imaging API अनुप्रयोगों के भीतर छवियों (फ़ोटो) को बनाने, संशोधित करने, आकर्षित करने या परिवर्तित करने के लिए एक छवि प्रसंस्करण समाधान है। यह प्रदान करता है: क्रॉस-प्लेटफ़ॉर्म छवि प्रसंस्करण, जिसमें विभिन्न छवि प्रारूपों (समान बहु-पृष्ठ या बहु-फ़्रेम छवि प्रसंस्करण सहित) के बीच रूपांतरण शामिल हैं, लेकिन इन्हीं तक सीमित नहीं है, ड्राइंग जैसे संशोधन, ग्राफिक प्राइमेटिव के साथ काम करना, परिवर्तन (आकार बदलना, फसल करना, फ्लिप करना और घुमाना) , बिनाराइज़ेशन, ग्रेस्केल, एडजस्ट), उन्नत छवि हेरफेर सुविधाएँ (फ़िल्टरिंग, डिथरिंग, मास्किंग, डेस्क्यूइंग), और मेमोरी ऑप्टिमाइज़ेशन रणनीतियाँ। यह एक स्टैंडअलोन लाइब्रेरी है और इमेज ऑपरेशंस के लिए किसी सॉफ्टवेयर पर निर्भर नहीं है। परियोजनाओं के भीतर देशी एपीआई के साथ आसानी से उच्च-प्रदर्शन छवि रूपांतरण सुविधाएँ जोड़ सकते हैं। ये 100% निजी ऑन-प्रिमाइसेस एपीआई हैं और छवियों को आपके सर्वर पर संसाधित किया जाता है।ऑनलाइन ऐप के द्वारा CDRs में पृष्ठभूमि बदलें
हमारी लाइव डेमो वेबसाइट पर जाकर CDR दस्तावेज़ों में पृष्ठभूमि बदलें। लाइव डेमो के निम्नलिखित लाभ हैं
CDR क्या है CDR फाइल का प्रारूप
CDR फ़ाइल एक वेक्टर ड्राइंग इमेज फ़ाइल है जो मूल रूप से CorelDRAW के साथ डिजिटल छवि एन्कोडेड और संपीड़ित को संग्रहीत करने के लिए बनाई गई है। इस तरह की एक ड्राइंग फ़ाइल में छवि सामग्री के वेक्टर प्रतिनिधित्व के लिए पाठ, रेखाएं, आकार, चित्र, रंग और प्रभाव होते हैं। CDR फाइलें प्राथमिक एप्लिकेशन के रूप में CorelDRAW के साथ खोली जा सकती हैं और अन्य प्रारूपों जैसे PDF, JPG, PNG, BMP और AI में भी परिवर्तित की जा सकती हैं। इसका उपयोग ब्रोशर, टैब्लॉयड, लिफाफे और पोस्टकार्ड जैसे विभिन्न ग्राफिक्स डेटा के प्रतिनिधित्व के लिए किया जा सकता है। CorelDRAW के अलावा, Corel पेंटशॉप प्रो और CorelDRAW ग्राफ़िक्स सूट जैसे अन्य Corel उत्पाद भी CDR फ़ाइल स्वरूपों को खोल सकते हैं।
अधिक पढ़ेंअन्य समर्थित परिवर्तन पृष्ठभूमि प्रारूप
Java का उपयोग करके, कोई भी व्यक्ति विभिन्न स्वरूपों में पृष्ठभूमि को आसानी से बदल सकता है, जिसमें शामिल हैं।