コード例 #1
0
        public StardewBitmap GetBoundedImage(Rectangle rBounds)
        {
            StardewBitmap imPort = new StardewBitmap(rBounds.Width, rBounds.Height);

            imPort.DrawImage(this, new Rectangle(0, 0, rBounds.Width, rBounds.Height), rBounds);

            return(imPort);
        }
コード例 #2
0
        public void DrawImage(StardewBitmap image, Rectangle destination, Rectangle source)
        {
#if TRACE
            StardewLogger.DumpObject("drawimage image", image);
            StardewLogger.DumpObject("drawimage SourceImage", SourceImage);
            StardewLogger.DumpObject("  d rectange", destination);
            StardewLogger.DumpObject("  d skrectange", ConvertxRect(destination));
            StardewLogger.DumpObject("  s rectange", source);
            StardewLogger.DumpObject("  s krectange", ConvertxRect(source));
#endif
            var canvas = new SKCanvas(SourceImage);

            canvas.DrawBitmap(image.SourceImage, ConvertxRect(source), ConvertxRect(destination));
            canvas.Flush();
            canvas.Save();
        }
コード例 #3
0
        internal static void DumpObject(string sName, StardewBitmap oBitmap)
        {
            if (oBitmap == null)
            {
                LogTrace($"StardewBitmap {sName}", "is null");
            }
            else
            {
                LogTrace("StardewBitmap", sName);
                LogTrace("{", "");
                DumpObject("    width", oBitmap.Width);
                DumpObject("    height", oBitmap.Height);

                LogTrace("}", "");
            }
        }
コード例 #4
0
        public static StardewBitmap LoadImageInUIThread(string sImage)
        {
            StardewBitmap sbResult;

            //
            //  check if the request can be handled in the current
            //  thread or needs to be queued to be handled in the UI
            //  thread
            //
            if (Thread.CurrentThread.ManagedThreadId == mainThreadId)
            {
                sbResult = new StardewBitmap(oHelper.Content.Load <Texture2D>(sImage, ContentSource.GameContent));
            }
            else
            {
                //
                //  Queue up spritesheet request
                //
                lock (lImagesToLoad)
                {
                    lImagesToLoad.Add(sImage);
                    //
                    // use SMAPI to add hook to fetch image in the UI thread
                    //
                    oHelper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked_LoadImage;
                }
                //
                //  Wait for request to be handled in another thread
                //
                while (!dcImages.ContainsKey(sImage))
                {
                    Thread.Sleep(200);
                }
                //
                //  Retrieve results
                //
                lock (dcImages)
                {
                    sbResult = dcImages[sImage];
                    dcImages.Remove(sImage);
                }
            }

            return(sbResult);
        }
コード例 #5
0
        public StardewBitmap GetBoundedImage(int iWidth, int iHeight, int iImageIndex)
        {
            int iRow = 0;
            int iCol = 0;

            int iCols = SourceImage.Width / iWidth;

            if (iImageIndex > -1)
            {
                iRow = iImageIndex / iCols;
                iCol = iImageIndex % iCols;
            }

            StardewBitmap imPort = new StardewBitmap(iWidth, iHeight);

            imPort.DrawImage(this, new Rectangle(0, 0, iWidth, iHeight), new Rectangle(iWidth * iCol, iRow * iHeight, iWidth, iHeight));

            return(imPort);
        }
コード例 #6
0
 private SKBitmap StardewToNative(StardewBitmap source)
 {
     return(SKBitmap.Decode(source.SourceStream()));
 }