I have just started using imagesharp and I imagine that many of my questions regarding the package will be asked by others. So, I have begun a Q&A page

master
asterixorobelix 9 years ago
parent
commit
d61c7d2c9e
  1. 32
      Questions-and-Answers.md

32
Questions-and-Answers.md

@ -0,0 +1,32 @@
## Have I installed the correct Nuget package?
See: https://github.com/SixLabors/ImageSharp/issues/418
## How do I convert a JPG to a PNG image?
`
using (Image<Rgba32> image =Image.Load<Rgba32>($"{filename}.jpg"))
{
image.Save($"{filename}.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?
`
using (Image<Rgba32> image = Image.Load<Rgba32>($"{filename}.png"))
{
image.Mutate(x=>x.BlackWhite());
image.Save($"{filename}blackWhite.png");
}
`
## How do I access the individual pixels of an image?
`
using (Image<Rgba32> image = Image.Load($"{filename}.png"))
{
var imageHeight = image.Height;//pixel height
var imageWidth = image.Width;
var pixels =image[200,200];//<1  1  1  1>
var pixels2 = image[125, 180];//<0.7647059  0.7647059  0.7647059  1>
}
`
Loading…
Cancel
Save