Questions tagged [cgcontextdrawimage]

CGContextDrawImage is available in OSX and iOS which helps to draws an image into a graphics context. The issues related with drawRect or CGContextDrawImage can be tagged with this tag

CGContextDrawImage draws an image into a graphics context. It can be used by importing Apple's CoreGraphics framework.

There are some use cases (not the majority) for which the CALayer and Core Animation approach will not work. For those cases, CGContextDrawImage could spend a lot of time in decompressing or resampling the images as necessary because the images will not be cached in the layer tree.

For more information:

Example:

Draw your image into a grayscale context

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
  context = CGBitmapContextCreate(nil, inputWidth, inputHeight,
                     8, 0, colorSpace, (CGBitmapInfo)kCGImageAlphaNone);

  CGContextDrawImage(context, imageRect, [imageWithGhost CGImage]);

  CGImageRef imageRef = CGBitmapContextCreateImage(context);
  UIImage * finalImage = [UIImage imageWithCGImage:imageRef];

Related Stack Overflow Questions:

  1. CGContextDrawImage draws image upside down when passed UIImage.CGImage

  2. CGContextDrawImage is EXTREMELY slow after large UIImage drawn into it

  3. rotate image using CGContextDrawImage

74 questions
1
vote
1 answer

iOS - is it possible to cache CGContextDrawImage?

I used the timing profile tool to identify that 95% of the time is spent calling the function CGContextDrawImage. In my app there are a lot of duplicate images repeatably being chopped from a sprite map and drawn to the screen. I was wondering if…
woot586
  • 3,906
  • 10
  • 32
  • 40
1
vote
0 answers

CGContext strokes lags when scaled compared to the default scale value

I'm working on a simple freehand drawing app. Below is the sample code, I'm using the UIGesture class to track the scribble, i.e., pencil or finger movement, and then stroking those touch points on the UIImageView, the stroke edges are blurry hence…
1
vote
3 answers

Using CGContext of UIGraphicImageRenderer to redraw an image, flipped the image. How to prevent the flip?

Given an image, when I want to convert to standard sRGB, I can CGContext to help draw it as below. Given the original image When I use the CGContext directly, it redraws correctly extension UIImage { func toSRGB() -> UIImage { …
Elye
  • 53,639
  • 54
  • 212
  • 474
1
vote
2 answers

Convert raw image data to jpeg in swift

I am trying to convert the raw image data to jpeg in swift. But unfortunately, the jpeg image created is skewed. Please find below the code used for the conversion. let rawPtr = (rawImgData as NSData).bytes let mutableRawPtr =…
Aravind G S
  • 392
  • 3
  • 17
1
vote
1 answer

How use CGContextDrawImage in Swift 3?

I have an UIImage extension that uses CGContextDrawImage. It simply rotate a UIImage. I updated to Xcode8 and Swift3 and cant figure out how to use CGContextDrawImage. I got error on CGContextDrawImage. "Cannot convert value of type "CGImage.Type…
dejix
  • 1,144
  • 1
  • 12
  • 23
1
vote
0 answers

UIGraphicsBeginImageContextWithOptions casue black edge

UIGraphicsBeginImageContextWithOptions(size, YES, [UIScreen mainScreen].scale); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); [[UIColor whiteColor] set]; CGContextFillRect(context, CGRectMake(0, 0, size.width,…
zedzhao
  • 517
  • 1
  • 3
  • 17
1
vote
0 answers

CGContextDrawImage Blending

I am drawing, or should I say "stamping", an image using the CGContextDrawImage method in Objective C. The image gets drawn to points that are determined by touch movements. Basically I'm stamping an image to create a "brush" effect. Looks something…
Amendale
  • 317
  • 3
  • 19
1
vote
0 answers

image position was wrong in block using CGContextDrawImage

I was followed by this tutorial to draw text using Core Text, and I want to add web image to the view. when I used the code below, everything works fine except waiting the downloading time. - (void)drawRect:(CGRect)rect { CGContextRef context =…
lixiaoyu
  • 378
  • 5
  • 18
1
vote
0 answers

iOS Best way to draw multiple small images on a large UIView

I have a very, very large UIView, which uses a CATiledLayer. I need to render a lot of small images onto it. These small images are stored in one large image (1024x1024). They may have transparency. At the moment, I use CGImageCreateWithImageInRect…
PhilipG
  • 113
  • 6
1
vote
1 answer

Create Scalable Path CGContextPath

I'm new to developing in iOS. I have problem when draw with Core Graphics/UIKit. I want to implement a function like shape of paint in Window. I use this source: https://github.com/JagCesar/Simple-Paint-App-iOS, and add new function. When…
1
vote
0 answers

CGContextDrawImage off Screen performance

I have been using the following code to create an image off the screen (creating a context, off-screen in background thread using GDC ) and later render it in the main thread on the screen only when i receive updated "array of UIImages" . I found…
user519274
  • 1,074
  • 1
  • 11
  • 22
1
vote
1 answer

How to get boarder of ellipse using CGContextDrawImage in ios 6.0

I have drawn a ellipse using following code with border. When i use CGContextDrawImage method i am not getting border, image is visible as ellipse shape. Otherwise i got border line of this ellipse. Actually i would like to get image with ellipse…
Prasad G
  • 6,702
  • 7
  • 42
  • 65
1
vote
1 answer

CGContextDrawPath: invalid context 0x0

I have this code, that I think is the problem here: CGContextRef context = CGBitmapContextCreate(nil, routeView.frame.size.width, …
Alejandro L.
  • 1,066
  • 5
  • 17
  • 38
1
vote
1 answer

iOS: Rotating with CGContextRotate

Im trying to rotate an image, that i want to draw on a image file (to the context. Everything works fine, except when i rotate the image. Basically i have an image; i want to scale and resize the image and then clip it to a rect and finaly draw it…
Oritm
  • 2,113
  • 2
  • 25
  • 40
1
vote
3 answers

Add PDF page in iOS

I have an algorithm to create a PDF file, but I want just to add one pdf page at the end of existing pdf. Do any one has idea about that?
objectivecdeveloper
  • 1,050
  • 11
  • 29