This repository was archived by the owner on Mar 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 174
ImageInterpolationMode not working with GdipDrawImageRectRect #730
Copy link
Copy link
Open
Description
Setting Graphics.ImageInterpolationMode has no effect.
The following code:
var target = new Bitmap(100, 100);
using (var g = Graphics.FromImage(target))
{
g.Clear(Color.Red);
g.PixelOffsetMode = PixelOffsetMode.Half;
g.InterpolationMode = InterpolationMode.NearestNeighbor;
var bmp = new Bitmap(2, 2);
bmp.SetPixel(0, 0, Color.Black);
bmp.SetPixel(0, 1, Color.White);
bmp.SetPixel(1, 0, Color.White);
bmp.SetPixel(1, 1, Color.Black);
var destRect = new RectangleF(20, 20, 60, 60);
var srcRect = new RectangleF(0, 0, 2, 2);
g.DrawImage(bmp, destRect, srcRect, GraphicsUnit.Pixel);
}
It is expect to render like this:

We are building libgdiplus from main.
The problem seems to be at the end of GdipDrawImageRectRect. It creates two surfaces, and sets an interpolation for the first of them. I can't see that that surface is used for anything. Seems to be dead code? For the second surface no interpolation filter is set. The commented out line fixes the issue:
gdip_bitmap_ensure_surface (preprocessed_image);
filter = cairo_pattern_create_for_surface (preprocessed_image->surface);
cairo_pattern_set_filter (filter, gdip_get_cairo_filter (graphics->interpolation));
cairo_matrix_translate (&mat, srcx, srcy);
if (!gdip_near_zero(srcwidth - dstwidth) || !gdip_near_zero(srcheight - dstheight))
cairo_matrix_scale (&mat, srcwidth / dstwidth, srcheight / dstheight);
cairo_matrix_translate (&mat, -dstx, -dsty);
pattern = cairo_pattern_create_for_surface (preprocessed_image->surface);
// cairo_pattern_set_filter (pattern, gdip_get_cairo_filter (graphics->interpolation));
cairo_pattern_set_matrix (pattern, &mat);
Metadata
Metadata
Assignees
Labels
No labels
