Fixed transparency for clipboard upload

This commit is contained in:
oxysoft 2015-12-21 19:57:22 -05:00
parent 1539d9148d
commit df5d50b3d2

View file

@ -29,8 +29,10 @@ You should have received a copy of the GNU General Public License
using ShareX.UploadersLib;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Web;
using System.Windows.Forms;
@ -173,7 +175,35 @@ public static void ClipboardUpload(TaskSettings taskSettings = null)
if (Clipboard.ContainsImage())
{
Image img = Clipboard.GetImage();
IDataObject data = Clipboard.GetDataObject();
byte[] stream = ((MemoryStream)Clipboard.GetData(DataFormats.Dib)).ToArray();
int w = BitConverter.ToInt32(stream, 4);
int h = BitConverter.ToInt32(stream, 8);
short bpp = BitConverter.ToInt16(stream, 14);
Image img = null;
if (bpp == 32)
{
var gch = GCHandle.Alloc(stream, GCHandleType.Pinned);
Bitmap bmp = null;
try
{
var ptr = new IntPtr((long)gch.AddrOfPinnedObject() + 40);
bmp = new Bitmap(w, h, w * 4, PixelFormat.Format32bppArgb, ptr);
img = (Image) bmp.Clone();
img.RotateFlip(RotateFlipType.Rotate180FlipX);
} finally
{
gch.Free();
if (bmp != null) bmp.Dispose();
}
} else
{
img = Clipboard.GetImage();
}
if (img != null)
{