public ColorProfileInfo(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } this.path = fileName; ColorProfileHelper.GetProfileInfo(fileName, out this.description, out this.colorSpace); }
protected override void OnShown(EventArgs e) { base.OnShown(e); try { string srgbProfile = ColorProfileHelper.GetSRGBProfilePath(); if (this.inputProfile == null) { this.inputProfile = new ColorProfileInfo(srgbProfile); } this.inputProfileDescription.Text = this.inputProfile.Description; if (this.displayProfile == null) { string displayProfilePath = ColorProfileHelper.GetMonitorColorProfilePath(this.Handle); if (string.IsNullOrEmpty(displayProfilePath)) { displayProfilePath = srgbProfile; } this.displayProfile = new ColorProfileInfo(displayProfilePath); } this.displayProfileDescription.Text = this.displayProfile.Description; if (this.proofingProfilesCombo.SelectedIndex == -1) { this.proofingProfilesCombo.SelectedIndex = 0; } } catch (IOException ex) { ShowErrorMessage(ex.Message); } catch (UnauthorizedAccessException ex) { ShowErrorMessage(ex.Message); } catch (Win32Exception ex) { ShowErrorMessage(ex.Message); } }
private bool SaveImage() { bool result = false; ColorProfileInfo profile = this.proofingProfileIndex >= 0 ? this.proofingColorProfiles[this.proofingProfileIndex] : this.inputProfile; if (CanSaveInColorSpace(profile.ColorSpace)) { try { if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK) { bool tiff = SaveFormatIsTIFF(this.saveFileDialog1.FileName); using (SaveOptionsDialog optionsDialog = new SaveOptionsDialog(tiff, profile)) { optionsDialog.BackColor = BackColor; optionsDialog.ForeColor = ForeColor; if (optionsDialog.ShowDialog(this) == DialogResult.OK) { SaveOptions options = optionsDialog.Options; BitmapSource source = null; Uri destinationProfileUri = null; if (profile.Equals(this.inputProfile)) { // No conversion is necessary when saving as the input color profile. source = GetBitmapSourceFromEffectSourceSurface(tiff, options); destinationProfileUri = new Uri(this.inputProfile.Path, UriKind.Absolute); } else { // Convert the image to the destination color profile. PixelFormat destinationPixelFormat = GetDestiniationPixelFormat(tiff, profile.ColorSpace); WriteableBitmap writable = new WriteableBitmap( this.EffectSourceSurface.Width, this.EffectSourceSurface.Height, options.HorizontalResolution, options.VerticalResolution, destinationPixelFormat, null ); RenderingIntent destinationRenderingIntent = (RenderingIntent)this.proofingIntentCombo.SelectedIndex; ColorProfileHelper.ConvertToColorProfile( this.inputProfile.Path, profile.Path, destinationRenderingIntent, this.blackPointCheckBox.Checked, this.EffectSourceSurface, writable ); source = writable; // Write a new profile with the selected rendering intent, if necessary. if (ColorProfileHelper.ChangeProfileRenderingIntent(profile.Path, destinationRenderingIntent, out this.destinationProfileTempPath)) { destinationProfileUri = new Uri(this.destinationProfileTempPath, UriKind.Absolute); } else { destinationProfileUri = new Uri(profile.Path, UriKind.Absolute); } } BitmapEncoder encoder; if (tiff) { TIFFSaveOptions tiffOptions = (TIFFSaveOptions)options; encoder = new TiffBitmapEncoder() { Compression = tiffOptions.LZWCompression ? TiffCompressOption.Lzw : TiffCompressOption.None }; } else { JPEGSaveOptions jpegOptions = (JPEGSaveOptions)options; encoder = new JpegBitmapEncoder() { QualityLevel = jpegOptions.Quality, }; } ColorContext[] colorContexts = new ColorContext[] { new ColorContext(destinationProfileUri) }; encoder.Frames.Add(BitmapFrame.Create(source, null, null, Array.AsReadOnly(colorContexts))); using (FileStream stream = new FileStream(this.saveFileDialog1.FileName, FileMode.Create, FileAccess.Write, FileShare.None)) { encoder.Save(stream); } result = true; } } } } catch (IOException ex) { ShowErrorMessage(ex.Message); } catch (LCMSException ex) { ShowErrorMessage(ex.Message); } catch (OverflowException ex) { ShowErrorMessage(ex.Message); } catch (UnauthorizedAccessException ex) { ShowErrorMessage(ex.Message); } } return(result); }