Example #1
0
        /// <summary>
        /// Resize the image to the specified width and height.
        /// </summary>
        /// <param name="image">The image to resize.</param>
        /// <param name="width">The width to resize to.</param>
        /// <param name="height">The height to resize to.</param>
        /// <returns>The resized image.</returns>
        public static Bitmap GetAlphaMask(this Bitmap alpha)
        {
            var alphaData = alpha.GetBGRAData();
            var data      = new byte[alphaData.Length];

            for (int i = 0; i < data.Length; i += 4)
            {
                data[i]     = alphaData[i + 3];
                data[i + 1] = alphaData[i + 3];
                data[i + 2] = alphaData[i + 3];
                data[i + 3] = 255;
            }

            var bmp = new Bitmap(alpha.Width, alpha.Height);

            try
            {
                BitmapData bmpData = bmp.LockBits(
                    new Rectangle(0, 0, bmp.Width, bmp.Height),
                    ImageLockMode.WriteOnly, bmp.PixelFormat);

                Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
                bmp.UnlockBits(bmpData);
            }
            catch { bmp.Dispose(); throw; }

            return(bmp);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bmp"></param>
        /// <returns></returns>
        public static byte[] GetRGBAData(this Bitmap bmp)
        {
            var bytes = bmp.GetBGRAData();

            for (int i = 0; i < bytes.Length; i += 4)
            {
                var temp = bytes[i];
                bytes[i]     = bytes[i + 2];
                bytes[i + 2] = temp;
            }

            return(bytes);
        }
Example #3
0
        /// <summary>
        /// Resize the image to the specified width and height.
        /// </summary>
        /// <param name="image">The image to resize.</param>
        /// <param name="width">The width to resize to.</param>
        /// <param name="height">The height to resize to.</param>
        /// <returns>The resized image.</returns>
        public static void ApplyAlpha(this Bitmap bmp, Bitmap alpha)
        {
            var alphaData = alpha.GetBGRAData();
            var data      = bmp.GetBGRAData();

            for (int i = 0; i < data.Length; i += 4)
            {
                data[i + 3] = alphaData[i + 3];
            }

            try
            {
                BitmapData bmpData = bmp.LockBits(
                    new Rectangle(0, 0, bmp.Width, bmp.Height),
                    ImageLockMode.WriteOnly, bmp.PixelFormat);

                Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
                bmp.UnlockBits(bmpData);
            }
            catch { bmp.Dispose(); throw; }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static HSD_TOBJ ToTOBJ(this Bitmap bmp, GXTexFmt texFmt, GXTlutFmt palFmt)
        {
            var tobj = new HSD_TOBJ()
            {
                MagFilter   = GXTexFilter.GX_LINEAR,
                Flags       = TOBJ_FLAGS.COORD_UV | TOBJ_FLAGS.LIGHTMAP_DIFFUSE | TOBJ_FLAGS.COLORMAP_MODULATE | TOBJ_FLAGS.ALPHAMAP_MODULATE,
                HScale      = 1,
                WScale      = 1,
                WrapS       = GXWrapMode.CLAMP,
                WrapT       = GXWrapMode.CLAMP,
                SX          = 1,
                SY          = 1,
                SZ          = 1,
                GXTexGenSrc = 4,
                Blending    = 1
            };

            tobj.EncodeImageData(bmp.GetBGRAData(), bmp.Width, bmp.Height, texFmt, palFmt);

            return(tobj);
        }