How to remove background from an image programmatically in flutter. I want to remove background from this below image .enter image description here
Asked
Active
Viewed 6,026 times
0
-
refer here:https://gist.github.com/plateaukao/ebb5e7169dd89cc52bda338762d4997e – gretal Dec 09 '21 at 08:02
-
Please provide enough code so others can better understand or reproduce the problem. – Community Dec 14 '21 at 07:57
3 Answers
1

Jeel Bhatti
- 651
- 3
- 15
-
Hi , Thankyou for your response. Remove BG API available only native android(JAVA) and Ios(Swift). I need to using Flutter Project. – Ranjith Jith Dec 09 '21 at 09:04
-
This is available using http package. And they provide rest API that's why we can use in flutter. Review this https://stackoverflow.com/questions/60626619/is-it-possible-to-develop-an-app-using-the-remove-bg-api-in-flutter. – Jeel Bhatti Dec 09 '21 at 09:34
-
removebg API response get only image . how to set this image in my flutter project. – Ranjith Jith Dec 09 '21 at 12:19
-
0
pass your image path to this code:
assets/imagepath.jpg : rename this with your path,
https://www.remove.bg/dashboard#api-key[][1] open this link and get the api key and copy,
import 'dart:typed_data';
import 'package:http/http.dart' as http;
class ApiClient {
Future<Uint8List> removeBgApi(String imagePath) async {
var request = http.MultipartRequest("POST", Uri.parse("https://api.remove.bg/v1.0/removebg"));
request.files.add(await http.MultipartFile.fromPath("image_file", imagePath));
request.headers.addAll({"X-API-Key": " replace with your api key "});
final response = await request.send();
if (response.statusCode == 200) {
http.Response imgRes = await http.Response.fromStream(response);
return imgRes.bodyBytes;
} else {
throw Exception("Error occurred with response ${response.statusCode}");
}
}
}
ApiClient().removeBgApi('assets/imagepath.jpg');

توصیف خٹک
- 1
- 1
-2
Using http package, you can access remove.bg rest api & get removed background image.
To remove.bg rest api, you can pass/input image using multipart request & from the response, you can get streamed response using http.Response.fromStream()
to get removed background image. Below code snippet for the reference,
var request = new http.MultipartRequest("POST", remove_bg_api_uri);
var streamedResponse = await request.send()
var response = await http.Response.fromStream(streamedResponse);
For know more details on how to remove image background using remove.bg api, refer this link.

ritsapp
- 80
- 2