//返回图片的字节流byte[] private byte[] getImageByte(string StylePic) { //FileStream files = new FileStream(imagePath, FileMode.Open); //byte[] imgByte = new byte[files.Length]; //files.Read(imgByte, 0, imgByte.Length); //files.Close(); //return imgByte; byte[] retBytes = PrdManagerSoapClient.FileRead(frmImageReadFilePath, StylePic); return(retBytes); }
/// <summary> /// 获取图片文件 /// </summary> /// <param name="StylePic"></param> /// <param name="Pic_Version"></param> /// <returns></returns> public static byte[] PicFileRead(string StylePic, string Pic_Version) { if (StylePic == string.Empty || Pic_Version == string.Empty) { return(null); } string AppPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string AllPath = AppPath + frmImageFilePath; string PicFileName = string.Format("{0}\\{1}_ver{2}", AllPath, StylePic, Pic_Version); byte[] retBytes = null; if (!Directory.Exists(AllPath)) { Directory.CreateDirectory(AllPath); } if (File.Exists(PicFileName)) { retBytes = GetbytesFromFile(PicFileName); } else { if (PrdManagerSoapClient != null) { try { retBytes = PrdManagerSoapClient.FileRead(frmImageReadFilePath, StylePic); string[] oldPics = Directory.GetFiles(string.Format("{0}\\", AllPath), string.Format("{0}_ver*", StylePic)); if (retBytes != null) { foreach (string o in oldPics) { File.SetAttributes(o, FileAttributes.Normal); File.Delete(o); } File.WriteAllBytes(PicFileName, retBytes); } else { if (oldPics.Length > 0) { retBytes = GetbytesFromFile(oldPics[0]); } } } catch (ObjectDisposedException) { } } } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); return(retBytes); }