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
0
votes
0 answers

Any links / guidance on how to iterate and log raw pixels of an image using swift in iOS?

I'm trying to work on raw pixels of an image using swift language in iOS development. My target is to iterate and log pixel values / color space information of image using CGContextDrawImage and CGContextRef methods. Like the output in attached…
Rajesh Mappu
  • 483
  • 9
  • 23
0
votes
1 answer

UIImage is reversed when drawn on UIView

I am using camera picker controller to take a picture and I display it in my app. However I am not using UIImageView to display the picture. I am drawing the UIImage on a UIView, and the result I get is the reversed image. Here is the…
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
0
votes
1 answer

CGContextDrawImage error, how to allocate the buffer?

I am trying to store image data in buffer in my app so i will be able to use it however I get EXC_BAD_ACCESS error on CGContextDrawImage line. Here is the code i am using: resizedImage.Array() // resizedImage - resized image of 280x140 pixels size …
0
votes
0 answers

Error Checking in CGContextDrawImage

I am trying to draw a png image into a view. I tried copying the code from other sources. Absolutely nothing gets drawn. I inserted code to draw a background and doodles and that appears fine. Image draw. Nothing. It's reading the file because the…
user3344003
  • 20,574
  • 3
  • 26
  • 62
0
votes
3 answers

iOS 8.1 crash (EXC_BAD_ACCESS) : : ImageIO: CGImageReadGetBytesAtOffset : *** ERROR *** CGImageSource was created with data size:

Appreciate any help fixing a crash (EXC_BAD_ACCESS) in my iOS app. I am seeing this since updating my app to iOS 8, using latest available iOS 8.1.2. The same code worked fine in iOS 7.x. One of the views in my app is a UICollectionView. Every cell…
0
votes
1 answer

Centering image and vertically in UISegmentControl ios?

So I am trying to insert both image and text into a UISegmentControl .Now in this segmentControl I am looking to place image on top and text at its bottom.So I am using a category on UIImage to put title on it like below.However my image and text…
iSD
  • 103
  • 10
0
votes
1 answer

Cannot draw an image.

I have a UIImageView within an UIViewController and want to add a simple image on the existing imageView. The viewDidLoad-method looks like this: UIImage *test; test = [UIImage imageNamed:@"position-dot.png"]; [test…
iHank
  • 526
  • 9
  • 22
0
votes
2 answers

CGContextDrawImage distorts proportions

I have a cropped image (mainImage) that I allow users to draw on top of using their fingers. The red zig-zag on screen A. shows the finger drawn portion. Right now, using the code below, the newly drawn image context (red zig-zag) is shoved into the…
Jared Gross
  • 649
  • 3
  • 9
  • 23
0
votes
2 answers

How to draw a triangle over a UIImage in a UIImageView

I'm having trouble drawing atop an image in a UIImageView, I've already looked at "Draw another image on a UIImage" But it was only so much help. Here's my scenario: I have a UIPopoverController with a UITableView in it and I want to display a…
Sakiboy
  • 7,252
  • 7
  • 52
  • 69
0
votes
1 answer

iOS: CGContext SetTextDrawingMode Different Characters Cause Crash / No Text Drawn

I am using these functions to draw text over an image: char* text = (char *)[text1 cStringUsingEncoding:NSASCIIStringEncoding]; CGContextSelectFont(context, "Helvetica", fontSize, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context,…
Unheilig
  • 16,196
  • 193
  • 68
  • 98
0
votes
0 answers

How can make multiple stages for running multiple movie files using openGL?

I want to make program in xcode on mac where i want to make a window in two stages and two movie will run on it and these movie file data will come from buffer.Thats mean i have two movie file and i want to play these file concurrently in one window…
Emon
  • 452
  • 3
  • 11
  • 21
0
votes
2 answers

Is it possible to draw Graphics with CGContext and save them into a NSMutableArray?

At first I draw graphics: -(void)drawRect: (CGRect)rect{ //Circle circle = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(circle, [UIColor darkGrayColor].CGColor); …
Studie
  • 799
  • 2
  • 12
  • 20
0
votes
1 answer

clearContextBeforeDrawing in TouchEnd Method

I am using the pencil drawing simply. But i have to show it from rough drawing to Smooth drawing. So I am using the code differently in both touchesMoved and touchesEnded. The codes are as follows: -(void)touchesMoved:(NSSet *)touches…
Myaaoonn
  • 1,001
  • 12
  • 25
0
votes
1 answer

Array object gets released in iPad app due to memory warnings in iPad app

I am developing an iPad app. In my iPad if i run that app only then nothing happens, if i start some other apps nearly 4 to 5 then my app shows application received memory warning level 1 & application received memory warning level 2 and also in my…
Manikandan
  • 107
  • 2
  • 12
1 2 3 4
5