Home > Uncategorized > Remove the background from an Image using C#

Remove the background from an Image using C#

Instead of manually processing images, and cutting out the subject from the background, you can use an API to do this, as long as the image is publicly accessible via a URL – Even temporarily accessible, you could upload to S3, then delete it again afterwards.

Here’s the code – in C#


var url = "https://image-background-removal3.p.rapidapi.com/BackgroundRemoverLambda";

var oReq = new { url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ2nkYh11Mswy-IVb5tM3C4c_nlbYOvNyso9w&usqp=CAU" };

var strReq = JsonConvert.SerializeObject(oReq);

using var web = new WebClient();
web.Headers.Add("x-rapidapi-key", "xxxxxx");
var response = web.UploadData(url, "POST", Encoding.UTF8.GetBytes(strReq));
var b64Response = Convert.FromBase64String(Encoding.UTF8.GetString(response));
File.WriteAllBytes("result3.png", b64Response);

Where the API Key can be found here: https://rapidapi.com/appaio/api/image-background-removal3/

Categories: Uncategorized
  1. Kiarash Doorandish
    November 25, 2023 at 6:05 am

    Is there any built-in library to remove image backgrounds without the need to access the Internet and calling the API?

    Like

  2. Kiarash Doorandish
    November 25, 2023 at 6:05 am

    Is there any built-in library to remove image backgrounds without the need to access the Internet and calling the API?

    Like

  1. No trackbacks yet.

Leave a comment