zoukankan      html  css  js  c++  java
  • 获取网络图片验证码转换字节流保存本地并显示

     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.IO;
     7 using System.Linq;
     8 using System.Net;
     9 using System.Text;
    10 using System.Threading.Tasks;
    11 using System.Windows.Forms;
    12 
    13 namespace _0922
    14 {
    15     public partial class Form1 : Form
    16     {
    17         public Form1()
    18         {
    19             InitializeComponent();
    20         }
    21 
    22         private void Form1_Load(object sender, EventArgs e)
    23         {
    24             //将服务器上图片保存本地
    25             string url = string.Format("https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew?module=regist&rand=sjrand&0.5173300584942714");
    26             //创建一个request 同时可以配置requst其余属性
    27 
    28             System.Net.WebRequest imgRequst = System.Net.WebRequest.Create(url);
    29             //在这里我是以流的方式保存图片
    30 
    31             System.Drawing.Image downImage = System.Drawing.Image.FromStream(imgRequst.GetResponse().GetResponseStream());
    32 
    33             string dertory = "C:\test\";
    34 
    35             string fileName = string.Format("{0}.jpg", DateTime.Now.ToString("HHmmssffff"));
    36 
    37             if (!System.IO.Directory.Exists(dertory))
    38             {
    39 
    40                 System.IO.Directory.CreateDirectory(dertory);
    41             }
    42 
    43             downImage.Save(dertory + fileName,System.Drawing.Imaging.ImageFormat.Jpeg);
    44 
    45             downImage.Dispose();
    46 
    47             this.pictureBox1.Image = Image.FromFile(dertory+fileName);
    48            
    49 
    50 
    51         }
    52        
    53 
    54 
    55 
    56     }
    57 }
  • 相关阅读:
    Zookeeper zkCli.sh常用命令
    windows 服务
    Zookeeper的下载安装
    Zookeeper 基础知识
    在Java中使用Redis
    Redis 集群(cluster)
    Redis 哨兵(Sentinel)机制
    Redis 主从复制
    Redis 发布/订阅
    Redis 事务
  • 原文地址:https://www.cnblogs.com/xiaz/p/4828431.html
Copyright © 2011-2022 走看看