当前位置: 首页>>代码示例>>C#>>正文


C# Runtime.SetResource方法代码示例

本文整理汇总了C#中Runtime.SetResource方法的典型用法代码示例。如果您正苦于以下问题:C# Runtime.SetResource方法的具体用法?C# Runtime.SetResource怎么用?C# Runtime.SetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Runtime的用法示例。


在下文中一共展示了Runtime.SetResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Init


//.........这里部分代码省略.........

            syscalls.maDrawImage = delegate(int image, int left, int top)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();
                Rect srcRect = new Rect(0, 0, src.PixelWidth, src.PixelHeight);
                Rect dstRect = new Rect(left, top, src.PixelWidth, src.PixelHeight);
                mCurrentDrawTarget.Blit(dstRect, src, srcRect, WriteableBitmapExtensions.BlendMode.Alpha);
            };

            syscalls.maDrawImageRegion = delegate(int image, int srcRectPtr, int dstPointPtr, int transformMode)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_IMAGE, image);
                WriteableBitmap src = (WriteableBitmap)res.GetInternalObject();

                Memory dataMemory = core.GetDataMemory();
                int srcRectX = dataMemory.ReadInt32(srcRectPtr + 0);
                int srcRectY = dataMemory.ReadInt32(srcRectPtr + 4);
                int srcRectW = dataMemory.ReadInt32(srcRectPtr + 8);
                int srcRectH = dataMemory.ReadInt32(srcRectPtr + 12);
                int dstPointX = dataMemory.ReadInt32(dstPointPtr + 0);
                int dstPointY = dataMemory.ReadInt32(dstPointPtr + 4);

                Rect srcRect = new Rect(srcRectX, srcRectY, srcRectW, srcRectH);
                Rect dstRect = new Rect(dstPointX, dstPointY, srcRectW, srcRectH);
                // mCurrentDrawTarget.Blit(dstRect, src, srcRect, WriteableBitmapExtensions.BlendMode.Alpha);

                DrawImageRegion(mCurrentDrawTarget, dstPointX, dstPointY, srcRect, src, transformMode);
            };

            syscalls.maCreateDrawableImage = delegate(int placeholder, int width, int height)
            {
                Resource res = runtime.GetResource(MoSync.Constants.RT_PLACEHOLDER, placeholder);
                res.SetResourceType(MoSync.Constants.RT_IMAGE);
                WriteableBitmap bitmap = null;

                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    bitmap = new WriteableBitmap(width, height);
                });

                if (bitmap == null) return MoSync.Constants.RES_OUT_OF_MEMORY;
                res.SetInternalObject(bitmap);
                return MoSync.Constants.RES_OK;
            };

            syscalls.maCreateImageRaw = delegate(int _placeholder, int _src, int _size, int _alpha)
            {
                int width = MoSync.Util.ExtentX(_size);
                int height = MoSync.Util.ExtentY(_size);

                WriteableBitmap bitmap = null;
                MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        bitmap = new WriteableBitmap(width, height);
                    });

                //core.GetDataMemory().ReadIntegers(bitmap.Pixels, _src, width * height);
                bitmap.FromByteArray(core.GetDataMemory().GetData(), _src, width * height * 4);
                if (_alpha == 0)
                {
                    int[] pixels = bitmap.Pixels;
                    int numPixels = width * height;
                    for (int i = 0; i < numPixels; i++)
                    {
                        pixels[i] = (int)((uint)pixels[i] | 0xff000000);
开发者ID:asamuelsson,项目名称:MoSync,代码行数:67,代码来源:MoSyncGraphicsModule.cs

示例2: Init

        public void Init(Syscalls syscalls, Core core, Runtime runtime)
        {
            runtime.RegisterCleaner(delegate()
            {
                CleanDictionary(mFileHandles);
                CleanDictionary(mStoreHandles);
                mFileListHandles.Clear();
            });

            // todo: store "stores" in a separate location from the filesystem,
            // to avoid clashes.
            syscalls.maOpenStore = delegate(int _name, int _flags)
            {
                String name = core.GetDataMemory().ReadStringAtAddress(_name);
                name = ConvertPath(name);
                File file = new File(name, FileAccess.ReadWrite);
                if (file.IsDirectory)
                {
                    throw new Exception("Invalid store name");
                }
                if (file.Exists)
                    file.TryOpen();
                else if ((_flags & MoSync.Constants.MAS_CREATE_IF_NECESSARY) != 0)
                {
                    file.Create();
                }
                else
                    return MoSync.Constants.STERR_NONEXISTENT;
                if (file.FileStream == null)
                    return MoSync.Constants.STERR_GENERIC;
                mStoreHandles.Add(mNextStoreHandle, file);
                return mNextStoreHandle++;
            };

            syscalls.maWriteStore = delegate(int _store, int _data)
            {
                File file = mStoreHandles[_store];
                IsolatedStorageFileStream fileStream = file.FileStream;
                fileStream.SetLength(0);
                Resource dataRes = runtime.GetResource(MoSync.Constants.RT_BINARY, _data);
                Stream data = (Stream)dataRes.GetInternalObject();
                data.Seek(0, SeekOrigin.Begin);
                //fileStream.Write(data.GetData(), 0, data.GetData().Length);
                data.CopyTo(fileStream);
                return 1;
            };

            syscalls.maReadStore = delegate(int _store, int _placeholder)
            {
                File file = mStoreHandles[_store];
                IsolatedStorageFileStream fileStream = file.FileStream;
                //Memory mem = new Memory((int)fileStream.Length);
                MemoryStream mem = new MemoryStream((int)fileStream.Length);
                fileStream.Seek(0, SeekOrigin.Begin);
                fileStream.Read(mem.GetBuffer(), 0, (int)fileStream.Length);
                runtime.SetResource(_placeholder, new Resource(mem, MoSync.Constants.RT_BINARY));
                return MoSync.Constants.RES_OK;
            };

            syscalls.maCloseStore = delegate(int _store, int _delete)
            {
                File file = mStoreHandles[_store];
                file.Close();
                if (_delete != 0)
                    file.Delete();
                mStoreHandles.Remove(_store);
            };
        }
开发者ID:patrickbroman,项目名称:MoSync,代码行数:68,代码来源:MoSyncFileModule.cs


注:本文中的Runtime.SetResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。