I need to create and then email a composite image - a paint layer imposed onto a photo. It is working on iOS devices, but on Android devices the image is not getting attached to the email. In an attempt to narrow down the problem I'm saving the composite image to the device's data directory. The image file is getting created in iOS but not in Android.
... paintViewImage = paintView.toImage(); combinedImageView.add(imgView); // a photo from the camera combinedImageView.add(paintView);// the finger paint layer if (Ti.Platform.osname == 'android') { var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, "comboFile.png"); var outstream = f.open(Titanium.Filesystem.MODE_WRITE); var combinedImageBlob = combinedImageView.toBlob(); var instream = Titanium.Stream.createStream({ mode : Titanium.Stream.MODE_READ, source : combinedImageBlob // should be a Blob }); var buffer = Ti.createBuffer({ length : 1024 }); // Read and write chunks. var read_bytes = 0; while (( read_bytes = instream.read(buffer)) > 0) { outstream.write(buffer, 0, read_bytes); } // Cleanup. instream.close(); outstream.close(); emailDialog.addAttachment(f); } else { // iOS - writing to a file works fine var comboImageFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'comboFile.png'); comboImageFile.write(combinedImageView.toImage()); emailDialog.addAttachment(comboImageFile); }In the version above, the blob does not seem to be recognized as a blob and errors out with a Runtime Error: Unable to create a stream for the specified argument . If I don't use the conditional and run the else block for both platforms, I don't get any errors, but the combo file isn't created and (of course) nothing gets attached to the email.
I am not attached to the idea of using the file stream. That is just the last thing I tried before resorting to asking for help. I tried a bunch of simpler solutions, variations on what is in the else block first.
Help! thanks!