English 中文(简体)
接近安全的UIImage转播?
原标题:Thread safe UIImage resizing?

我将这一备忘录延期,以获得一份更新的复印件:

-(UIImage*)scaleByRatio:(float) scaleRatio
{ 
    CGSize scaledSize = CGSizeMake(self.size.width * scaleRatio, self.size.height * scaleRatio);

    //The output context.   
    UIGraphicsBeginImageContext(scaledSize);
    CGContextRef context = UIGraphicsGetCurrentContext();

//Percent (101%)    
#define SCALE_OVER_A_BIT 1.01

    //Scale.
    CGContextScaleCTM(context, scaleRatio * SCALE_OVER_A_BIT, scaleRatio * SCALE_OVER_A_BIT);
    [self drawAtPoint:CGPointZero];

    //End?
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

在大多数情况下,在我最近的项目中,它产生了原始形象(除了使用UIImageJPEGRepresentation和imageWithData:之后的磁盘)。

我在背景中使用了这种方法。 这个问题吗? 我怎么能够把这个问题变成安全的地方(使问题产生于翻新)。

最佳回答
-(UIImage*)scaleByRatio:(float) scaleRatio
{ 
   CGSize scaledSize = CGSizeMake(self.size.width * scaleRatio, self.size.height * scaleRatio);
   CGColorSpaceRef colorSpace;
   int   bitmapBytesPerRow;
   bitmapBytesPerRow   = (size.width * 4);

   //The output context.   
   UIGraphicsBeginImageContext(scaledSize);
   CGContextRef context = context = CGBitmapContextCreate (NULL,
                                 scaledSize .width,
                                 scaledSize .height,
                                 8,      // bits per component
                                 bitmapBytesPerRow,
                                 colorSpace,
                                 kCGImageAlphaPremultipliedLast);

 //Percent (101%)    
 #define SCALE_OVER_A_BIT 1.01

    //Scale.
   CGContextScaleCTM(context, scaleRatio * SCALE_OVER_A_BIT, scaleRatio * SCALE_OVER_A_BIT);
[self drawAtPoint:CGPointZero];

   //End?
   UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
   return scaledImage;
 }

在座各位必须使用<条形码>(CGBitmapContextCreate,不使用国名GetCurrentContext() ; becuase UIGraphicsGetCurrentContext() ;并非安全。

希望将有助于你们。

问题回答

暂无回答




相关问题
Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Is reading from an XmlDocument object thread safe?

I was wondering if i could safely read from an XmlDocument object using SelectNodes() and SelectSingleNode() from multiple threads with no problems. MSDN says that they are not guaranteed to be ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签