从URL将图像拉入字节数组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从URL将图像拉入字节数组相关的知识,希望对你有一定的参考价值。
This snippet pulls down an image from a URL into a byte(). From there you can re-size or save.Don't forget the necessary try - catch.
public byte[] getImageFromUrl(string url) { System.Net.HttpWebRequest request = null; System.Net.HttpWebResponse response = null; byte[] b = null; request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); response = (System.Net.HttpWebResponse)request.GetResponse(); if (request.HaveResponse) { if (response.StatusCode == System.Net.HttpStatusCode.OK) { Stream receiveStream = response.GetResponseStream(); { b = br.ReadBytes(500000); br.Close(); } } } return b; }
以上是关于从URL将图像拉入字节数组的主要内容,如果未能解决你的问题,请参考以下文章
如何从从json获得的url加载图像到collectionview