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


C# NSMutableDictionary.Release方法代码示例

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


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

示例1: IISaveImage

        // Save the given image to a file at the given url.
        // Returns true if successful, false otherwise.
        public static bool IISaveImage(ImageView view, NSURL url, uint width, uint height)
        {
            ImageInfo image = view.Image;
            bool result = false;

            // If there is no image, no destination, or the width/height is 0, then fail early.
            if ((url != null) && (width != 0) && (height != 0))
            {
                // Try to create a jpeg image destination at the url given to us
                IntPtr imageDest = CGImageDestination.CreateWithURL(url, UTType.kUTTypeJPEG, 1, null);
                if (imageDest != IntPtr.Zero)
                {
                    // And if we can, then we can start building our final image.
                    // We begin by creating a CGBitmapContext to host our desintation image.

                    // Allocate enough space to hold our pixels
                    IntPtr imageData = Marshal.AllocHGlobal((int) (Marshal.SizeOf(typeof (UInt32))*width*height));

                    // Create the bitmap context
                    IntPtr bitmapContext = CGBitmapContext.Create(
                        imageData, // image data we just allocated...
                        width, // width
                        height, // height
                        8, // 8 bits per component
                        sizeof (UInt32)*width, // bytes per pixel times number of pixels wide
                        CGImage.GetColorSpace(image.fImageRef), // use the same colorspace as the original image
                        (CGBitmapInfo) CGImageAlphaInfo.kCGImageAlphaPremultipliedFirst); // use premultiplied alpha

                    // Check that all that went well
                    if (bitmapContext != IntPtr.Zero)
                    {
                        // Now, we draw the image to the bitmap context
                        IIDrawImageTransformed(ref image, bitmapContext, CGRect.CGRectMake(0.0f, 0.0f, width, height));

                        // We have now gotten our image data to the bitmap context, and correspondingly
                        // into imageData. If we wanted to, we could look at any of the pixels of the image
                        // and manipulate them in any way that we desire, but for this case, we're just
                        // going to ask ImageIO to write this out to disk.

                        // Obtain a CGImageRef from the bitmap context for ImageIO
                        IntPtr imageIOImage = CGBitmapContext.CreateImage(bitmapContext);

                        // Check if we have additional properties from the original image
                        if (image.fProperties != null)
                        {
                            // If we do, then we want to inspect the orientation property.
                            // If it exists and is not the default orientation, then we
                            // want to replace that orientation in the destination file
                            int orientation = IIGetImageOrientation(ref image);
                            if (orientation != 1)
                            {
                                // If the orientation in the original image was not the default,
                                // then we need to replace that key in a duplicate of that dictionary
                                // and then pass that dictionary to ImageIO when adding the image.
                                NSMutableDictionary prop = new NSMutableDictionary(image.fProperties);
                                orientation = 1;
                                prop.SetValueForKey(NSNumber.NumberWithInt(orientation), CGImageProperties.kCGImagePropertyOrientation);

                                // And add the image with the new properties
                                CGImageDestination.AddImage(imageDest, imageIOImage, prop);

                                // Clean up after ourselves
                                prop.Release();
                            }
                            else
                            {
                                // Otherwise, the image was already in the default orientation and we can just save
                                // it with the original properties.
                                CGImageDestination.AddImage(imageDest, imageIOImage, image.fProperties);
                            }
                        }
                        else
                        {
                            // If we don't, then just add the image without properties
                            CGImageDestination.AddImage(imageDest, imageIOImage, null);
                        }

                        // Release the image and the context, since we are done with both.
                        CGImage.Release(imageIOImage);
                        CGContext.Release(bitmapContext);
                    }

                    // Deallocate the image data
                    Marshal.FreeHGlobal(imageData);

                    // Finalize the image destination
                    result = CGImageDestination.Finalize(imageDest);
                    CFType.CFRelease(imageDest);
                }
            }

            return result;
        }
开发者ID:Monobjc,项目名称:monobjc-samples,代码行数:95,代码来源:ImageUtils.cs


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