How to convert web socket Uint8List output to Image in flutter
I am a new programmer in flutter, and decoding the bytes image is driving me nuts from more than 10 days. I am working to create flutter application that will allow users to upload image, and the image will be sent to python server which will apply deep learning model to it, and send back the altered image. I have somehow managed to send image from flutter to python ( I converted it to bytes and on python side I used PIL library to convert it back to Image ).
But when I send the image from python in the following way.
image1 = Image.open(io.BytesIO(flutter_input))
image = np.array(image1)
// Apply machine learning algorithim
print("Length of image is ", len(image.flatten()))
output = bytes(image)
self.sendMessage(our, True)
I am unable to convert the following sent image, to Image in flutter. I found out that the input was of type
Uint8List.
I have tried this thread, Flutter, dart:io - convert Uint8List (from websocket) to a jpeg file I can draw But, when I use
I.Image _img = I.decodeImage(binaryIntList);
_img = I.encodeJpg(_img);
it gives out the following error.
Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
Here is my flutter code, to retrieve data from server.
IOWebSocketChannel.connect("ws://10.7.4.78:8080");
List<int> imageBytes = img.readAsBytesSync();
channel.sink.add(imageBytes);
channel.stream.listen(( message) {
Image im1 =Image.memory(message)};
print(im1.height) // Prints null
Moreover, Image.decodeImage also cannot decode the input. Please tell me, how can I get the input and interpret as Image file or JpegFile so I use it further in my application.
Please, tell me how can I overcome it or is there any way in which I can use my above client.py code in flutter to avoid the complexities.
Thanks
encoding utf-8 websocket flutter
add a comment |
I am a new programmer in flutter, and decoding the bytes image is driving me nuts from more than 10 days. I am working to create flutter application that will allow users to upload image, and the image will be sent to python server which will apply deep learning model to it, and send back the altered image. I have somehow managed to send image from flutter to python ( I converted it to bytes and on python side I used PIL library to convert it back to Image ).
But when I send the image from python in the following way.
image1 = Image.open(io.BytesIO(flutter_input))
image = np.array(image1)
// Apply machine learning algorithim
print("Length of image is ", len(image.flatten()))
output = bytes(image)
self.sendMessage(our, True)
I am unable to convert the following sent image, to Image in flutter. I found out that the input was of type
Uint8List.
I have tried this thread, Flutter, dart:io - convert Uint8List (from websocket) to a jpeg file I can draw But, when I use
I.Image _img = I.decodeImage(binaryIntList);
_img = I.encodeJpg(_img);
it gives out the following error.
Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
Here is my flutter code, to retrieve data from server.
IOWebSocketChannel.connect("ws://10.7.4.78:8080");
List<int> imageBytes = img.readAsBytesSync();
channel.sink.add(imageBytes);
channel.stream.listen(( message) {
Image im1 =Image.memory(message)};
print(im1.height) // Prints null
Moreover, Image.decodeImage also cannot decode the input. Please tell me, how can I get the input and interpret as Image file or JpegFile so I use it further in my application.
Please, tell me how can I overcome it or is there any way in which I can use my above client.py code in flutter to avoid the complexities.
Thanks
encoding utf-8 websocket flutter
This the output, when I do print(message) , they are not in hex [146, 126, 102, 154, 134, 110, 160, 140, 116, 158, 138, 114, 153, 133, 109, 151, 131,..
– Muhammad Rafique
Jan 20 at 10:18
I tried, to convert them to hex using message.toRadixString(16) but it is throwing an error that Uint8List has no instance toRadixString(16)
– Muhammad Rafique
Jan 20 at 10:27
So, please tell me then how can I convert it to Image
– Muhammad Rafique
Jan 20 at 10:31
I am not able to find the matching signature. Can you tell me Image.memory() supports which format
– Muhammad Rafique
Jan 20 at 11:07
add a comment |
I am a new programmer in flutter, and decoding the bytes image is driving me nuts from more than 10 days. I am working to create flutter application that will allow users to upload image, and the image will be sent to python server which will apply deep learning model to it, and send back the altered image. I have somehow managed to send image from flutter to python ( I converted it to bytes and on python side I used PIL library to convert it back to Image ).
But when I send the image from python in the following way.
image1 = Image.open(io.BytesIO(flutter_input))
image = np.array(image1)
// Apply machine learning algorithim
print("Length of image is ", len(image.flatten()))
output = bytes(image)
self.sendMessage(our, True)
I am unable to convert the following sent image, to Image in flutter. I found out that the input was of type
Uint8List.
I have tried this thread, Flutter, dart:io - convert Uint8List (from websocket) to a jpeg file I can draw But, when I use
I.Image _img = I.decodeImage(binaryIntList);
_img = I.encodeJpg(_img);
it gives out the following error.
Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
Here is my flutter code, to retrieve data from server.
IOWebSocketChannel.connect("ws://10.7.4.78:8080");
List<int> imageBytes = img.readAsBytesSync();
channel.sink.add(imageBytes);
channel.stream.listen(( message) {
Image im1 =Image.memory(message)};
print(im1.height) // Prints null
Moreover, Image.decodeImage also cannot decode the input. Please tell me, how can I get the input and interpret as Image file or JpegFile so I use it further in my application.
Please, tell me how can I overcome it or is there any way in which I can use my above client.py code in flutter to avoid the complexities.
Thanks
encoding utf-8 websocket flutter
I am a new programmer in flutter, and decoding the bytes image is driving me nuts from more than 10 days. I am working to create flutter application that will allow users to upload image, and the image will be sent to python server which will apply deep learning model to it, and send back the altered image. I have somehow managed to send image from flutter to python ( I converted it to bytes and on python side I used PIL library to convert it back to Image ).
But when I send the image from python in the following way.
image1 = Image.open(io.BytesIO(flutter_input))
image = np.array(image1)
// Apply machine learning algorithim
print("Length of image is ", len(image.flatten()))
output = bytes(image)
self.sendMessage(our, True)
I am unable to convert the following sent image, to Image in flutter. I found out that the input was of type
Uint8List.
I have tried this thread, Flutter, dart:io - convert Uint8List (from websocket) to a jpeg file I can draw But, when I use
I.Image _img = I.decodeImage(binaryIntList);
_img = I.encodeJpg(_img);
it gives out the following error.
Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
Here is my flutter code, to retrieve data from server.
IOWebSocketChannel.connect("ws://10.7.4.78:8080");
List<int> imageBytes = img.readAsBytesSync();
channel.sink.add(imageBytes);
channel.stream.listen(( message) {
Image im1 =Image.memory(message)};
print(im1.height) // Prints null
Moreover, Image.decodeImage also cannot decode the input. Please tell me, how can I get the input and interpret as Image file or JpegFile so I use it further in my application.
Please, tell me how can I overcome it or is there any way in which I can use my above client.py code in flutter to avoid the complexities.
Thanks
encoding utf-8 websocket flutter
encoding utf-8 websocket flutter
asked Jan 20 at 10:04
Muhammad RafiqueMuhammad Rafique
86
86
This the output, when I do print(message) , they are not in hex [146, 126, 102, 154, 134, 110, 160, 140, 116, 158, 138, 114, 153, 133, 109, 151, 131,..
– Muhammad Rafique
Jan 20 at 10:18
I tried, to convert them to hex using message.toRadixString(16) but it is throwing an error that Uint8List has no instance toRadixString(16)
– Muhammad Rafique
Jan 20 at 10:27
So, please tell me then how can I convert it to Image
– Muhammad Rafique
Jan 20 at 10:31
I am not able to find the matching signature. Can you tell me Image.memory() supports which format
– Muhammad Rafique
Jan 20 at 11:07
add a comment |
This the output, when I do print(message) , they are not in hex [146, 126, 102, 154, 134, 110, 160, 140, 116, 158, 138, 114, 153, 133, 109, 151, 131,..
– Muhammad Rafique
Jan 20 at 10:18
I tried, to convert them to hex using message.toRadixString(16) but it is throwing an error that Uint8List has no instance toRadixString(16)
– Muhammad Rafique
Jan 20 at 10:27
So, please tell me then how can I convert it to Image
– Muhammad Rafique
Jan 20 at 10:31
I am not able to find the matching signature. Can you tell me Image.memory() supports which format
– Muhammad Rafique
Jan 20 at 11:07
This the output, when I do print(message) , they are not in hex [146, 126, 102, 154, 134, 110, 160, 140, 116, 158, 138, 114, 153, 133, 109, 151, 131,..
– Muhammad Rafique
Jan 20 at 10:18
This the output, when I do print(message) , they are not in hex [146, 126, 102, 154, 134, 110, 160, 140, 116, 158, 138, 114, 153, 133, 109, 151, 131,..
– Muhammad Rafique
Jan 20 at 10:18
I tried, to convert them to hex using message.toRadixString(16) but it is throwing an error that Uint8List has no instance toRadixString(16)
– Muhammad Rafique
Jan 20 at 10:27
I tried, to convert them to hex using message.toRadixString(16) but it is throwing an error that Uint8List has no instance toRadixString(16)
– Muhammad Rafique
Jan 20 at 10:27
So, please tell me then how can I convert it to Image
– Muhammad Rafique
Jan 20 at 10:31
So, please tell me then how can I convert it to Image
– Muhammad Rafique
Jan 20 at 10:31
I am not able to find the matching signature. Can you tell me Image.memory() supports which format
– Muhammad Rafique
Jan 20 at 11:07
I am not able to find the matching signature. Can you tell me Image.memory() supports which format
– Muhammad Rafique
Jan 20 at 11:07
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275350%2fhow-to-convert-web-socket-uint8list-output-to-image-in-flutter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54275350%2fhow-to-convert-web-socket-uint8list-output-to-image-in-flutter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This the output, when I do print(message) , they are not in hex [146, 126, 102, 154, 134, 110, 160, 140, 116, 158, 138, 114, 153, 133, 109, 151, 131,..
– Muhammad Rafique
Jan 20 at 10:18
I tried, to convert them to hex using message.toRadixString(16) but it is throwing an error that Uint8List has no instance toRadixString(16)
– Muhammad Rafique
Jan 20 at 10:27
So, please tell me then how can I convert it to Image
– Muhammad Rafique
Jan 20 at 10:31
I am not able to find the matching signature. Can you tell me Image.memory() supports which format
– Muhammad Rafique
Jan 20 at 11:07