本文整理汇总了C#中Cocos2D.CCTexture2D.InitWithStream方法的典型用法代码示例。如果您正苦于以下问题:C# CCTexture2D.InitWithStream方法的具体用法?C# CCTexture2D.InitWithStream怎么用?C# CCTexture2D.InitWithStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cocos2D.CCTexture2D
的用法示例。
在下文中一共展示了CCTexture2D.InitWithStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNativeLabel
internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
CCVerticalTextAlignment vAlignment, string fontName,
float fontSize, CCColor4B textColor)
{
if (string.IsNullOrEmpty(text))
{
return new CCTexture2D();
}
var font = CreateFont (fontName, fontSize);
if (dimensions.Equals(CCSize.Zero))
{
CreateBitmap(1, 1);
var ms = _graphics.MeasureString(text, font);
dimensions.Width = ms.Width;
dimensions.Height = ms.Height;
}
CreateBitmap((int)dimensions.Width, (int)dimensions.Height);
var stringFormat = new StringFormat();
switch (hAlignment)
{
case CCTextAlignment.Left:
stringFormat.Alignment = StringAlignment.Near;
break;
case CCTextAlignment.Center:
stringFormat.Alignment = StringAlignment.Center;
break;
case CCTextAlignment.Right:
stringFormat.Alignment = StringAlignment.Far;
break;
}
switch (vAlignment)
{
case CCVerticalTextAlignment.Top:
stringFormat.LineAlignment = StringAlignment.Near;
break;
case CCVerticalTextAlignment.Center:
stringFormat.LineAlignment = StringAlignment.Center;
break;
case CCVerticalTextAlignment.Bottom:
stringFormat.LineAlignment = StringAlignment.Far;
break;
}
_graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
_graphics.Flush();
var texture = new CCTexture2D();
texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444);
return texture;
}
示例2: saveImage
public void saveImage(object pSender)
{
using (var stream = new MemoryStream())
{
m_pTarget.SaveToStream(stream, CCImageFormat.PNG);
//m_pTarget.saveToFile(jpg, ImageFormat.JPG);
stream.Position = 0;
var tex = new CCTexture2D();
tex.InitWithStream(stream);
CCSprite sprite = new CCSprite(tex);
sprite.Scale = 0.3f;
AddChild(sprite);
sprite.Position = new CCPoint(40, 40);
sprite.Rotation = counter * 3;
}
counter++;
}