Does your company or startup need an expert? If so, write to me to talk about possibilities of professional cooperation.
PROGRAMMING on-line course is approaching! Write to me if you are interested in free early access.

Marcin Jamro, PhD, DSc

How to set JPEG quality with SkiaSharp?

C#  |  .NET  |  ASP.NET

If you want to specify the JPEG quality, just use the second parameter of the Encode method, as shown in the following code snippet:

using SKBitmap bitmap = new(/* Width */, /* Height */);
using SKCanvas canvas = new(bitmap);
/* Drawing */
using SKImage target = SKImage.FromBitmap(bitmap);
using SKData data = target.Encode(SKEncodedImageFormat.Jpeg, 90);
data.SaveTo(/* Stream */);

The full working example is provided below:

using SkiaSharp;

const int width = 1920;
const int height = 1080;
using SKBitmap bitmap = new(width, height);
using SKCanvas canvas = new(bitmap);
using SKPaint red = new() { Color = new SKColor(255, 0, 0) };
using SKPaint white = new() { Color = new SKColor(255, 255, 255) };
int yMiddle = height / 2;
canvas.DrawRect(100, 100, width - 200, yMiddle - 100, white);
canvas.DrawRect(100, yMiddle, width - 200, yMiddle - 100, red);
using SKImage target = SKImage.FromBitmap(bitmap);
using SKData data = target.Encode(SKEncodedImageFormat.Jpeg, 90);
using FileStream stream = new("image.jpg", FileMode.Create);

Of course, you should not forget to install the SkiaSharp package from the NuGet package manager.

The content, including any part of code, is presented without warranty, either express or implied. The author cannot be held liable for any damages caused or alleged to have been caused directly or indirectly by any content shown on this website.

Hello, I am Marcin

Reliable entrepreneur with 10+ years of companies operation, such as CEO at a few IT companies. I was an author of a few software & hardware products, still open to new ideas & cooperation.

Helpful expert with 10+ years of experience, together with PhD and DSc in Computer Science. I was an author of books and publications, as well as an expert in international projects.

Experienced developer with 10+ years of development and 100+ completed projects. I worked on various complex international projects, e.g. at Microsoft in USA and as CTO at a few companies. I have MCP, MCTS and MCPD certificates.

You can read more about me in my short bio. I am waiting for contact at [email protected], as well as at my Facebook and LinkedIn profiles.


I am an author of a few books and numerous publications, also in high-quality international scientific journals.

If you want to learn data structures and algorithms in the context of C#, let's take a look at my newest book. It is the second edition of C# Data Structures and Algorithms. You can buy it here.


Do you like traveling? If so, discover an amazing world with local guides, right here and right now at:


I love travels, learning new cultures and regions, meeting outstanding people, as well as taking pictures of beautiful places. Take a look at my travel diary.