mirror of
https://github.com/4sval/FModel.git
synced 2026-07-20 18:18:48 -05:00
new opacity method (fix?)
This commit is contained in:
parent
7d74ff4c2f
commit
e9a4a1051b
|
|
@ -61,7 +61,7 @@ namespace FModel.Methods.Utilities
|
|||
{
|
||||
if (string.IsNullOrEmpty(FProp.Default.FOutput_Path))
|
||||
{
|
||||
FProp.Default.FOutput_Path = AppDomain.CurrentDomain.BaseDirectory + "\\Output";
|
||||
FProp.Default.FOutput_Path = AppDomain.CurrentDomain.BaseDirectory + "Output";
|
||||
FProp.Default.Save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,33 +30,48 @@ namespace FModel.Methods.Utilities
|
|||
|
||||
public static BitmapSource CreateTransparency(BitmapSource source, int opacity)
|
||||
{
|
||||
if (source.Format != PixelFormats.Bgra32)
|
||||
int pixelsCount = source.PixelWidth * source.PixelHeight;
|
||||
int[] pixels = new int[pixelsCount];
|
||||
int stride = (source.PixelWidth * source.Format.BitsPerPixel + 7) / 8;
|
||||
source.CopyPixels(pixels, stride, 0);
|
||||
|
||||
for (int i = 0; i < pixelsCount; i++)
|
||||
{
|
||||
return source;
|
||||
int alpha = (pixels[i] >> 24) & 255;
|
||||
int red = (pixels[i] >> 16) & 255;
|
||||
int green = (pixels[i] >> 8) & 255;
|
||||
int blue = pixels[i] & 255;
|
||||
|
||||
alpha = ChangeColorOpacity(alpha, opacity);
|
||||
|
||||
int color = (alpha << 24) + (red << 16) + (green << 8) + blue;
|
||||
|
||||
pixels[i] = color;
|
||||
}
|
||||
|
||||
int bytesPerPixel = (source.Format.BitsPerPixel + 7) / 8;
|
||||
int stride = bytesPerPixel * source.PixelWidth;
|
||||
byte[] buffer = new byte[stride * source.PixelHeight];
|
||||
BitmapSource result = BitmapSource.Create(source.PixelWidth, source.PixelHeight, source.DpiX, source.DpiY,
|
||||
PixelFormats.Bgra32, null, pixels, stride);
|
||||
|
||||
source.CopyPixels(buffer, stride, 0);
|
||||
return result;
|
||||
}
|
||||
private static int ChangeColorOpacity(int color, int opacity)
|
||||
{
|
||||
color -= 255 - opacity;
|
||||
|
||||
for (int y = 0; y < source.PixelHeight; y++)
|
||||
return AdjustColorValue(color);
|
||||
}
|
||||
private static int AdjustColorValue(int color)
|
||||
{
|
||||
if (color > 255)
|
||||
{
|
||||
for (int x = 0; x < source.PixelWidth; x++)
|
||||
{
|
||||
int i = stride * y + bytesPerPixel * x;
|
||||
if (buffer[i + 3] != 0x00) //do not change the pixels that are already transparent god dammit
|
||||
{
|
||||
buffer[i + 3] = Convert.ToByte(opacity);
|
||||
}
|
||||
}
|
||||
color = 255;
|
||||
}
|
||||
else if (color < 0)
|
||||
{
|
||||
color = 0;
|
||||
}
|
||||
|
||||
return BitmapSource.Create(
|
||||
source.PixelWidth, source.PixelHeight,
|
||||
source.DpiX, source.DpiY,
|
||||
source.Format, null, buffer, stride);
|
||||
return color;
|
||||
}
|
||||
|
||||
public static void LoadImageAfterExtraction(DrawingVisual image)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@
|
|||
<img src="https://img.shields.io/github/v/release/iamasval/fmodel"
|
||||
alt="Releases">
|
||||
</a>
|
||||
<a href="https://github.com/iAmAsval/FModel/releases/latest">
|
||||
<img src="https://img.shields.io/github/downloads/iAmAsval/FModel/latest/total.svg?label=v3.0%20Downloads"
|
||||
alt="Downloads">
|
||||
</a>
|
||||
<a href="https://twitter.com/AsvalFN"><img src="https://img.shields.io/badge/Twitter-@AsvalFN-1da1f2.svg?logo=twitter"></a>
|
||||
<a href="https://discord.gg/fdkNYYQ">
|
||||
<img src="https://img.shields.io/badge/Discord-Need%20Help%3F-778cd4.svg?logo=discord">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user