Skip to content

Commit

Permalink
Use Marshal.Copy on the buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Susko3 committed Apr 18, 2024
1 parent c80ec2d commit a6f3944
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions osu.Framework/Platform/Windows/WindowsClipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,11 @@ public override bool SetImage(Image image)
{
var encoder = image.Configuration.ImageFormatsManager.GetEncoder(BmpFormat.Instance);
image.Save(stream, encoder);
var span = new ReadOnlySpan<byte>(stream.GetBuffer(), bitmap_file_header_length, (int)stream.Length - bitmap_file_header_length);
IntPtr unmanagedPointer = Marshal.AllocHGlobal(span.Length);

unsafe
{
fixed (void* source = span)
Buffer.MemoryCopy(source, unmanagedPointer.ToPointer(), span.Length, span.Length);
}

return setClipboard(unmanagedPointer, span.Length, cf_dib);
int bitmapDataLength = (int)stream.Length - bitmap_file_header_length;
IntPtr unmanagedPointer = Marshal.AllocHGlobal(bitmapDataLength);
Marshal.Copy(stream.GetBuffer(), bitmap_file_header_length, unmanagedPointer, bitmapDataLength);
return setClipboard(unmanagedPointer, bitmapDataLength, cf_dib);
}
}

Expand Down

0 comments on commit a6f3944

Please sign in to comment.