How to convert image url to byte array or stream using Silverlight?
Easiest thing to do is use WebClient to download the Uri as a Stream. For this to work at least one of the following must be true:
The image is hosted on the same domain as the Silverlight app.
The domain that the image is hosted on is providing a clientaccesspolicy file to allow your Silverlight app to access the image.
This will give you access to the contents of the file as a Stream. If you want access to the decoded pixels rather than the raw contents of the file, load the Stream into an Image element (using BitmapSource.SetSource(Stream)), wait for the Image.ImageOpened event and then capture the Image element in a WriteableBitmap. You can then read the image pixel data from the WriteableBitmap.Pixels array. If the image is not coming cross-domain, you do not need to download the Stream and can just set the Image Source to the URI directly,
Related
We need to have the ability to set a custom image for new channels.
From docs https://getstream.io/chat/docs/#initialize_channel, I can see the field image and if send here some remote URL - works fine.
But what to do when we need to send an image from the phone? For sending image for message I can see the functionality. But it's bonded to channel which is going to be created.
I know we can use base64, but I hope there is a better way of doing the required functionality? (like upload the image to server and get remoteURL)?
I study the phoenix, create an application that loads the image on aws s3, and then displays it. I was able to upload the image to the cloud, but now it is not clear how to display it to the user on the page (I do not want to make public link to these images in the cloud). I was looking for information on this issue, but did not find anything useful.
From the clouds I get the file as binary data. Do I need to create some of these data is a temporary file that will be displayed on the page? I can display the image as base64, but I think this is not the best way. I would appreciate advice.
Since you've already fetched the image to a binary, you can just send it directly to the client with the appropriate content type and the browser will render it as an image. For example, to fetch and send the png at https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png:
def index(conn, _params) do
image = HTTPoison.get!("https://upload.wikimedia.org/wikipedia/commons/7/70/Example.png").body
conn
|> put_resp_header("content-type", "image/png")
|> send_resp(200, image)
end
If you open this in your browser, you'll see the image being rendered correctly because of the content-type header.
Let's say I have an MP4 file on a remote server that's encrypted (i. e. is in some format that cannot be immediately used as the src in an HTML 5 VIDEO tag).
I want JavaScript code that will be able to fetch that file, decrypt it (assuming I have the JavaScript code to do so), and then have it play using the VIDEO tag, WHILE the file is being decrypted (i. e. as opposed to reading the whole file into an array, processing it, and then creating a blob URL for it that's later assigned as the src to the VIDEO tag).
The problem is that the HTML 5 VIDEO tag only accepts a filename or blob URL as the SRC. So my question, essentially, is if there's anyway I can specify a stream URL to be the VIDEO src, and then access that stream (i. e. via an Event) and then within that event, add data to that stream incrementally.
I've researched the JavaScript MediaStream API, but don't see anyway I can use it to add processed data (i. e. a portion of a decoded stream) to the stream as described above.
If this CANNOT be done, I'm assuming I need a JavaScript video player that can read an encrypted file and render it to an HTML 5 CANVAS as it's being decrypted. However, that's more work.
I'm evaluating Fine Uploader compared to various other options, specifically JQuery File Upload.
I generally prefer the Fine Uploader approach as it's more lightweight, compared to JQuery File Uploader which has dependencies on Bootstrap and JQuery UI.
However it's important to be able to resize images: e.g., a user may select a large file from their camera and this may be very large - uploading the full resolution photo may take a very long time. JQuery File Upload doe this.
Additionally we don't have much use for very high resolution files.
If possible (I'm aware some browsers may not support this), I'd like to be able to resize images client size.
Is this possible?
Fine Uploader does not currently have any native support for image manipulation. This is a feature in our backlog, but we have not had many users tell us they are interested in this. This is one of the reasons why such a feature has yet to be implemented natively. There is a case, #707 that marks the start of native image-editing support for Fine Uploader. It is tentatively scheduled for 4.0.
However, you can certainly make use of FileReader and Canvas to resize the image. You can then submit this resized image as a Blob to Fine Uploader via the addFiles API method. At that point, the file has been submitted and Fine Uploader is ready to upload the item.
Essentially, the steps you would follow to handle this specific scenario, before Fine Uploader natively supports image manipulation:
Provide your own file input element(s) or make use of Fine Uploader's file/folder drag and drop support to get a handle on some files selected by the user.
Use FileReader to read the contents of the image.
FileReader will provide you with a URL for the image, assign that to the src attribute of an img element.
Draw the img onto a canvas element. This is where the resizing occurs.
Grab the URL of the resized image from the canvas element (canvas.toDataURL(...)).
Convert the URL to a Blob.
Pass the Blob to the addFiles API method of Fine Uploader.
The intent is to take care of most if not all of this for integrators such as yourself in the future by adding native image manipulation support to Fine Uploader.
Hope this helps.
I am uploading an image via Amazon SDK to S3. Those PNG images are optimized using ImageMagick ASP.NET library. The problem is that I can see them fine when optimized on my computer (testing locally), but when uploaded to S3, they are being heavily distorted. Do you know what can be the cause for this?
I am using ASP.net. I thought that the reason for that is that the image haven't been completely saved, but that no seems to be a good option because the file should have been locked and couldn't be streamed.
Here, take a look..
http://i1182.photobucket.com/albums/x448/dphotowriter/2011-09-07_002928.png
I did a test. When I upload the image directly to Amazon via AWS it is fine. The problem lies somewhere between saving the image and the moment it is streams. Maybe is asynchronous and the image hasn't finished to be written completely and then uploaded only part of it.
I tried to put:
System.Threading.Thread.Sleep(5000);
after the optimization to but it didn't help either. Maybe it something to do with the STREAM for that PNG files. I do the following:
1) Save the image to a temp.png file.
2) Read the file to an image object
3) convert the file to byte array
4) pass the byte array to the MemoryStream constructor