zoukankan      html  css  js  c++  java
  • C# 读取本地图片 转存到其他盘符

    UpFileContent upfile = new UpFileContent();
    upfile.StationImageName = "123.png";
    FileStream fs = new FileStream(@"E:123.jpg", FileMode.Open, FileAccess.Read);
    Byte[] btye2 = new byte[fs.Length];
    fs.Read(btye2, 0, Convert.ToInt32(fs.Length));
    fs.Close();
    upfile.ImageContent = btye2;


    Stream sourceStream = new MemoryStream(upfile.ImageContent);
    FileStream targetStream = null;
    if (!sourceStream.CanRead)
    {
    throw new Exception("");
    }

    string DiskName = @"d:";
    string FileAddress = @"ProductImagesSmall";
    string LocationAddress = DiskName + FileAddress;

    if (!Directory.Exists(LocationAddress))
    {
    Directory.CreateDirectory(LocationAddress);
    }
    string filePath = Path.Combine(LocationAddress, upfile.StationImageName);
    using (targetStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write))
    {
    int count = 0;
    const int bufferlength = 4096;
    byte[] buffer = new byte[bufferlength];
    while ((count = sourceStream.Read(buffer, 0, bufferlength)) > 0)
    {
    targetStream.Write(buffer, 0, count);
    }
    targetStream.Close();
    sourceStream.Close();
    IsSuccess = true;
    }

  • 相关阅读:
    原型模式(8)
    工厂方法模式(7)
    代理模式(6)
    装饰模式(5)
    策略模式与简单工厂结合(4)
    策略模式(3)
    简单工厂模式(2)
    序(1)
    国际控制报文协议ICMP
    IP 转发分组的流程
  • 原文地址:https://www.cnblogs.com/androllen/p/3453309.html
Copyright © 2011-2022 走看看