【发布时间】:2015-01-29 04:51:43
【问题描述】:
我正在使用 CGContextRef 在 UIImage 上画线。我的图像的分辨率非常大,例如 3000x4500。如果我画一条线,它不会给我内存警告,但如果我要画多条线,那么它会给我内存警告,然后我的应用程序崩溃。尝试释放 CGContextRef 对象但出现错误。我的代码:
UIGraphicsBeginImageContext(imageView.image.size);
[imageView.image drawAtPoint:CGPointMake(0, 0)];
context2=UIGraphicsGetCurrentContext();
for(int i=0; i<kmtaObject.iTotalSize; i++)
{
kmtaGroup=&kmtaObject.KMTA_GROUP_OBJ[i];
//NSLog(@"Group # = %d",i);
for (int j=0; j<kmtaGroup->TotalLines; j++)
{
lineObject=&kmtaGroup->Line_INFO_OBJ[j];
// NSLog(@"Line # = %d",j);
// NSLog(@"*****************");
x0 = lineObject->x0;
y0= lineObject->y0;
x1= lineObject->x1;
y1= lineObject->y1;
color= lineObject->Color;
lineWidth= lineObject->LinkWidth;
lineColor=[self add_colorWithRGBAHexValue:color];
linearColor=lineColor;
// Brush width
CGContextSetLineWidth(context2, lineWidth);
// Line Color
CGContextSetStrokeColorWithColor(context2,[linearColor CGColor]);
CGContextMoveToPoint(context2, x0, y0);
CGContextAddLineToPoint(context2, x1, y1);
CGContextStrokePath(context2);
}
}
newImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageView.image=newImage;
【问题讨论】:
-
@Zaph 如果你能详细说明......
-
对不起,不好的评论,我猜你不能因为所有不同的颜色,宽度。
-
我认为你应该看看这个例子 ZoomingPDFViewer:developer.apple.com/library/ios/samplecode/ZoomingPDFViewer/… 你应该看看
TiledPDFView
标签: ios objective-c uiimageview uiimage