I currently have a python socket server that captures from a webcam using opencv. I have converted the captured image using image.tostring();
I am trying to send this image to an android application and have it open in a web view. I can get the text string to open, but cannot make it back into an image.
This is the only way that I can get anything to display in the web view :
webv.loadData(html, "text/html", "utf-8");
The data is transferring to the android device, so I know that the socket is working fine, I just cannot figure out the translation.
Any suggestions?
EDIT based on comments below:
Ok. So I now converted the string to base64 in python, before sending it.
I tried using bitmapfactory to add the image to an ImageView using:
byte[] decodedString = Base64.decode(result, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
but I get the error SkImageDecoder:: Factory returned null
I also tried a webview with the following, which gives me a broken image icon
String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "text/html", "utf-8");
These give me a blank webview
String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "iamge/jpeg", "base64");
String html = "<img src=\"data:image/jpeg;base64,"+result+"\" />";
webv.loadData(html, "text/html", "base64");
webv.loadData(result, "image/jpeg","base64");
It seems that the problem is in my python code, as the base64 string exported to a text file cannot be reformed into an image, it "contains errors" applicable code fragments:
img = cv.QueryFrame(cam)
imgstr = base64.b64encode(img.tostring())
conn = s.accept()
conn.send(imgstr)