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 }
  • 相关阅读:
    什么是lambda
    Google guava工具类的介绍和使用
    Java并发编程:Java创建线程的三种方式
    线程池之ThreadPoolExecutor概述
    idea Spring-boot三种启动方式
    linux 安装kong gateway
    Beautiful Soup 的使用问题
    python与tesserocr的安装和使用
    python中关于yeild关键字的用法
    springboot——@EnableConfigurationProperties是如何起作用
  • 原文地址:https://www.cnblogs.com/xiaz/p/4828431.html
Copyright © 2011-2022 走看看