Checks if an image has any transparency. - CSharp System.Drawing

CSharp examples for System.Drawing:Image Operation

Description

Checks if an image has any transparency.

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using System;//ww  w  .j  a  v a2  s.com

public class Main{
        /// <summary>
        /// Checks if an image has any transparency.
        /// </summary>
        public static bool HasAlpha(Bitmap bmp) {
            for (int y = 0; y < bmp.Height; y++) {
                for (int x = 0; x < bmp.Width; x++) {
                    if (bmp.GetPixel(x, y).A < 255) {
                        return true;
                    }
                }
            }
            return false;
        }
}

Related Tutorials