mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-26 12:27:27 -05:00
71 lines
2.7 KiB
C#
71 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
|
|
namespace PKHeX
|
|
{
|
|
public partial class Util
|
|
{
|
|
public static Image layerImage(Image baseLayer, Image overLayer, int x, int y, double trans)
|
|
{
|
|
Bitmap overlayImage = (Bitmap)overLayer;
|
|
Bitmap newImage = (Bitmap)baseLayer;
|
|
if (baseLayer == null) return overLayer;
|
|
for (int i = 0; i < (overlayImage.Width * overlayImage.Height); i++)
|
|
{
|
|
Color newColor = overlayImage.GetPixel(i % (overlayImage.Width), i / (overlayImage.Width));
|
|
Color oldColor = newImage.GetPixel(i % (overlayImage.Width) + x, i / (overlayImage.Width) + y);
|
|
newColor = Color.FromArgb((int)((double)(newColor.A) * trans), newColor.R, newColor.G, newColor.B); // Apply transparency change
|
|
// if (newColor.A != 0) // If Pixel isn't transparent, we'll overwrite the color.
|
|
{
|
|
// if (newColor.A < 100)
|
|
newColor = AlphaBlend(newColor, oldColor);
|
|
newImage.SetPixel(
|
|
i % (overlayImage.Width) + x,
|
|
i / (overlayImage.Width) + y,
|
|
newColor);
|
|
}
|
|
}
|
|
return newImage;
|
|
}
|
|
public static string GetTempFolder() // From 3DSSE's decompiled source.
|
|
{
|
|
string tempPath = Path.GetTempPath();
|
|
string str2 = "SE3DS";
|
|
str2 = "3DSSE";
|
|
tempPath = Path.Combine(tempPath, str2);
|
|
// Directory.CreateDirectory(tempPath);
|
|
return (tempPath + "/");
|
|
}
|
|
|
|
public static Color AlphaBlend(Color ForeGround, Color BackGround)
|
|
{
|
|
if (ForeGround.A == 0)
|
|
return BackGround;
|
|
if (BackGround.A == 0)
|
|
return ForeGround;
|
|
if (ForeGround.A == 255)
|
|
return ForeGround;
|
|
int Alpha = Convert.ToInt32(ForeGround.A) + 1;
|
|
int B = Alpha * ForeGround.B + (255 - Alpha) * BackGround.B >> 8;
|
|
int G = Alpha * ForeGround.G + (255 - Alpha) * BackGround.G >> 8;
|
|
int R = Alpha * ForeGround.R + (255 - Alpha) * BackGround.R >> 8;
|
|
int A = ForeGround.A;
|
|
if (BackGround.A == 255)
|
|
A = 255;
|
|
if (A > 255)
|
|
A = 255;
|
|
if (R > 255)
|
|
R = 255;
|
|
if (G > 255)
|
|
G = 255;
|
|
if (B > 255)
|
|
B = 255;
|
|
return Color.FromArgb(Math.Abs(A), Math.Abs(R), Math.Abs(G), Math.Abs(B));
|
|
}
|
|
}
|
|
}
|