public void SetBackgroundImage(string imageFileName, Control control, int width, int height) { _control = new ControlProxy(control); SetBackgroundImage(imageFileName, _control, width, height); //if (string.IsNullOrEmpty(imageFileName) || !File.Exists(imageFileName)) //{ // SetNewBackground(control, null); // _previousImageFileInfo = null; // return; //} //// если имидж не изменился, то не надо ничего менять //if (IsPreviousFile(imageFileName)) return; ////if (!IsFileChange(imageFileName)) return; //// если простой имидж то его и загружаем, если PowerPoint, то вытаскиваем из него //if (IsPowerPointPresentation(imageFileName)) //{ // string file; // if (IsFileChange(imageFileName)) // { // file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // //if (!Directory.Exists(file)) // // Directory.CreateDirectory(file); // bool isSuccess; // using (PowerPoint powerPoint = PowerPoint.OpenFile(imageFileName)) // { // isSuccess = powerPoint.SaveSlideToFile(1, file, width, height); // } // if (!isSuccess) return; // _fileTemps[imageFileName] = file; // } // else // { // file = _fileTemps[imageFileName]; // } // LoadImageFromFile(control, file); //} //else //{ // LoadImageFromFile(control, imageFileName); //} }
public void SetBackgroundImage(string imageFileName, IBackgroundSupport control) { if (string.IsNullOrEmpty(imageFileName) || !File.Exists(imageFileName)) { SetNewBackground(control, null); _previousImageFileInfo = null; return; } // если имидж не изменился, то не надо ничего менять if (IsPreviousFile(imageFileName)) return; //if (!IsFileChange(imageFileName)) return; // если простой имидж то его и загружаем, если PowerPoint, то вытаскиваем из него if (IsPowerPointPresentation(imageFileName)) { string file; if (IsFileChange(imageFileName)) { file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); //if (!Directory.Exists(file)) // Directory.CreateDirectory(file); bool isSuccess; using (PowerPoint powerPoint = PowerPoint.OpenFile(imageFileName)) { isSuccess = powerPoint.SaveSlideToFile(1, file); } if (!isSuccess) return; _fileTemps[imageFileName] = file; } else { file = _fileTemps[imageFileName]; } LoadImageFromFile(control, file); } else { LoadImageFromFile(control, imageFileName); } }
private void SetNewBackground(IBackgroundSupport control, Image image) { if (control.Background != null) { control.Background.Dispose(); } control.Background = image; }
void LoadImageFromFile(IBackgroundSupport control, string file) { Image image; try { image = Image.FromFile(file); } catch (Exception) { image = null; return; } SetNewBackground(control, image); }
public void SetBackgroundImage(string imageFileName, IBackgroundSupport control, int width, int height) { _control = control; if (string.IsNullOrEmpty(imageFileName) || !File.Exists(imageFileName)) { SetNewBackground(control, null); _previousImageFileInfo = null; return; } // если имидж не изменился, то не надо ничего менять if (IsPreviousFile(imageFileName)) return; //if (!IsFileChange(imageFileName)) return; // если простой имидж то его и загружаем, если PowerPoint, то вытаскиваем из него // концепция изменилась - теперь сначала пробуем загрузить имидж, так как на агенте- это будет именно имидж, тут мы сэкономим в скорости на агенте bool isSuccess = LoadImageFromFile(control, imageFileName); if (!isSuccess) { try { // если здесь, то предполагаем что у нас PowerPoint // для оптимизации НЕ проверяем вначале это string file = string.Empty; if (!_fileTemps.TryGetValue(imageFileName, out file) | IsFileChange(imageFileName)) { file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); //if (!Directory.Exists(file)) // Directory.CreateDirectory(file); using (PowerPoint powerPoint = PowerPoint.OpenFile(imageFileName)) { isSuccess = powerPoint.SaveSlideToFile(1, file, width, height); } if (!isSuccess) return; _fileTemps[imageFileName] = file; } LoadImageFromFile(control, file); } catch { return; } } //if (IsPowerPointPresentation(imageFileName)) //{ // string file; // if (IsFileChange(imageFileName)) // { // file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // //if (!Directory.Exists(file)) // // Directory.CreateDirectory(file); // bool isSuccess; // using (PowerPoint powerPoint = PowerPoint.OpenFile(imageFileName)) // { // isSuccess = powerPoint.SaveSlideToFile(1, file, width, height); // } // if (!isSuccess) return; // _fileTemps[imageFileName] = file; // } // else // { // file = _fileTemps[imageFileName]; // } // LoadImageFromFile(control, file); //} //else //{ // LoadImageFromFile(control, imageFileName); //} }