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
using System; | |
using System.Net; | |
using System.IO; | |
using System.Windows.Forms; | |
using System.Drawing; | |
class ストリームからイメージを作成する | |
{ | |
[STAThread] | |
static void Main(string[] args) | |
{ | |
Application.Run(new MyForm()); | |
} | |
} | |
class MyForm : Form | |
{ | |
public MyForm() | |
{ | |
String uri = @"http://livedoor.blogimg.jp/borocso/imgs/3/6/36b40029.jpg"; | |
PictureBox pic = new PictureBox(); | |
this.Controls.Add(pic); | |
this.Size = new Size(600, 400); | |
pic.PointToClient(new Point(0, 0)); | |
pic.ClientSize = this.ClientSize; | |
Image image = null; | |
WebClient wc = new WebClient(); | |
using(Stream stream = wc.OpenRead(uri)) | |
{ | |
if(wc.ResponseHeaders["Content-Type"].StartsWith("image/")) | |
{ | |
image = Image.FromStream(stream); | |
pic.Image = image; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment