示例#1
0
        public override void LoadTexture(Texture t)
        {
            string path = NSBundle.MainBundle.PathForResource(Path.GetFileNameWithoutExtension(t.Name), "png");

            CGDataProvider dataProvider = null;
            CGImage        image        = null;

            try
            {
                dataProvider = CGDataProvider.FromFile(path);
                image        = CGImage.FromPNG(dataProvider, null, false, CGColorRenderingIntent.Default);

                LoadTextureFromImage(t, image);
            }
            catch (Exception)
            {
                t.Failed = true;
                return;
            }
            finally
            {
                if (dataProvider != null)
                {
                    dataProvider.Dispose();
                }
                if (image != null)
                {
                    image.Dispose();
                }
            }
        }
示例#2
0
        public void Dispose()
        {
            if (cgdata != null)
            {
                cgdata.Dispose();
                cgdata = null;
            }

            if (cgimage != null)
            {
                cgimage.Dispose();
                cgimage = null;
            }

            if (image != null)
            {
                image.Dispose();
                image = null;
            }

            if (colorSpace != null)
            {
                colorSpace.Dispose();
                colorSpace = null;
            }

            //if (bits != IntPtr.Zero)
            //	Marshal.FreeHGlobal (bits);

            bits = null;
        }
示例#3
0
 private void FreeBitmap()
 {
     dataProvider?.Dispose();
     dataProvider = null;
     bitmapData?.Dispose();
     bitmapData = null;
 }
示例#4
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (NativeCGImage != null)
         {
             NativeCGImage.Dispose();
             NativeCGImage = null;
         }
         if (dataProvider != null)
         {
             dataProvider.Dispose();
             dataProvider = null;
         }
         if (imageSource != null)
         {
             imageSource.Dispose();
             imageSource = null;
         }
     }
     base.Dispose(disposing);
 }
示例#5
0
        internal new void RotateFlip(RotateFlipType rotateFlipType)
        {
            CGAffineTransform rotateFlip = CGAffineTransform.MakeIdentity();

            int width, height;

            width  = (int)NativeCGImage.Width;
            height = (int)NativeCGImage.Height;

            switch (rotateFlipType)
            {
            //			case RotateFlipType.RotateNoneFlipNone:
            //			//case RotateFlipType.Rotate180FlipXY:
            //				rotateFlip = GeomUtilities.CreateRotateFlipTransform (b.Width, b.Height, 0, false, false);
            //				break;
            case RotateFlipType.Rotate90FlipNone:
                //case RotateFlipType.Rotate270FlipXY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 90, false, false);
                break;

            case RotateFlipType.Rotate180FlipNone:
                //case RotateFlipType.RotateNoneFlipXY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 0, true, true);
                break;

            case RotateFlipType.Rotate270FlipNone:
                //case RotateFlipType.Rotate90FlipXY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 270, false, false);
                break;

            case RotateFlipType.RotateNoneFlipX:
                //case RotateFlipType.Rotate180FlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 0, true, false);
                break;

            case RotateFlipType.Rotate90FlipX:
                //case RotateFlipType.Rotate270FlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 90, true, false);
                break;

            case RotateFlipType.Rotate180FlipX:
                //case RotateFlipType.RotateNoneFlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 0, false, true);
                break;

            case RotateFlipType.Rotate270FlipX:
                //case RotateFlipType.Rotate90FlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform(ref width, ref height, 270, true, false);
                break;
            }

            var bytesPerRow      = (width * (int)NativeCGImage.BitsPerPixel + 7) / 8;
            var newBitmapBlock   = Marshal.AllocHGlobal(height * bytesPerRow);
            var newBitmapContext = new CGBitmapContext(newBitmapBlock, width, height, NativeCGImage.BitsPerComponent, bytesPerRow, NativeCGImage.ColorSpace, NativeCGImage.AlphaInfo);

            newBitmapContext.ConcatCTM(rotateFlip);
            newBitmapContext.DrawImage(new CGRect(0, 0, NativeCGImage.Width, NativeCGImage.Height), NativeCGImage);
            newBitmapContext.Flush();

            // If the width or height is not the seme we need to switch the dpiHeight and dpiWidth
            // We should be able to get around this with set resolution later.
            if (NativeCGImage.Width != width || NativeCGImage.Height != height)
            {
                var temp = dpiWidth;
                dpiHeight = dpiWidth;
                dpiWidth  = temp;
            }

            physicalDimension.Width  = (float)width;
            physicalDimension.Height = (float)height;

            physicalSize         = new SizeF(physicalDimension.Width, physicalDimension.Height);
            physicalSize.Width  *= ConversionHelpers.MS_DPI / dpiWidth;
            physicalSize.Height *= ConversionHelpers.MS_DPI / dpiHeight;

            // In windows the RawFormat is changed to MemoryBmp to show that the image has changed.
            rawFormat = ImageFormat.MemoryBmp;

            // Set our transform for this image for the new height
            imageTransform = new CGAffineTransform(1, 0, 0, -1, 0, height);

            // bitmapBlock is owned by dataProvider and freed implicitly
            if (dataProvider != null)
            {
                dataProvider.Dispose();
            }

            if (cachedContext != null)
            {
                cachedContext.Dispose();
            }
            NativeCGImage.Dispose();

            this.bitmapBlock   = newBitmapBlock;
            this.dataProvider  = new CGDataProvider(bitmapBlock, height * bytesPerRow);
            this.NativeCGImage = newBitmapContext.ToImage();
            this.cachedContext = newBitmapContext;
            this.imageSource   = null;

            // update the cached size
            imageSize.Width  = this.Width;
            imageSize.Height = this.Height;
        }