2013-04-08 2 views
15

मैं इस यूआईसीओलर मूल्य से यूआईएममेज बनाने की कोशिश कर रहा हूं। UIImage बनाया जा रहा है, लेकिन अल्फा मान खो गया है। छवि अपारदर्शी बनी हुई है।यूआईसीओएल से UICmage अल्फा

@implementation GetImage 

+ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size 
{ 
    UIImage *img = nil; 

    CGRect rect = CGRectMake(0, 0, size.width, size.height); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetFillColorWithColor(context, 
           color.CGColor); 
    CGContextFillRect(context, rect); 

    img = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

    return img; 
} 

@end 

कौन सा मैं बहुत की तरह फोन:

-(void) setButtonColours{ 

    UIImage *img1, *img2; 

    UIColor *red = [UIColor colorWithRed:205.0/255.0 green:68.0/255.0 blue:51.0/255.0 alpha:1.0], 
    *blue = [UIColor colorWithRed:71.0/255.0 green:97.0/255.0 blue:151.0/255.0 alpha:1.0]; 

    img1 = [GetImage imageWithColor: blue andSize: self.dummyButton.frame.size]; 

    img2 = [GetImage imageWithColor: red andSize: self.dummyButton.frame.size]; 

    [self.dummyButton setBackgroundImage: img1 forState:UIControlStateNormal]; 
    [self.dummyButton setBackgroundImage: img2 forState:UIControlStateSelected]; 

} 

किसी भी विचार है कि मैं क्या याद कर रहा हूँ मैं निम्नलिखित कोड का उपयोग कर रहा हूँ?

उत्तर

15

आप एक अपारदर्शी छवि संदर्भ बना रहे हैं।

UIGraphicsBeginImageContext(rect.size); 

साथ:

UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); 
+0

यह काम किया

इस लाइन की जगह! धन्यवाद! :) –

2

घटना किसी में इस सवाल पाता है और वे Monotouch कार्यान्वयन के लिए देख रहे हैं:

public class ColorRGBA 
     { 
      public float Red=0; 
      public float Green=0; 
      public float Blue=0; 
      public float Alpha=0; 

      public ColorRGBA (float red, float green, float blue, float alpha) 
      { 
       Red = red; 
       Green = green; 
       Blue = blue; 
       Alpha = alpha; 
      } 
     } 

//then from within a custom mt.d element 

private ColorRGBA color; 

    public override UITableViewCell GetCell (UITableView tv) 
       { 
        //create square with color 
        var imageSize = new SizeF(30, 30); 
        var imageSizeRectF = new RectangleF (0, 0, 30, 30); 
        UIGraphics.BeginImageContextWithOptions (imageSize, false, 0); 
        var context = UIGraphics.GetCurrentContext(); 
        context.SetFillColor (color.Red, color.Green, color.Blue, color.Alpha); 
        context.FillRect (imageSizeRectF); 
        var image = UIGraphics.GetImageFromCurrentImageContext(); 
        UIGraphics.EndImageContext(); 

        var cell = base.GetCell(tv); 
        cell.Accessory = UITableViewCellAccessory.DisclosureIndicator; 
        cell.ImageView.Image = image; 

        return cell; 
       } 
संबंधित मुद्दे