English 中文(简体)
3. 位于多瑙托库的透明巴布亚新几内亚
原标题:Transparent PNGs in Monotouch for iOS

我有一个问题,我早就在提出解决办法之前寻求几个月。

问题在于全国过渡政府在Monotouch的透明档案:

我正试图将transuz PNG装在context上,以便读和书写色体。 我正在使用以下守则,该守则与不透明的全国过渡政府完全合作。 (我还在试图取得正确结果时,包括其他一些尝试)

有了透明的PNGS,问题似乎在于,我不得不在预选的甲型六氯环己烷(CGImage AlphaInfo.Premultiplied Last)的背景下装上图像。 由此可见,RGB的价值观在装满时将从其原有价值中加以改变。

I tried to create a context with CGImageAlphaInfo.Last (which is theoretically correct), but I get an exception (not acceptable parameter combination).

我以核心为着想,但这将限制我们的用户到5岁或以后,我决定这是不可接受的。

我迫切需要找到一种途径,在透明的国家政府中获取和配置餐具,因为我正在开发一个跨平台软件(iPhone、iPad、Mac利用MonoMac和Windows),需要处理透明的政府。

Any help will be greatly appreciated. Thanks!

using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
using MonoTouch.CoreGraphics;
using System.Runtime.InteropServices;
using MonoTouch.CoreImage;

namespace TestPNG
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register ("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        // class-level declarations
        UIWindow window;
        TestPNGViewController viewController;

        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.Bounds);

            viewController = new TestPNGViewController ();
            window.RootViewController = viewController;
            window.MakeKeyAndVisible ();

            UIImage _CarrierImage = UIImage.FromFile ("Blue50.png");

            int width = _CarrierImage.CGImage.Width;
            int height = _CarrierImage.CGImage.Height;
            CGImage cg = _CarrierImage.CGImage;
            Console.WriteLine ("width: " + width.ToString ("000") + ", height: " + height.ToString ("000"));
            Console.WriteLine ("BitsPerComponent: " + cg.BitsPerComponent.ToString ());
            Console.WriteLine ("BytesPerRow: " + cg.BytesPerRow.ToString ());
            Console.WriteLine ("BitsPerPixel: " + cg.BitsPerPixel.ToString ());
            Console.WriteLine ("ColorSpace: " + cg.ColorSpace.ToString ());
            Console.WriteLine ("For image Blue0.png should have values: R:0, G:0, B:255, A: 0");
            Console.WriteLine ("For image Blue50.png should have values: R:0, G:0, B:255, A: 128");
            Console.WriteLine ("For image Blue100.png should have values: R:0, G:0, B:255, A: 255");

            // METHOD 1
//          CGDataProvider p = CGDataProvider.FromFile("Blue50.png");
//          CGImage cgimg = CGImage.FromPNG(p,null,false,CGColorRenderingIntent.Default);
//          UIImage _CarrierImage = new UIImage(cgimg);


            // METHOD 2
//          NSData dt = _CarrierImage.AsPNG();
//          IntPtr bitmapData = dt.Bytes;
//          
//          Console.WriteLine("Length: " + dt.Length.ToString());
//          for (int i=0; i < dt.Length; i++)
//          {
//              Console.WriteLine("i: " + i.ToString("00") + ", byte: " + dt[i].ToString());
//          }
//          


            // METHOD 3
//          UIGraphics.BeginImageContext (_CarrierImage.Size);
//          CGContext ctx = UIGraphics.GetCurrentContext ();
//          ctx.DrawImage (new RectangleF (0, 0, _CarrierImage.Size.Width, _CarrierImage.Size.Height), _CarrierImage.CGImage);
//          IntPtr dt = ctx.Handle;
//          for (int i=0; i < 100; i++)
//          {
//              Console.WriteLine("i: " + i.ToString("00") + ", byte: " + GetByte(i, dt).ToString ());
//          }
//          UIGraphics.EndImageContext();



            // METHOD 4
            int bitmapBytesPerRow = width * 4;
            IntPtr bitmapData = Marshal.AllocHGlobal (width * 4 * height);

            CGBitmapContext ctxt = new CGBitmapContext (bitmapData, width, height, cg.BitsPerComponent, bitmapBytesPerRow, cg.ColorSpace, CGImageAlphaInfo.PremultipliedLast);

            RectangleF rect = new RectangleF (0.0f, 0.0f, width, height);
            ctxt.DrawImage (rect, _CarrierImage.CGImage); 
            IntPtr dt = ctxt.Data;

            Console.WriteLine ("R: " + GetByte (0, dt).ToString ());
            Console.WriteLine ("G: " + GetByte (1, dt).ToString ());
            Console.WriteLine ("B: " + GetByte (2, dt).ToString ());
            Console.WriteLine ("A: " + GetByte (3, dt).ToString ());

            return true;
        }

        unsafe byte GetByte (int offset, IntPtr buffer)
        {
            byte* bufferAsBytes = (byte*)buffer;
            return bufferAsBytes [offset];
        }

    }
}
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签