Пример #1
0
        private static string ConvertChunksToManifest(IList <Chunk> chunks)
        {
            string        currentModule    = "";
            string        currentDirectory = null;
            List <string> lines            = new List <string>();
            int           chunkId          = 1;

            foreach (Chunk chunk in chunks)
            {
                chunk.ID = chunkId++;
                lines.Add("C," + chunk.ID + "," + chunk.Width + "," + chunk.Height);

                UniversalBitmap chunkBmp         = new UniversalBitmap(chunk.Width, chunk.Height);
                UniversalBitmap.DrawingSession g = chunkBmp.CreateNewDrawingSession();
                for (int i = 0; i < chunk.Images.Count; ++i)
                {
                    Image  image = chunk.Images[i];
                    string path  = image.File.OriginalPath;
                    string dir;
                    string filename;
                    int    lastSlash = path.LastIndexOf('/');
                    if (lastSlash == -1)
                    {
                        dir      = "/";
                        filename = path;
                    }
                    else
                    {
                        dir      = path.Substring(0, lastSlash);
                        filename = path.Substring(lastSlash + 1);
                    }

                    int x = chunk.X[i];
                    int y = chunk.Y[i];
                    g.Blit(image.File.Bitmap, x, y);
                    if (image.Module != currentModule)
                    {
                        currentModule = image.Module;
                        lines.Add("M," + currentModule);
                    }
                    if (dir != currentDirectory)
                    {
                        currentDirectory = dir;
                        lines.Add("D," + currentDirectory);
                    }
                    lines.Add("F," + x + "," + y + "," + image.Width + "," + image.Height + "," + filename);
                }
                g.Flush();
                chunk.FinalizedBitmap = chunkBmp;
            }
            return(string.Join('\n', lines));
        }
Пример #2
0
        public static void SendImageToRenderer(object frameObj, int id, object nativeImageData, int x, int y, int width, int height)
        {
            NoriFrame       frame = (NoriFrame)frameObj;
            UniversalBitmap atlas = (UniversalBitmap)nativeImageData;
            UniversalBitmap cropped;

            if (atlas.Width == width && atlas.Height == height)
            {
                cropped = atlas;
            }
            else
            {
                cropped = new UniversalBitmap(width, height);
                UniversalBitmap.DrawingSession session = cropped.GetActiveDrawingSession();
                session.Draw(atlas, 0, 0, x, y, width, height);
                session.Flush();
            }
            byte[] pngBytes    = cropped.GetBytesAsPng();
            string base64Image = UniversalBitmap.ToBase64("data:image/png;base64,", pngBytes);

            frame.SendImageToBrowser(id, width, height, base64Image);
        }