Created
May 3, 2011 01:18
-
-
Save billdawson/952659 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ti.Media.showCamera({ | |
success: function(e) { | |
// Open stream on blob. | |
var instream = Titanium.Stream.createStream({ | |
mode: Titanium.Stream.MODE_READ, | |
source: e.media // e.media is a Blob | |
}); | |
// Open an output stream for a file | |
// to hold the blob data. | |
var f = | |
Titanium.Filesystem.getFile( | |
Titanium.Filesystem.applicationDataDirectory, "out.jpg"); | |
var outstream = f.open(Titanium.Filesystem.MODE_WRITE); | |
// Create a buffer for chunking the data. | |
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(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment