does anyone know a smooth / fast way of removing transparency from e.g. pngs/tiffs etc and replacing it with a white background?
Basically what I need this for is I need to create PDF/A compatible images, which may, according to the spec, have -no- transparency (and therefore a fixed white background is fine).
Any ideas / suggestions?
Cheers & thanks, -Jörg
The CSS for this is opacity:1;. When the mouse pointer moves away from the image, the image will be transparent again. An example of reversed hover effect: When using the opacity property to add transparency to the background of an element, all of its child elements inherit the same transparency.
The opacity property specifies the opacity/transparency of an element. The opacity property can take a value from 0.0 - 1.0. The lower value, the more transparent: The opacity property is often used together with the :hover selector to change the opacity on mouse-over: The first CSS block is similar to the code in Example 1.
The CSS for this is opacity:1;. When the mouse pointer moves away from the image, the image will be transparent again. An example of reversed hover effect:
Transparency plays an important role in front end development. It lets you choose how transparent the elements on your web pages appear. You can adjust transparency in several ways – because of course, in CSS, there are multiple ways to do the same thing.
You have to remove the alpha channel. Otherwise you'll still have a transparent image - just without transparent areas.
class Program
{
static void Main(string[] args)
{
//this also works for different file formats
ReplaceTransparency(@"C:\Y\transparent.png", System.Drawing.Color.White).Save(@"C:\Y\no_transparency.png");
ReplaceTransparency(@"C:\Y\transparent.gif", System.Drawing.Color.White).Save(@"C:\Y\no_transparency.gif");
}
public static System.Drawing.Bitmap ReplaceTransparency(string file, System.Drawing.Color background)
{
return ReplaceTransparency(System.Drawing.Image.FromFile(file), background);
}
public static System.Drawing.Bitmap ReplaceTransparency(System.Drawing.Image image, System.Drawing.Color background)
{
return ReplaceTransparency((System.Drawing.Bitmap)image, background);
}
public static System.Drawing.Bitmap ReplaceTransparency(System.Drawing.Bitmap bitmap, System.Drawing.Color background)
{
/* Important: you have to set the PixelFormat to remove the alpha channel.
* Otherwise you'll still have a transparent image - just without transparent areas */
var result = new System.Drawing.Bitmap(bitmap.Size.Width, bitmap.Size.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
var g = System.Drawing.Graphics.FromImage(result);
g.Clear(background);
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
g.DrawImage(bitmap, 0, 0);
return result;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With