Tag: uigraphicscontext

UIScrollView中的UIView的素描

当我尝试在UIScrollView的子视图UIView上绘制草图时遇到问题。 在UIView放大或滚动之后尝试在UIView上绘制草图时,会出现问题。 看起来我的草图代码(如下所示)没有考虑UIScrollView内的UIView的缩放或缩放,因为线条模糊,并没有显示他们应该在哪里。 请让我知道是否有什么可以做我的代码或提供另一种解决scheme。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"Draw touchesBegan"); mouseSwipedPSVC = NO; UITouch *touch = [touches anyObject]; lastPointPSVC = [touch locationInView:sheetDrawView]; } – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwipedPSVC = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:sheetDrawView]; UIGraphicsBeginImageContext(sheetDrawView.frame.size); [drawImageView.image drawInRect:CGRectMake(0, 0, sheetDrawView.frame.size.width, sheetDrawView.frame.size.height)]; CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPointPSVC.x, lastPointPSVC.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, […]

renderInContext税收应用程序内存

我正在2448 X 2448像素图像上运行此代码。 fullScaleView也是2448 X 2448( fullScreenView Rect:{{0, 0}, {2448, 2448}} )。 方法完成后,应用程序内存从49.7MB跳到240MB到172​​MB。 它保持在172MB。 在这个renderInContext之后,似乎应用程序仍然应该在如此高的内存空间下运行。 在哪里以及如何强制发布? (iOS 7 XCode 5 ARC)。 UIGraphicsBeginImageContextWithOptions(fullScaleView.bounds.size, fullScaleView.opaque, 1.0); [fullScaleView.layer renderInContext: UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();

如何撤消一个行中的ios

我开发一个着色应用程序,但是我不能设法实现一个UNDObutton。 我不确定的方法,我尝试过实施NSUndoManager,但我无法得到有效的工作。 我的方法可能不正确。 林将不胜感激基于我的例子使用代码的答案。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = NO; UITouch *touch = [touches anyObject]; lastPoint = [touch locationInView:self.view]; } – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; UIGraphicsBeginImageContext(self.view.frame.size); [self.tempImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; //get the current touch point and then […]

FileManager表示文件不存在

我有一个用例,需要将UIImage保存到文档目录 – 然后UIImage需要被转换成PDF并保存到文档目录。 代码转换为PDF var filePath = NSString(string: self.selectedMedia!.imagePath!) if FileManager().fileExists(atPath: filePath as String) { filePath = filePath.deletingPathExtension as NSString filePath = NSString(string: filePath.appendingPathExtension("PDF")!) if let image = UIImage(data: self.selectedMedia?.image! as! Data) { let rect:CGRect = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) UIGraphicsBeginPDFContextToFile(filePath as String, rect, nil); UIGraphicsBeginPDFPageWithInfo(rect, nil); UIGraphicsGetCurrentContext(); image.draw(in: rect) UIGraphicsEndPDFContext(); […]

目标c中从uiwebview生成PDF的问题

我已经在uiwebview中打开pdf文件,在uiwebview子视图中添加图像和文本。然后我尝试创buildPDF文件。 下面我用来生成pdf文件的示例。 在单页中写多页。 我如何写样本质量和确切的大小。 请检查屏幕截图和源代码 UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil ); for (int i = 0; i < 10; i++) { CGRect f = [pdfView frame]; [pdfView setFrame: f]; UIGraphicsBeginPDFPage(); CGContextRef currentContext = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(currentContext, 72, 72); // Translate for 1" margins [[[pdfView subviews] lastObject] setContentOffset:CGPointMake(0, 648 * i) animated:NO]; [pdfView.layer renderInContext:currentContext]; } UIGraphicsEndPDFContext(); 而且我也尝试了下面这个链接,但是我不能添加uiwebview子视图来写pdf。 http://b2cloud.com.au/tutorial/drawing-over-a-pdf-in-ios-pdf-template/

swift UIGraphicsGetImageFromCurrentImageContext不能释放内存

SWIFT代码 当我们得到一个UIView的截图时,我们通常使用这个代码: UIGraphicsBeginImageContextWithOptions(frame.size, false, scale) drawViewHierarchyInRect(bounds, afterScreenUpdates: true) var image:UIImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() 问题 drawViewHierarchyInRect && UIGraphicsGetImageFromCurrentImageContext将在当前上下文中生成一个图像,但是当调用UIGraphicsEndImageContext时,内存不会被释放。 内存使用继续增加,直到应用程序崩溃。 虽然有一个单词UIGraphicsEndImageContext会自动调用CGContextRelease “,但它不起作用。 我如何释放内存drawViewHierarchyInRect或UIGraphicsGetImageFromCurrentImageContext 要么? 反正有没有drawViewHierarchyInRect生成屏幕截图? 已经尝试过了 1自动释放:不工作 var image:UIImage? autoreleasepool{ UIGraphicsBeginImageContextWithOptions(frame.size, false, scale) drawViewHierarchyInRect(bounds, afterScreenUpdates: true) image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() } image = nil 2 UnsafeMutablePointer:不起作用 var image:UnsafeMutablePointer<UIImage> = UnsafeMutablePointer.alloc(1) autoreleasepool{ UIGraphicsBeginImageContextWithOptions(frame.size, false, scale) drawViewHierarchyInRect(bounds, afterScreenUpdates: true) […]

在objective-c中创build多页PDF

我正在尝试创build一个多页PDF。 我已经按照这个教程 。 这是与静态文本的XIB文件,然后添加一个代码表。 但是,我有ATM的问题是,当表大于一页时。 当表格有多于9行时。 它应该继续下一页。 这就是我在代码中所做的。 +(void)drawPDF:(NSString*)fileName { NSMutableDictionary *mutDictValues = [[[NSUserDefaults standardUserDefaults] objectForKey:@"dicValues"] mutableCopy]; NSMutableArray *arrSelectedCities = [[mutDictValues objectForKey:@"cities"]mutableCopy ]; if(arrSelectedCities.count <= 8){ // If there are only 8 rows –> we can fit everyting on one page ! // Create the PDF context using the default page size of 612 x […]

UIImage用另一个图像填充透明部分

我想用iOS中的另一个图像填充图像的透明部分。 我已经尝试了一些与UIGraphicsContext东西,但我不能得到它的工作,因为我从来没有使用过。 这是图像: 我试过一些代码: UIImageView *v = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 70, 70)]; UIGraphicsBeginImageContextWithOptions(v.frame.size, YES, 0); CGContextRef context = UIGraphicsGetCurrentContext(); // beach image UIImage *img = [UIImage imageNamed:@"zivogosce_camping_05.jpg"]; //[img drawInRect:CGRectMake(2, 0, 12, 12)]; UIImage *annotationImg = [UIImage imageNamed:@"custom_annotation"]; [annotationImg drawAtPoint:CGPointMake(0, 0)]; CGContextSetFillColorWithColor(context, [[UIColor colorWithPatternImage:img] CGColor]); CGContextFillRect(context, CGRectMake(0, 0, 50, 50)); CGContextDrawImage(context, CGRectMake(0, 0, v.frame.size.width, v.frame.size.height), […]

擦除时图像变得模糊和缩小

我正在使用擦除图像的function,我的代码如下所示。 你可以看到这里的video 。 这里current_sticker_img是我的Imageview 注意: 我也使用Pan Gesture来缩放图像 //MARK: Eraser touch event override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { if btn_eraser.isSelected == true || btn_repaint.isSelected == true{ let touch : UITouch = touches.first! lastpoint = touch.location(in: current_sticker_img) } } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { if btn_eraser.isSelected == true || btn_repaint.isSelected […]

IOS的雪碧套件screengrab?

我试图获得一个SKScene的视图的屏幕抓取。 我正在使用的技术是: UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, scale); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 这对于普通的UIViews来说效果很好,但是无论如何它忽略了SKScene中的所有精灵。 我不确定这是否是一个错误,或者Sprite Kit的渲染是否与UIGraphics分离。 问题:如何在使用UIViews的方式看起来不适用于Sprite Kit,或者有人使用Sprite Kit使用UIGraphics上下文时,如何获得SKScene的屏幕截图?