mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Added random opacity option
This commit is contained in:
parent
f07a90a910
commit
612ccc8ecc
1 changed files with 29 additions and 2 deletions
|
@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
|
|||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -73,6 +74,15 @@ public int ImageCount
|
|||
[DefaultValue(360)]
|
||||
public int RandomRotateMax { get; set; }
|
||||
|
||||
[DefaultValue(false)]
|
||||
public bool RandomOpacity { get; set; }
|
||||
|
||||
[DefaultValue(0)]
|
||||
public int RandomOpacityMin { get; set; }
|
||||
|
||||
[DefaultValue(100)]
|
||||
public int RandomOpacityMax { get; set; }
|
||||
|
||||
public DrawRandomImages()
|
||||
{
|
||||
this.ApplyDefaultPropertyValues();
|
||||
|
@ -140,12 +150,29 @@ private void DrawImage(Image img, Image img2, Graphics g)
|
|||
{
|
||||
float moveX = rect.X + (rect.Width / 2f);
|
||||
float moveY = rect.Y + (rect.Height / 2f);
|
||||
int rotate = MathHelpers.Random(Math.Min(RandomRotateMin, RandomRotateMax), Math.Max(RandomRotateMin, RandomRotateMax));
|
||||
|
||||
g.TranslateTransform(moveX, moveY);
|
||||
g.RotateTransform(MathHelpers.Random(Math.Min(RandomRotateMin, RandomRotateMax), Math.Max(RandomRotateMin, RandomRotateMax)));
|
||||
g.RotateTransform(rotate);
|
||||
g.TranslateTransform(-moveX, -moveY);
|
||||
}
|
||||
|
||||
g.DrawImage(img2, rect);
|
||||
if (RandomOpacity)
|
||||
{
|
||||
float opacity = MathHelpers.Random(Math.Min(RandomOpacityMin, RandomOpacityMax), Math.Max(RandomOpacityMin, RandomOpacityMax)).Clamp(0, 100) / 100f;
|
||||
|
||||
ColorMatrix matrix = new ColorMatrix();
|
||||
matrix.Matrix33 = opacity;
|
||||
using (ImageAttributes attributes = new ImageAttributes())
|
||||
{
|
||||
attributes.SetColorMatrix(matrix);
|
||||
g.DrawImage(img2, rect, 0, 0, img2.Width, img2.Height, GraphicsUnit.Pixel, attributes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g.DrawImage(img2, rect);
|
||||
}
|
||||
|
||||
if (RandomRotate)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue