GifRecorder/Encoding/PixelUtil.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace ScreenToGif.Encoding
{
/// <summary>
/// Helper Class that gets and sets image pixels using Marshal calls.
/// </summary>
public class PixelUtil
{
readonly Bitmap _source = null;
IntPtr _iptr = IntPtr.Zero;
BitmapData _bitmapData = null;
public byte[] Pixels { get; set; }
public int Depth { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
/// <summary>
/// Pixel marshalling class, use this to access pixels rapidly.
/// </summary>
/// <param name="source">The Bitmap to work with</param>
public PixelUtil(Bitmap source)
{
//this.source = new Bitmap(source); //Not working
this._source = source;
}
/// <summary>
/// Lock bitmap data
/// </summary>
public void LockBits()
{
try
{
// Get width and height of bitmap
Width = _source.Width;
Height = _source.Height;
// Get total locked pixels count
int pixelCount = Width * Height;
// Create rectangle to lock
var rect = new Rectangle(0, 0, Width, Height);
// get source bitmap pixel format size
Depth = Image.GetPixelFormatSize(_source.PixelFormat);
// Check if bpp (Bits Per Pixel) is 8, 24, or 32
if (Depth != 8 && Depth != 24 && Depth != 32)
{
throw new ArgumentException("Only 8, 24 and 32 bpp images are supported.");
}
后面还有 113 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
