Black and white overlay for MKMapView

I have MKMapView and I am adding an overlay (MKOverlay) to it.

I would like the overlay to make the map look beneath it black and white (i.e. monochrome). Is there any way to do this?

(I think I could make the overlay translucent black / gray, but this is not the exact effect I would like.)


System Information: iOS 5 app development in Xcode 4.2.

+5
source share
2 answers

The most correct route, which, unfortunately, is not yet available on iOS, would be:

MKOverlay - MKOverlayView, CALayer, UIView. CIFilter compositingFilter CALayer s, , . CIColorMonochrome.

, , . , MKOverlayView, drawView , Apple QA1703, ( , ), - .

-, , , ?

+7

, , - , :

  • CGcontex
  • CGcontext
  • UIImage CGcontext
  • CIFilter UIImage CIImage
  • CIImage CIContext CGImageRef
  • UIImage CGImageRef
  • subviewview Apple.
  • View

:

  self.drawContext = [[CIContext alloc] init];
  [self.monochromeSubView removeFromSuperview];

  UIGraphicsBeginImageContext(self.appleMapView.bounds.size);
  UIImage *mySourceImage = UIGraphicsGetImageFromCurrentImageContext();
  CIImage *newMyCiImage = [[CIImage alloc] initWithImage:mySourceImage];
  CIFilter *newMyMonochromeFilter = [CIFilter filterWithName:@"CIPhotoEffectTonal"];
  [newMyMonochromeFilter setValue:newMyCiImage forKey:kCIInputImageKey];
  CIImage *newMyfilteredCIImage = newMyMonochromeFilter.outputImage;
  
  CGImageRef myOutputImageRef = [self.drawContext createCGImage:newMyfilteredCIImage
                                                       fromRect:newMyfilteredCIImage.extent];
  UIImage *newMyImage = [[UIImage alloc] initWithCGImage:myOutputImageRef];

  self.monochromeSubView.image = newMyImage;
  [self.appleMapView addSubview:self.monochromeSubView];

  CGImageRelease(myOutputImageRef);
  UIGraphicsEndImageContext();
Hide result

- - . , , , . touchesMoved , - . apple, 1/3 , ( 3 FPS iPhone 5s), , , : , , , , . CALayer, , Apple , , , , , : GoogleMap MapBox.

+1

All Articles