workingpopla.blogg.se

What is edge blending in bitmaps called
What is edge blending in bitmaps called















Because the background is already transparent, it doesn’t need to call MakeTransparent for this bitmap. This time it clears the bitmap with the color Transparent before it draws. Next, the program repeats roughly the same steps to make another smiley bitmap. It then calls the bitmap’s MakeTransparent method to make the white pixels transparent. It clears the bitmap with white and then calls the DrawSmiley method described shortly to draw on it. The form’s Load event handler first creates the FgOnWhite bitmap.

#WHAT IS EDGE BLENDING IN BITMAPS CALLED CODE#

The code declares the FgOnWhite and FgOnTransparent bitmaps outside of any method so all of the form’s code can use them. Using (Graphics gr = Graphics.FromImage(FgOnTransparent)) Gr.SmoothingMode = SmoothingMode.AntiAlias ĭrawSmiley(gr, pictureBox1.ClientRectangle, 10) Using (Graphics gr = Graphics.FromImage(FgOnWhite)) Private void Form1_Load(object sender, EventArgs e) Draw the smiley bitmaps with transparent backgrounds. private Bitmap FgOnWhite, FgOnTransparent The following code shows how the program draws its two smiley bitmaps, each of which contains some transparent background pixels. (You can also see in both smileys how the black and yellow pixels blend together.) Code In the right smiley, those pixels have colors that include some transparency so they blend the smiley’s black edge with any background color (in this case, blue). In the left smiley, they are shades of gray that blended the original white background with the smiley’s black edge. In this enlarged image, you can easily see the pixels that provide the anti-aliasing. The picture on the right shows a closeup of the area between the smileys. If you look closely, you’ll see that the smiley’s edge blend smoothly with the background. The program uses this third approach to draw the right smiley in the picture at the top of this post. Now no matter what background you place behind the bitmap, the transparent parts of the image will blend perfectly. Then the anti-aliasing will make the appropriate pixels semi-transparent as needed just as if you had taken the second approach. It also requires you to examine every pixel in the the image, which could be slow.Ī third approach, and by far the best, is to draw the original image on a transparent background. This approach should work well, but only if you know which colors show the anti-aliasing. For example, if a gray pixel is 50% white and 50% black, you would convert it into 50% transparent and 50% black. You would then convert the background component into a transparent component. In this example, you would look for shades of gray. If you are simply given an image with transparent pixels and you need to place it over a specific background image, then you might not have that luxury.Ī second approach would be to examine all of the transparent bitmap’s pixels and find the ones that use anti-aliasing. That solution only works if you have control over how the original image or the final image is produced. In this example, the program could either use a blue background for the original image before calling MakeTransparent, or it could use a white background in the final image instead of a blue one. Then the anti-aliased pixels blend properly. First, you can ensure that the background in the original image matches (at least approximately) the background in the final image on which you display the bitmap. There are a couple of ways that you can fix this problem. (Look closely at the edges of the left smiley in the picture above.) Approaches When the program draws the result on the blue background, you can still see the gray pixels along the edge of the smiley face. Then when the program calls MakeTransparent, that method only makes the pixels that are pure white into transparent pixels. For example, where the smiley’s black outline pixels meet the white background, some pixels are converted into shades of gray to make them blend more smoothly together. The result is that the pixels at the border between two colors are blended. The problem is that the smiley face was drawn with anti-aliasing.

what is edge blending in bitmaps called what is edge blending in bitmaps called

It finished by copying the bitmap, which now has some transparent pixels, onto a PictureBox that has a blue background. It then used the bitmap’s MakeTransparent method to make the image’s white pixels transparent. To make the drawing on the left, the program drew a smiley face in a bitmap with a white background.

what is edge blending in bitmaps called

To see where the problem occurs, consider the picture at the top of this post. Unfortunately, when you use both anti-aliasing and transparency, you can get some odd results. Transparency allows you to place an image on top of another image so parts of the underlying image show through. Anti-aliasing makes drawn lines look smoother on a raster image such as a bitmap or on the screen.















What is edge blending in bitmaps called