1
votes

I am writing some code to generate images - essentially I have a source image that is large and includes transparent regions.

I use GDI+ to open that image and add additional objects.

What I want to do next is to save this new image much smaller, so I used the Bitmap constructor that takes a source Image object and a height and width, then saved that.

I was expecting the alpha channel to be smoothed like the color channels, but this did not happen -- it did result in a couple of semitransparent pixels, but overall it is very blocky. What gives?

Using img As New Bitmap("source100x100.png")
 ''// Drawing stuff
 Using simg As New Bitmap(img, 20, 20)
  simg.Save("target20x20.png")
 End Using
End Using

Edit: I think what I want is SuperSampling, like what Paint.NET does when set to "Best Quality"

1

1 Answers

2
votes

Draw the image on the new bitmap instead of creating the new bitmap from the image.

Create an empty bitmap by just specifying the size, then use the Graphics.FromImage method to create a Graphics object for the bitmap. Use the DrawImage method to draw the image onto the new bitmap.

There are properties like Interpolationmode and PixelOffsetMode in the Graphics object that you can use to control how the image is scaled and drawn.