We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Does the api support extracting a shape such as portrait or product from backgroud?

Hi, Support:
I want to know whether the api supports extracting a shape such as portrait or product from its backgroud, and then save it as png file?
Thanks for your help.

Please look at

as an example of avialble solution.

The code is based on C+.
However, I failed to convert it into Vb.net ones.
Would you please provide me a vb.net demo?

There is no need to make time consuming exercises porting our .NET C# code to VB.NET. You may compile it as .NET C# dll instead, add it as a dependency to your VB.NET application along with Aspose.Imaging .NET and use then.

I try the c demo, but there are two errors,how to fix it?
111.jpg (71.6 KB)

the report of the first error is that AutoMaskingGraphCutOptions class is not found.
the report of the second error is that “cannot apply indexing with [] to an expression of type ‘MaskingResult’”.
My DEV is VS 2017, and the Dll is v20.10 and Net3.5.
How to fix this two errors?

We’ve introduced the image masking later. Please use the latest Aspose.Imaging.dll version.

I try the v22.4,but it still throw an exception like this:
222.jpg (81.9 KB)
333.jpg (72.8 KB)

What’s wrong?how to fix it?
DEV are VS2017, VC#, aspose.imaging.dll(v22.4),net3.5.

Please do

using (MaskingResult results = new ImageMasking(image).Decompose(options))

I try what you suggest, but the problem still there.
44.jpg (75.2 KB)

55.jpg (80.0 KB)

what’s wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Png;
using Aspose.Imaging.ImageOptions;
using Aspose.Imaging.Masking;
using Aspose.Imaging.Masking.Options;
using Aspose.Imaging.Masking.Result;
using Aspose.Imaging.Sources;

namespace YCImgCutOut
static class Program
static void Main(string[] args)
int i = 0;
if (true )
string inputFile = args[0];
string outputFile = args[1];
using (RasterImage image = (RasterImage)Aspose.Imaging.Image.Load(inputFile))
AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions
CalculateDefaultStrokes = true,
FeatheringRadius = (Math.Max(image.Width, image.Height) / 500) + 1,
Method = SegmentationMethod.GraphCut,
Decompose = false,
ExportOptions =
new PngOptions()
ColorType = PngColorType.TruecolorWithAlpha,
Source = new FileCreateSource(outputFile)
BackgroundReplacementColor = Color.Transparent

                using (MaskingResult results = new ImageMasking(image).Decompose(options))

                    using (RasterImage resultImage = (RasterImage)results[0].GetImage())
                        resultImage.Save(outputFile, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha });




@ducaisoft You should either

  1. specify Source = new FileCreateSource(outputFile) in ExportOptions and then perform
    without specifying image path and new ImageOptionsBase;
  2. specify Source = new FileCreateSource("some-temp-file-path") in ExportOptions and then perform
    resultImage.Save(outputFilePath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha })
    saving the image to a desired destination.

I suggest you to use the second option to avoid using scope limitations.

You can see more examples here:

Thus works!
However, the output is out of expectation, that’s is to say, the result is useless. Whereas the remove.bg can work very fine. Is there any possible to improve the api function for removing bg?
the input is Tmp.jpg (24.7 KB)
whereas the output is tmp.jpg (25.8 KB).
By compare, the output by remove.bg is as follow: Tmp-removebg-preview.jpg (37.6 KB)

@ducaisoft Yes, you can use following methods from the mentioned article to improve the result.
This one utilizing Imaging.Cloud API:

Or one of this ones with some manual help:

Following your references, I found nothing how to work it out.
Would you please show me a full demo how the API works even better.

You may evaluate the feature at https://products.aspose.app/imaging/remove-background.
If you find it suitable to your needs - please review previous reply to see how it works.

I evaluate it at https://products.aspose.app/imaging/remove-background,
It looks ok, but it takes a long time (serval minutes) to process an image which is not tolerable, whereas the API cloud at removebg.com that is similar as yours only takes about 10 second to finish the processing. Is there any method to speed up the process? Or the api makes no use for it consume too long time!
Would you please provide me a full and fine demo to work it out? by C#?

The follow is the code I test:

It takes a long time to finish the process.
And the Output like this is totally out of expectation!

How to speed it up and improve the output?

Thank you for coming back.

Regarding the performance, comparing to other products - unlike them we do not strictly depend on AI/ML and our approach is more universal but slower.

Regarding the quality - we’ve reviewed your code sinppet and found one principle difference with out approach at Remove background application - we are using pre-identification of objects to improve the qualty, see above mentioned code snippet Remove background from images|Documentation (aspose.com).