本文整理汇总了C#中System.Image.Load方法的典型用法代码示例。如果您正苦于以下问题:C# Image.Load方法的具体用法?C# Image.Load怎么用?C# Image.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Image
的用法示例。
在下文中一共展示了Image.Load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CaptureAndAnalyze
async Task<string> CaptureAndAnalyze(bool readText = false)
{
var imgFormat = ImageEncodingProperties.CreateJpeg();
//NOTE: this is how you can save a frame to the CameraRoll folder:
//var file = await KnownFolders.CameraRoll.CreateFileAsync($"MCS_Photo{DateTime.Now:HH-mm-ss}.jpg", CreationCollisionOption.GenerateUniqueName);
//await mediaCapture.CapturePhotoToStorageFileAsync(imgFormat, file);
//var stream = await file.OpenStreamForReadAsync();
// Capture a frame and put it to MemoryStream
var memoryStream = new MemoryStream();
using (var ras = new InMemoryRandomAccessStream())
{
await mediaCapture.CapturePhotoToStreamAsync(imgFormat, ras);
ras.Seek(0);
using (var stream = ras.AsStreamForRead())
stream.CopyTo(memoryStream);
}
var imageBytes = memoryStream.ToArray();
memoryStream.Position = 0;
if (withPreview)
{
InvokeOnMain(() =>
{
var image = new Image();
image.Load(new Urho.MemoryBuffer(imageBytes));
Node child = Scene.CreateChild();
child.Position = LeftCamera.Node.WorldPosition + LeftCamera.Node.WorldDirection * 2f;
child.LookAt(LeftCamera.Node.WorldPosition, Vector3.Up, TransformSpace.World);
child.Scale = new Vector3(1f, image.Height / (float)image.Width, 0.1f) / 10;
var texture = new Texture2D();
texture.SetData(image, true);
var material = new Material();
material.SetTechnique(0, CoreAssets.Techniques.Diff, 0, 0);
material.SetTexture(TextureUnit.Diffuse, texture);
var box = child.CreateComponent<Box>();
box.SetMaterial(material);
child.RunActions(new EaseBounceOut(new ScaleBy(1f, 5)));
});
}
try
{
var client = new VisionServiceClient(VisionApiKey);
if (readText)
{
var ocrResult = await client.RecognizeTextAsync(memoryStream, detectOrientation: false);
var words = ocrResult.Regions.SelectMany(region => region.Lines).SelectMany(line => line.Words).Select(word => word.Text);
return "it says: " + string.Join(" ", words);
}
else
{
// just describe the picture, you can also use cleint.AnalyzeImageAsync method to get more info
var result = await client.DescribeAsync(memoryStream);
return result?.Description?.Captions?.FirstOrDefault()?.Text;
}
}
catch (ClientException exc)
{
return exc?.Error?.Message ?? "Failed";
}
catch (Exception exc)
{
return "Failed";
}
}
示例2: CreateTerrain
private void CreateTerrain()
{
mTMgr = new MET.TerrainManager(OgreEngine.mMgr, "MET");
mTMgr.SetLodErrorMargin(2, OgreEngine.mWin.Height);
mTMgr.SetUseLodMorphing(true, 0.2f, "morphFactor");
mTInfo = new MET.TerrainInfo();
Mogre.Image image = new Mogre.Image();
image.Load("heightmap.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
MET.TerrainInfo.LoadHeightmapFromImage(mTInfo, image);
//mTInfo.Extents = new Mogre.AxisAlignedBox(0, 0, 0, land.SizeX + stepWidth, land.SizeZ, land.SizeY + stepHeight);
mTInfo.Extents = new Mogre.AxisAlignedBox(Vector3.ZERO, Size);
//lightmap
Mogre.Image lmImage = new Mogre.Image();
MET.TerrainInfo.CreateTerraingLightmap(mTInfo, lmImage, Constants.Land.LightmapSize, Constants.Land.LightmapSize, new Vector3(-1, -1, -1), new ColourValue(1, 1, 1), new ColourValue(0.2f, 0.2f, 0.2f), true);
//lmImage.Save("lightmapa" + land.Id + ".png");
TexturePtr lightmapTex = TextureManager.Singleton.CreateManual(
"ETLightmap",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
Mogre.TextureType.TEX_TYPE_2D,
Constants.Land.LightmapSize,
Constants.Land.LightmapSize,
1,
Mogre.PixelFormat.PF_BYTE_RGB);
TexturePtr tex = TextureManager.Singleton.GetByName("ETLightmap");
tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0));
mTMgr.CreateTerrain(mTInfo);
mTInfo.Dispose();
mTInfo = mTMgr.TerrainInfo;
image = new Image();
image.Load("textureMap0.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
TextureSize = image.Width;
mSMgr = new MET.SplattingManager("ETSplatting", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, image.Width, image.Width, 3);
mSMgr.NumTextures = 6;
mSMgr.LoadMapFromImage(0, image);
image = new Image();
image.Load("textureMap1.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
mSMgr.LoadMapFromImage(1, image);
mTMgr.Material = MaterialManager.Singleton.GetByName("ETTerrainMaterial");
// lightmapa
Pass pass = mTMgr.Material.GetTechnique(0).CreatePass();
pass.LightingEnabled = false;
pass.SetSceneBlending(SceneBlendType.SBT_MODULATE);
pass.SetVertexProgram("ET/Programs/VSLodMorph2");
pass.SetFragmentProgram("ET/Programs/PSLighting");
pass.CreateTextureUnitState("ETLightmap");
pass = mTMgr.Material.GetTechnique(1).CreatePass();
pass.LightingEnabled = false;
pass.SetSceneBlending(SceneBlendType.SBT_MODULATE);
pass.SetVertexProgram("ET/Programs/VSLodMorph2");
pass.SetFragmentProgram("ET/Programs/PSLighting");
pass.CreateTextureUnitState("ETLightmap");
//base texture for non shader graphics
lmImage = new Mogre.Image();
//TODO: replace by real bic texture
lmImage.Load("baseTexture.jpg", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
//lmImage.Save("lightmapa" + land.Id + ".png");
lightmapTex = TextureManager.Singleton.CreateManual(
"ETBasemap",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
Mogre.TextureType.TEX_TYPE_2D,
Constants.Land.LightmapSize,
Constants.Land.LightmapSize,
1,
Mogre.PixelFormat.PF_BYTE_RGB);
tex = TextureManager.Singleton.GetByName("ETBasemap");
tex.GetBuffer(0, 0).BlitFromMemory(lmImage.GetPixelBox(0, 0));
Technique tech = mTMgr.Material.CreateTechnique();
pass = tech.CreatePass();
pass.CreateTextureUnitState("ETBasemap");
}
示例3: GetTerrainImage
protected static void GetTerrainImage(bool flipX, bool flipY, Image img)
{
img.Load("terrain.png", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
if (flipX)
img.FlipAroundX();
if (flipY)
img.FlipAroundY();
}