Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
conholdate-gists / crop-image.java
Created May 16, 2025 10:17
Crop Image in Java | Crop JPG PNG BMP TIFF any Picture
// Load the image.
com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.Load("image.png");
// Before cropping, the image should be cached for better performance.
if (!rasterImage.isCached())
{
rasterImage.cacheData();
}
// Create an instance of Rectangle class with desired size and crop the image.
@conholdate-gists
conholdate-gists / flip-image-horizontal.java
Created May 12, 2025 13:36
Flip Images in Java | Flip Images Horizontally or Vertically
// Load image
com.aspose.imaging.RasterImage image = (com.aspose.imaging.RasterImage) com.aspose.imaging.Image.load("image.png");
// Flip the image horizontally
image.rotateFlip(com.aspose.imaging.RotateFlipType.RotateNoneFlipX);
// Save the flipped image
image.save("flipped-horizontal.png");
@conholdate-gists
conholdate-gists / rotate-image.cs
Created May 2, 2025 14:36
Rotate Image in C#
// Load an image in an instance of Image
using (Image image = Image.Load("image.bmp"))
{
// Rotate the image
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
// Save image
image.Save("image-rotated.bmp");
}
@conholdate-gists
conholdate-gists / convert-dwf-to-pdf.cs
Created April 23, 2025 20:54
Convert DWF to PDF in C#
// Load the input DWF file
Image image = Image.Load("DWFtoPDF.dwf");
// Create an object of CadRasterizationOptions to set different properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions()
{
PageWidth = 1600,
PageHeight = 1600,
ContentAsBitmap = true
@conholdate-gists
conholdate-gists / resize-image-proportionally.cs
Created April 23, 2025 18:46
Resize Image in C# | Scale JPG PNG GIF BMP Picture
// Load image
using (Image image = Image.Load("aspose-logo.png"))
{
// Cache image data
if (!image.IsCached)
{
image.CacheData();
}
// Specify width and height
@conholdate-gists
conholdate-gists / image-to-base64.cs
Created April 17, 2025 20:32
Convert Image to Base64 | JPG PNG to Base64 Image
// Load an input JPG image
var bytes = File.ReadAllBytes(@"C:\Files\Sample_JPG.jpg");
// Initialize an SVGDocument object
var document = new SVGDocument();
// Create an image element
var img = (SVGImageElement)document.CreateElementNS("http://www.w3.org/2000/svg", "image");
// Convert image to Base64
@conholdate-gists
conholdate-gists / convert-pptx-to-xml.cs
Created March 12, 2025 08:09
Convert PPTX to XML in C# | Presentation to PowerPoint XML in C# .NET
// Load the input Presentation
using var presentation = new Aspose.Slides.Presentation("sample.pptx");
// Save the output PowerPoint XML Presentation format
presentation.Save(dataDir + "output.xml", Aspose.Slides.Export.SaveFormat.Xml);
@conholdate-gists
conholdate-gists / redact-excel.java
Created March 12, 2025 08:09
Redact Excel Worksheet in Java
final com.groupdocs.redaction.Redactor redactor = new com.groupdocs.redaction.Redactor(dataDir + "SalesSeptember.xlsx");
try
{
com.groupdocs.redaction.redactions.CellFilter filter = new com.groupdocs.redaction.redactions.CellFilter();
filter.setColumnIndex(1);
filter.setWorkSheetName("Customers");
Pattern expression = Pattern.compile("^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
com.groupdocs.redaction.RedactorChangeLog result = redactor.apply(new com.groupdocs.redaction.redactions.CellColumnRedaction(filter, expression, new com.groupdocs.redaction.redactions.ReplacementOptions("[customer email]")));
if (result.getStatus() != com.groupdocs.redaction.RedactionStatus.Failed)
{
@conholdate-gists
conholdate-gists / convert-cdr-to-psd.java
Created March 12, 2025 08:09
Convert CDR to PSD in Java
// Load the CDR sample file using Image.load function into CdrImage object
try (com.aspose.imaging.fileformats.cdr.CdrImage CdrtoPSDImage = (com.aspose.imaging.fileformats.cdr.CdrImage)com.aspose.imaging.Image.load("SampleCDRFile.cdr"))
{
// Initialize PsdOptions object to set characteristics of output PSD file
com.aspose.imaging.ImageOptionsBase psdImportOptions = new com.aspose.imaging.imageoptions.PsdOptions();
// For a multi-page document, by default all the pages are converted
psdImportOptions.setMultiPageOptions(new com.aspose.imaging.imageoptions.MultiPageOptions());
// Use merger layer option to export multi-page CDR as a single layer
@conholdate-gists
conholdate-gists / convert-dxf-to-svg.java
Created March 4, 2025 10:11
Convert DXF to SVG in Java
// Load DXF file
var converter = new com.groupdocs.conversion.Converter("sample.dxf");
// Set conversion parameters for SVG format
var convertOptions = new com.groupdocs.conversion.filetypes.FileType().fromExtension("svg").getConvertOptions();
// Convert DXF to SVG format
converter.convert("output.svg", convertOptions);