Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

sample code for the Wiki

Aperta
#450 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
documentation

Direzione di ricerca

La issue fornisce due esempi C# per Magick.NET: proprietà di base delle immagini e gestione dei profili colore con conversioni seppia e in scala di grigi. Per prima cosa individua la posizione appropriata nel Wiki e verifica le convenzioni attuali per gli esempi; il lavoro sarà considerato completato quando gli esempi saranno integrati lì in una forma chiara e utilizzabile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
Prerequisites
  • I have written a descriptive issue title
  • I have verified that I am using the latest version of Magick.NET
System Configuration
  • Magick.NET version:
  • Environment (Operating system: Windows
Samples

Sample 1 -- List basic properties of input file (file = path of image).

  MagickReadSettings settings = new MagickReadSettings();
            settings.Verbose = true;
            settings.Debug = true;

 using (MagickImage image = new MagickImage(file, settings))
                        {
                            // Attach event handler to warning event
                            image.Warning += MagickImage_Warning;

                            Console.WriteLine("MagicKImage" + image.Format.ToString() + ", " + image.BaseWidth + ", " + image.BaseHeight +
                                ", Depth: " + image.Depth + ", Channels: " + image.ChannelCount +
                                ", ColorSpace:" + image.ColorSpace.ToString());
                            Console.WriteLine("MimeType: " + image.FormatInfo.MimeType +
                                ", Type: " + image.GetType().ToString() +
                                ", MultiFramed: " + image.FormatInfo.IsMultiFrame.ToString() +
                                 ", HasAlpha: " + image.HasAlpha.ToString());

                            Console.WriteLine("Comment:" + image.Comment);
}

Sample 2 - Color profile handling and conversion sample (sepia and grayscale).

/// ImageMagick.GetNextImageProperty(image);
using (MagickImage image = new MagickImage(file, settings))
{
/// ============================ COLOR PRofile testing
///
ColorProfile icc = image.GetColorProfile();
ImageMagick.ColorProfile profile = null;
String dest = null;
image.Comment = "mark test";
String CMYKProfilePath = "e:\Images\jpg\Test CMYK Profile.icc";
String GRAYProfilePath = "e:\Images\jpg\Test GRAY Profile.icc";
String RGBProfilePath = "e:\Images\jpg\Test RGB Profile.icc";
String baseName = Path.GetFileNameWithoutExtension(file);
String basePath = Path.GetFullPath(file);

                        Console.WriteLine("\nColor profile: {0}, colorSpace {1}", icc.Name, icc.ColorSpace);
                        ImageMagick.ColorSpace sourceImageColorSpace = image.ColorSpace;

                        //Check if image color space is of type CMYK, add color profile accordingly
                        if (sourceImageColorSpace == ImageMagick.ColorSpace.CMYK)
                        {
                            
                            //Adding of other color profiles code commented till the time the issue of multiple profile addition resolved
                            //_profilesCMYK is the list containing the ICSProfiles
                            if (CMYKProfilePath != "")
                            {   //Create a new color profile object according to selection and add it into image
                                IMagickImage clone = image.Clone();
                                clone.TransformColorSpace(ColorProfile.AdobeRGB1998);   // input must have a color profile
                                
                                // used file saved on disk...
                                profile = new ImageMagick.ColorProfile(CMYKProfilePath);
                                image.AddProfile(profile, true);    // true = replace profile with selected one (ie. path)
                                image.TransformColorSpace(ColorProfile.AdobeRGB1998);

                                image.Format = MagickFormat.Jpeg;
                                // Save the result
                                dest = "e:\\images\\jpg\\"+baseName +"-cmykToRGB.jpg";
                                image.Write(dest);
                         
                                dest = "e:\\images\\jpg\\" + baseName + "-cmykToRGBusingInput.jpg";
                                clone.TransformColorSpace(ColorProfile.AdobeRGB1998);   // convert to RGB applying input profile
                                clone.Write(dest);
                                
                                // test converting to Gray scale..
                                IMagickImage Sepia = image.Clone();
                                Sepia.SepiaTone();
                                dest = "e:\\images\\jpg\\" + baseName + "-cmykToSepia.jpg";
                                Sepia.Write(dest);
                                
                                // test converting to Gray scale..
                                IMagickImage grey = image.Clone();
                                grey.Grayscale();
                                dest = "e:\\images\\jpg\\" + baseName + "-cmykToGray.jpg";
                                grey.Write(dest);

                                grey.Format = MagickFormat.Png;
                                dest = "e:\\images\\jpg\\" + baseName + "-cmykToGray.png";
                                grey.Write(dest);
                                grey.Format = MagickFormat.Tiff;
                                dest = "e:\\images\\jpg\\" + baseName + "-cmykToGray.tiff";
                                grey.Write(dest);

                                // Test stripping all profiles

                                dest = "e:\\images\\jpg\\" + baseName + "-cmykToRGBNoProfiles.jpg";
                                image.Strip();
                                image.Write(dest);
                                continue;
                            }//End if
                        }

                        //Check if image color space is of type RGB, add color profile accordingly
                        else if (sourceImageColorSpace == ImageMagick.ColorSpace.RGB ||
                                 sourceImageColorSpace == ImageMagick.ColorSpace.sRGB)
                        {
                            image.Format = MagickFormat.Jpeg;
                            image.BorderColor = MagickColor.FromRgb(255, 0, 0);
                            image.Border(5);

                            // Save the result
                            dest = "e:\\images\\jpg\\" + baseName + "-isRGB.jpg";
                            image.TransformColorSpace(ColorProfile.AdobeRGB1998);       // Convert to RGB using input Profile.
                            image.Write(dest);

                            dest = "e:\\images\\jpg\\" + baseName + "-isRGBSepia.jpg";
                            image.SepiaTone();
                            image.Write(dest);

                            //ICSPrfile is the object containing the name and path of availabe prfiles
                            //_profilesRGB is the list containing the ICSProfiles
                            if (RGBProfilePath != "")
                            {   //Create a new color profile object according to selection and add it into image
                              //  profile = new ImageMagick.ColorProfile(RGBProfilePath);
                               // image.AddProfile(profile, true);    // Overwrite Existing.
                            }//End if
                            continue;
                        }

                        //Check if image color space is of type GRAY, add color profile accordingly
                        else if (sourceImageColorSpace == ImageMagick.ColorSpace.Gray)
                        {
                            if (GRAYProfilePath != "")
                            {   //Create a new color profile object according to selection and add it into image
                               profile = new ImageMagick.ColorProfile(GRAYProfilePath);
                                image.AddProfile(profile, true);        // Replace input profile (not applying input)
                                image.TransformColorSpace(ColorProfile.AdobeRGB1998);   // convert to RGB.

                                image.Format = MagickFormat.Jpeg;
                                // Save the result
                                dest = "e:\\images\\jpg\\GrayToRGB.jpg";
                                image.Write(dest);
                                continue;
                            }//End if
                        }

}

Lingua principale
C#
Stelle
4k
Fork
453
Merge medio
12h 54m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dlemstra/Magick.NET

Tutte le issue di dlemstra/Magick.NET

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.