mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-25 05:40:21 -04:00
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using AssetStudio;
|
|
using SixLabors.ImageSharp;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace AssetStudioGUI
|
|
{
|
|
public sealed class DirectBitmap : IDisposable
|
|
{
|
|
public DirectBitmap(Image<Bgra32> image)
|
|
{
|
|
Width = image.Width;
|
|
Height = image.Height;
|
|
var buff = BigArrayPool<byte>.Shared.Rent(Width * Height * 4);
|
|
image.CopyPixelDataTo(buff);
|
|
Bits = buff;
|
|
m_handle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
|
|
m_bitmap = new Bitmap(Width, Height, Stride, PixelFormat.Format32bppArgb, m_handle.AddrOfPinnedObject());
|
|
BigArrayPool<byte>.Shared.Return(buff);
|
|
}
|
|
|
|
private void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
m_bitmap.Dispose();
|
|
m_handle.Free();
|
|
}
|
|
m_bitmap = null;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
}
|
|
|
|
public int Height { get; }
|
|
public int Width { get; }
|
|
public int Stride => Width * 4;
|
|
public byte[] Bits { get; }
|
|
public Bitmap Bitmap => m_bitmap;
|
|
|
|
private Bitmap m_bitmap;
|
|
private readonly GCHandle m_handle;
|
|
}
|
|
}
|