本文整理汇总了C#中Pin.AddrOfPinnedObject方法的典型用法代码示例。如果您正苦于以下问题:C# Pin.AddrOfPinnedObject方法的具体用法?C# Pin.AddrOfPinnedObject怎么用?C# Pin.AddrOfPinnedObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pin
的用法示例。
在下文中一共展示了Pin.AddrOfPinnedObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeText
public ITextInfo AnalyzeText(
Graphics graphics,
Font font,
int fontHeight,
string line)
{
int index;
if ((index = line.IndexOfAny(new char[] { '\r', '\n' })) >= 0)
{
Debug.Assert(false);
throw new ArgumentException();
}
if (offscreenStrip == null)
{
using (GraphicsHDC hdc = new GraphicsHDC(graphics))
{
offscreenStrip = new GDIBitmap(visibleWidth, fontHeight, hdc);
}
Debug.Assert(hdcOffscreenStrip == null);
hdcOffscreenStrip = GDIDC.Create(offscreenStrip);
}
using (Pin<string> pinLine = new Pin<string>(line))
{
return TextItems.AnalyzeText(
this,
hdcOffscreenStrip,
pinLine.AddrOfPinnedObject(),
new FontRunInfo[] { new FontRunInfo(line.Length, font, fontHeight) });
}
}
示例2: GuessEncoding
private static EncodingInfo GuessEncoding(string path)
{
using (Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
Encoding encoding;
int bomLength = 0;
byte[] bom = new byte[3];
stream.Read(bom, 0, 3);
if ((bom[0] == 0xFF) && (bom[1] == 0xFE))
{
encoding = Encoding_UTF16;
bomLength = 2;
}
else if ((bom[0] == 0xFE) && (bom[1] == 0xFF))
{
encoding = Encoding_UTF16BigEndian;
bomLength = 2;
}
else if ((bom[0] == 0xEF) && (bom[1] == 0xBB) && (bom[2] == 0xBF))
{
encoding = Encoding_UTF8;
bomLength = 3;
}
else
{
stream.Seek(0, SeekOrigin.Begin);
using (Pin<byte[]> pinBuffer = new Pin<byte[]>(new byte[4096]))
{
int c = stream.Read(pinBuffer.Ref, 0, pinBuffer.Ref.Length);
IsTextUnicodeFlags flags = unchecked((IsTextUnicodeFlags)0xffffffff);
bool unicode = IsTextUnicode(pinBuffer.AddrOfPinnedObject(), c, ref flags);
if (unicode)
{
if ((flags & IsTextUnicodeFlags.IS_TEXT_UNICODE_UNICODE_MASK) != 0)
{
encoding = Encoding_UTF16;
}
else
{
encoding = Encoding_UTF16BigEndian;
}
}
else
{
encoding = Encoding_ANSI;
}
}
}
return new EncodingInfo(encoding, bomLength);
}
}