How do I scale a streaming bitmap in-place without reading the whole image first?

This method will read the header information from the image to determine its size, then read the image and scale it to the desired size in place without allocating memory for the full original sized image. It also uses BitmapFactory.Options.inPurgeable, which seems to be a sparsely documented but desirable option to prevent OoM exceptions when … Read more

Send custom HTTP request header with HTML5 audio tag

If you’re okay not supporting older browsers like IE, you can do this now with a service worker. Intercept the fetch request in the service worker and send it onwards with the custom header. Here is a basic example of intercepting a request to Google Drive and adding the Bearer token. self.addEventListener(‘fetch’, function(event) { if(event.request.url … Read more

Streaming large file uploads to ASP.NET MVC

It turns out that my initial code was basically correct; the only change required was to change request.ContentLength = clientRequest.InputStream.Length; to request.ContentLength = clientRequest.ContentLength; The former streams in the entire request to determine the content length; the latter merely checks the Content-Length header, which only requires that the headers have been sent in full. This … Read more

Streaming input to System.Speech.Recognition.SpeechRecognitionEngine

I got live speech recognition working by overriding the stream class: class SpeechStreamer : Stream { private AutoResetEvent _writeEvent; private List<byte> _buffer; private int _buffersize; private int _readposition; private int _writeposition; private bool _reset; public SpeechStreamer(int bufferSize) { _writeEvent = new AutoResetEvent(false); _buffersize = bufferSize; _buffer = new List<byte>(_buffersize); for (int i = 0; i … Read more

Unity: Live Video Streaming

I ran your code and it worked sometimes and failed sometimes(about 90% of the time). It ran with on my computer with 5 FPS. This will not play well on mobile device which I am sure you are targeting iPad. There are few problems in your code but they are very serious problems. 1.Your image … Read more

C++ OpenCV image sending through socket

Get Mat.data and directly send to the socket, the data order is BGR BGR BGR…. On the receiving side assumes you know the size of image. After receiving just assign the received buffer(BGR BGR… array) to a Mat. Client:- Mat frame; frame = (frame.reshape(0,1)); // to make it continuous int imgSize = frame.total()*frame.elemSize(); // Send … Read more

Python 2.7: streaming HTTP server supporting multiple connections on one port

The default BaseHTTPServer settings re-bind a new socket on every listener, which won’t work in Linux if all the listeners are on the same port. Change those settings between the BaseHTTPServer.HTTPServer() call and the serve_forever() call. The following example launches 100 handler threads on the same port, with each handler started through BaseHTTPServer. import time, … Read more

How to send image generated by PIL to browser?

Here’s a version without any temp files and the like (see here): def serve_pil_image(pil_img): img_io = StringIO() pil_img.save(img_io, ‘JPEG’, quality=70) img_io.seek(0) return send_file(img_io, mimetype=”image/jpeg”) To use in your code simply do @app.route(‘some/route/’) def serve_img(): img = Image.new(‘RGB’, …) return serve_pil_image(img)