Updated Questions and Answers (markdown)

master
asterixorobelix 9 years ago
parent
commit
b6f33a9c62
  1. 16
      Questions-and-Answers.md

16
Questions-and-Answers.md

@ -4,24 +4,24 @@ See: https://github.com/SixLabors/ImageSharp/issues/418
## How do I convert a JPG to a PNG image? ## How do I convert a JPG to a PNG image?
```cs ```cs
using (Image<Rgba32> image =Image.Load<Rgba32>($"{filename}.jpg")) using (Image<Rgba32> image =Image.Load<Rgba32>($"{filename}.jpg"))
{ {
image.Save($"{filename}.png"); image.Save($"{filename}.png");
} }
``` ```
ImageSharp will automatically choose the encoding based on the file extension used in the filename (eg .jpg or .png) ImageSharp will automatically choose the encoding based on the file extension used in the filename (eg .jpg or .png)
## How do I convert an image to black and white? ## How do I convert an image to black and white?
` ```cs
using (Image<Rgba32> image = Image.Load<Rgba32>($"{filename}.png")) using (Image<Rgba32> image = Image.Load<Rgba32>($"{filename}.png"))
{ {
image.Mutate(x=>x.BlackWhite()); image.Mutate(x=>x.BlackWhite());
image.Save($"{filename}blackWhite.png"); image.Save($"{filename}blackWhite.png");
} }
` ```
## How do I access the individual pixels of an image? ## How do I access the individual pixels of an image?
` ```cs
using (Image<Rgba32> image = Image.Load($"{filename}.png")) using (Image<Rgba32> image = Image.Load($"{filename}.png"))
{ {
var imageHeight = image.Height;//pixel height var imageHeight = image.Height;//pixel height
@ -29,4 +29,4 @@ using (Image<Rgba32> image = Image.Load($"{filename}.png"))
var pixels =image[200,200];//<1  1  1  1> var pixels =image[200,200];//<1  1  1  1>
var pixels2 = image[125, 180];//<0.7647059  0.7647059  0.7647059  1> var pixels2 = image[125, 180];//<0.7647059  0.7647059  0.7647059  1>
} }
` ```
Loading…
Cancel
Save