Это мой оригинальный img
[img]https://i .sstatic.net/3GcOmfZl.jpg[/img]
И вот результат
Это мой код:
public static void GetThumbNail(
string sourcePath,
string targetPath,
int width,
int height,
int R = 255,
int G = 255,
int B = 255)
{
if (targetPath == null)
targetPath = Path.Combine(Path.GetDirectoryName(sourcePath), $"{Path.GetFileNameWithoutExtension(sourcePath)}_Thumb{Path.GetExtension(sourcePath)}");
Image main = Image.Black(width, height, 3);
main = main + new[] { R, G, B };
Image watermark = Image.Thumbnail(sourcePath, width, height);
int top = (main.Height - watermark.Height) / 2;
int left = (main.Width - watermark.Width) / 2;
// extract related area from main image
var baseImage = main.Crop(left, top, watermark.Width, watermark.Height);
// composite the two areas using the PDF "over" mode
var composite = baseImage.Composite(watermark, Enums.BlendMode.Over);
// the result will have an alpha, and our base image does not..we must flatten
// out the alpha before we can insert it back into a plain RGB JPG image
composite = composite.Flatten();
// insert composite back in to main image on related area
var combined = main.Insert(composite, left, top);
combined.WriteToFile(targetPath);
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-of-image
Мобильная версия