Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. iOS
  4. how to use magic wand tool

how to use magic wand tool

Scheduled Pinned Locked Moved iOS
graphicsperformancetutorialswiftquestion
3 Posts 3 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    Uttam Kumar Utterapally
    wrote on last edited by
    #1

    how to change the colour of particular pixel and pixel area covered with the same colour.I am able to get the particular pixel colour using below swift code but I am not able to get surrounding area which has same colour pixel and unable to change it.

    import UIKit

    class ColorOfImage: UIImageView {

    var lastColor:UIColor? = nil
    
    
    
    /\*
     // Only override draw() if you perform custom drawing.
     // An empty implementation adversely affects performance during animation.
     override func draw(\_ rect: CGRect) {
     // Drawing code
     }
     \*/
    
    override func touchesEnded(\_ touches: Set, with event: UIEvent?) {
        
        if self.isHidden == true {
            
            self.next?.touchesEnded(touches, with: event)
            return
        }
        
        let touch: UITouch = touches.first!
        
        var point:CGPoint = touch.location(in: self)
        self.lastColor = self.getPixelColorAtLocation(point:point)  
    }
    
    
    public func createARGBBitmapContext(inImage: CGImage) -> CGContext {
    
        var bitmapByteCount = 0
        var bitmapBytesPerRow = 0
        
        //Get image width, height
        let pixelsWide = inImage.width
        let pixelsHigh = inImage.height
        
        // Declare the number of bytes per row. Each pixel in the bitmap in this
        // example is represented by 4 bytes; 8 bits each of red, green, blue, and
        // alpha.
        bitmapBytesPerRow = Int(pixelsWide) \* 4
        bitmapByteCount = bitmapBytesPerRow \* Int(pixelsHigh)
        
        // Use the generic RGB color space.
        let colorSpace = CGColorSpaceCreateDeviceRGB()
        
        
        
        // Allocate memory for image data. This is the destination in memory
        // where any drawing to the bitmap context will be rendered.
        let bitmapData = malloc(bitmapByteCount)
        
        // Create the bitmap context. We want pre-multiplied ARGB, 8-bits
        // per component. Regardless of what the source image format is
        // (CMYK, Grayscale, and so on) it will be converted over to the format
        // specified here by CGBitmapContextCreate.
        let context = CGContext(data: bitmapData, width: pixelsWide, height: pixelsHigh, bitsPerComponent: 8, bytesPerRow: bitmapBytesPerRow, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue)
        
        // Make sure and release colorspace before returning
        r
    
    S M 2 Replies Last reply
    0
    • U Uttam Kumar Utterapally

      how to change the colour of particular pixel and pixel area covered with the same colour.I am able to get the particular pixel colour using below swift code but I am not able to get surrounding area which has same colour pixel and unable to change it.

      import UIKit

      class ColorOfImage: UIImageView {

      var lastColor:UIColor? = nil
      
      
      
      /\*
       // Only override draw() if you perform custom drawing.
       // An empty implementation adversely affects performance during animation.
       override func draw(\_ rect: CGRect) {
       // Drawing code
       }
       \*/
      
      override func touchesEnded(\_ touches: Set, with event: UIEvent?) {
          
          if self.isHidden == true {
              
              self.next?.touchesEnded(touches, with: event)
              return
          }
          
          let touch: UITouch = touches.first!
          
          var point:CGPoint = touch.location(in: self)
          self.lastColor = self.getPixelColorAtLocation(point:point)  
      }
      
      
      public func createARGBBitmapContext(inImage: CGImage) -> CGContext {
      
          var bitmapByteCount = 0
          var bitmapBytesPerRow = 0
          
          //Get image width, height
          let pixelsWide = inImage.width
          let pixelsHigh = inImage.height
          
          // Declare the number of bytes per row. Each pixel in the bitmap in this
          // example is represented by 4 bytes; 8 bits each of red, green, blue, and
          // alpha.
          bitmapBytesPerRow = Int(pixelsWide) \* 4
          bitmapByteCount = bitmapBytesPerRow \* Int(pixelsHigh)
          
          // Use the generic RGB color space.
          let colorSpace = CGColorSpaceCreateDeviceRGB()
          
          
          
          // Allocate memory for image data. This is the destination in memory
          // where any drawing to the bitmap context will be rendered.
          let bitmapData = malloc(bitmapByteCount)
          
          // Create the bitmap context. We want pre-multiplied ARGB, 8-bits
          // per component. Regardless of what the source image format is
          // (CMYK, Grayscale, and so on) it will be converted over to the format
          // specified here by CGBitmapContextCreate.
          let context = CGContext(data: bitmapData, width: pixelsWide, height: pixelsHigh, bitsPerComponent: 8, bytesPerRow: bitmapBytesPerRow, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue)
          
          // Make sure and release colorspace before returning
          r
      
      S Offline
      S Offline
      Sneha Agarwal
      wrote on last edited by
      #2

      You are right.

      1 Reply Last reply
      0
      • U Uttam Kumar Utterapally

        how to change the colour of particular pixel and pixel area covered with the same colour.I am able to get the particular pixel colour using below swift code but I am not able to get surrounding area which has same colour pixel and unable to change it.

        import UIKit

        class ColorOfImage: UIImageView {

        var lastColor:UIColor? = nil
        
        
        
        /\*
         // Only override draw() if you perform custom drawing.
         // An empty implementation adversely affects performance during animation.
         override func draw(\_ rect: CGRect) {
         // Drawing code
         }
         \*/
        
        override func touchesEnded(\_ touches: Set, with event: UIEvent?) {
            
            if self.isHidden == true {
                
                self.next?.touchesEnded(touches, with: event)
                return
            }
            
            let touch: UITouch = touches.first!
            
            var point:CGPoint = touch.location(in: self)
            self.lastColor = self.getPixelColorAtLocation(point:point)  
        }
        
        
        public func createARGBBitmapContext(inImage: CGImage) -> CGContext {
        
            var bitmapByteCount = 0
            var bitmapBytesPerRow = 0
            
            //Get image width, height
            let pixelsWide = inImage.width
            let pixelsHigh = inImage.height
            
            // Declare the number of bytes per row. Each pixel in the bitmap in this
            // example is represented by 4 bytes; 8 bits each of red, green, blue, and
            // alpha.
            bitmapBytesPerRow = Int(pixelsWide) \* 4
            bitmapByteCount = bitmapBytesPerRow \* Int(pixelsHigh)
            
            // Use the generic RGB color space.
            let colorSpace = CGColorSpaceCreateDeviceRGB()
            
            
            
            // Allocate memory for image data. This is the destination in memory
            // where any drawing to the bitmap context will be rendered.
            let bitmapData = malloc(bitmapByteCount)
            
            // Create the bitmap context. We want pre-multiplied ARGB, 8-bits
            // per component. Regardless of what the source image format is
            // (CMYK, Grayscale, and so on) it will be converted over to the format
            // specified here by CGBitmapContextCreate.
            let context = CGContext(data: bitmapData, width: pixelsWide, height: pixelsHigh, bitsPerComponent: 8, bytesPerRow: bitmapBytesPerRow, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue)
            
            // Make sure and release colorspace before returning
            r
        
        M Offline
        M Offline
        Member_14920597
        wrote on last edited by
        #3

        I am not an expert in this field But if you find the solution, I am interested

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups