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
3
votes
2 answers

Strange behaviour with CGContext - iOS

The following code splits an image into 2. It seems working fine with non-retina devices, however it gives a different output with retina devices. Could someone please help me fix it? Thanks.. My Code UIImage *img = [UIImage…
user1526474
  • 925
  • 13
  • 26
3
votes
2 answers

drawRect always wants to update the entire screen when view is shrunken

I have a CGImage that is displayed in an UIView controlled by a UIScrollView. The image is typically 1680*1050 in 24 bit colors without alpha channel. The image is created like this: CGImageRef bitmapClass::CreateBitmap(int width, int height, int…
2
votes
1 answer

Alpha Detection in Layer OK on Simulator, not iPhone

First, check out this very handy extension to CALayer from elsewhere on SO. It helps you determine if a point in a layer's contents-assigned CGImageRef is or isn't transparent. n.b.: There is no guarantee about a layer's contents being representable…
2
votes
1 answer

iOS Redrawing image to prevent deferred decompression resulting in a bigger image

I've noticed some people redraw images on a CGContext to prevent deferred decompression and this has caused a bug in our app. The bug is that the size of the image professes to remain the same but the CGImageDataProvider data has extra bytes…
funct7
  • 3,407
  • 2
  • 27
  • 33
2
votes
1 answer

Why does my CGImage not display correctly after setNeedsDisplay

I'm drawing a colorWheel in my app. I do this by generating a CGImage in a separate function and using CGContextDrawImage in drawRect to put it onscreen. On the initial presentation it looks fine, but after I call setNeedsDisplay (or…
Philip De Vries
  • 417
  • 4
  • 13
2
votes
1 answer

Canvas drawImage draws only some part of SVG

I have chart SVG of width around 500 and height around 300. I have scaled it using scale attribute in SVG. Now when I tried drawing it on canvas it draws on some part from top left corner of the SVG. If I open SVG file separately in browser it shows…
Nitesh Phadatare
  • 315
  • 1
  • 2
  • 12
2
votes
3 answers

Creating a custom image with UIImage and other attributes

I am looking to create a custom image in iOS. The image would be used for sharing to social sites for example. As an example, the user might select a photo which we have a reference to as a UIImage. With this image we want to create another image…
StuartM
  • 6,743
  • 18
  • 84
  • 160
2
votes
0 answers

Accessing Bitmap of CIImage or CGImage besides CGContextDrawImage

I would like to get the RGB (actually, the image provided has been grey-scaled, so grey-scale information would be sufficient) values of the individual pixels of a CIImage. I currently have the following code: // // Conversion of CIImage to…
mercator
  • 99
  • 1
  • 10
2
votes
0 answers

Xamarin draw cyrillic text in CGContext

First, here is my code, I'm drawing first letter of nickname in userpic: context.TranslateCTM (0, rect.Height); context.ScaleCTM (1, -1); context.SelectFont ("Helvetica", 140.0f, CGTextEncoding.MacRoman); …
animekun
  • 1,789
  • 4
  • 28
  • 45
2
votes
1 answer

Scaling UIImage for use with with CGContextDrawImage

I have an image which measures 480px x 480px and I'd like to display it in a view which measures 375px x 375px using CGContextDrawImage as below. At the moment the image doesn't scale to fit the view - it is drawn at full size. How can I adjust the…
Simon
  • 384
  • 4
  • 22
2
votes
1 answer

iOS : Drawing on a CGContext eventually blurs

I have a app that displays a document that has a UIImage over the top of it where you can draw lines etc to highlight stuff. If I keep drawing lines (touch, draw, lift finger off, and repeat in a different area of the screen) The lines slowly…
Burf2000
  • 5,001
  • 14
  • 58
  • 117
2
votes
0 answers

App Crash due to Receive memory warning in CGContextDrawImage?

my app Crash due to Receive memory Warning.when i run app with instruments then i get the following leak memory issue . here is my full code of this method. - (UIImage *)resizeImage:(UIImage *)orignalImage newWidth:(int)width…
jamil
  • 2,419
  • 3
  • 37
  • 64
2
votes
2 answers

How to use CGContextDrawImage?

I need some help using the CGContextDrawImage. I have the following code which will create a Bitmap context and convert the pixel data to CGImageRef. Now I need to display that image using CGContextDrawImage. I'm not very clear on how I'm supposed…
Ereka
  • 103
  • 1
  • 10
2
votes
1 answer

Drawing pattern with UIImage not like pattern but it is filled UIImage in UIView

My line of code: UIColor *brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"Frame-1@2x.png"]]; CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),brushPattern.CGColor); Image pattern url Which does not draw like…
Undertaker
  • 39
  • 1
  • 7
2
votes
3 answers

How can I find the points in a line - Objective c?

Consider a line from point A (x,y) to B (p,q). The method CGContextMoveToPoint(context, x, y); moves to the point x,y and the method CGContextAddLineToPoint(context, p, q); will draw the line from point A to B. My question is, can I find the all…
Confused
  • 3,846
  • 7
  • 45
  • 72