Click here to Skip to main content
15,500,227 members
Home / Discussions / iOS
   

iOS

 
GeneralRe: Is there website to make free ios apps? Pin
Surya_Narayan13-Apr-17 20:20
professionalSurya_Narayan13-Apr-17 20:20 
GeneralRe: Is there website to make free ios apps? Pin
malina.fitowska15-Jan-18 1:30
Membermalina.fitowska15-Jan-18 1:30 
GeneralRe: Is there website to make free ios apps? Pin
Surya_Narayan16-Jan-18 22:53
professionalSurya_Narayan16-Jan-18 22:53 
QuestionRe: Is there website to make free ios apps? Pin
David Crow11-Apr-17 2:55
MemberDavid Crow11-Apr-17 2:55 
QuestionHow to Create Time Bar in xamarin iOS Pin
DELPIN SUSAI RAJ15-Mar-17 2:35
professionalDELPIN SUSAI RAJ15-Mar-17 2:35 
QuestionTimer (novice) Pin
Member 1296950226-Jan-17 12:12
MemberMember 1296950226-Jan-17 12:12 
AnswerRe: Timer (novice) Pin
Richard MacCutchan26-Jan-17 23:02
mveRichard MacCutchan26-Jan-17 23:02 
Questionhow to use magic wand tool Pin
Uttam Kumar Utterapally24-Jan-17 21:55
MemberUttam Kumar Utterapally24-Jan-17 21:55 
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.
Swift
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<UITouch>, 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
        return context!
    }
    
    
    
    
    public func getPixelColorAtLocation( point:CGPoint) -> UIColor {
        // Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
        var point = point
        
        var context:CGContext? = nil
        
        context = self.createARGBBitmapContext(inImage: (self.image?.cgImage)!)
        
        
        if context == nil {
            return UIColor.white
        }
        
        var pixelsWide = (self.image?.cgImage)!.width
        var pixelsHigh = (self.image?.cgImage)!.height
        var rect = CGRect(x:0, y:0, width:Int(pixelsWide), height:Int(pixelsHigh))
        
        var xScale:CGFloat = CGFloat(pixelsWide)/self.frame.size.width
        var yScale:CGFloat = CGFloat(pixelsHigh)/self.frame.size.height
        
        
        point.x = point.x * xScale
        point.y = point.y * yScale
        
        
        
        var x:CGFloat = 1.0
        
        
        
        if (self.image?.responds(to: #selector(getter:  self.image?.scale)))! {
            x =  ( self.image!.scale)
            
        }
        
        
        
        //Clear the context
        context?.clear(rect)
        
        // Draw the image to the bitmap context. Once we draw, the memory
        // allocated for the context for rendering will then contain the
        // raw image data in the specified color space.
        
        context?.draw((self.image?.cgImage)!, in: rect)
        
        // Now we can get a pointer to the image data associated with the bitmap
        // context.
        
        
        let data = context?.data
        //    let dataType = UnsafePointer<UInt8>(data)
        
        var color:UIColor? = nil
        if data != nil {
            let dataType = data?.assumingMemoryBound(to: UInt8.self)
            
            
            let offset = 4*((Int(pixelsWide) * Int(point.y)) + Int(point.x))
            let alpha = dataType?[offset]
            let red = dataType?[offset+1]
            let green = dataType?[offset+2]
            let blue = dataType?[offset+3]
            color = UIColor(red: CGFloat(red!)/255.0, green: CGFloat(green!)/255.0, blue: CGFloat(blue!)/255.0, alpha: CGFloat(alpha!)/255.0)
        }
        else
        {
            
            
        }
        
        
        
        // Free image data memory for the context
        free(data)
        return color!;
    } 
}


After some research I found one link to clear image like wand tool but that code is for mac can anyone tell me how to use it for ios app
http://losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/

or if there is any other code then please help me in changing the same pixel colour which covers particular area in UIImage.
can one please tell me how do use magic wand tools in ios?

modified 30-Jan-17 0:29am.

AnswerRe: how to use magic wand tool Pin
Member 1492059722-Aug-20 21:30
MemberMember 1492059722-Aug-20 21:30 
Questionhow to use magic wand tool in ios Pin
Uttam Kumar Utterapally24-Jan-17 21:55
MemberUttam Kumar Utterapally24-Jan-17 21:55 
AnswerRe: how to use magic wand tool in ios Pin
Member 1492059722-Aug-20 21:30
MemberMember 1492059722-Aug-20 21:30 
QuestionHow to focus on a specific location by using google maps. Pin
Asım Gündüz3-Jan-17 23:14
MemberAsım Gündüz3-Jan-17 23:14 
QuestionApple Pay - WEB Integration through Braintree - how to create Certificate for the Sandbox / Development Environment? Pin
AndreeaLib27-Dec-16 2:36
MemberAndreeaLib27-Dec-16 2:36 
QuestionXcode and I phone for debug Pin
Andy_Bell15-Dec-16 0:04
MemberAndy_Bell15-Dec-16 0:04 
QuestionRe: Xcode and I phone for debug Pin
David Crow15-Dec-16 3:26
MemberDavid Crow15-Dec-16 3:26 
Question2 Notification show in my create app ios Pin
Sathiya moorthi24-Oct-16 2:50
MemberSathiya moorthi24-Oct-16 2:50 
AnswerRe: 2 Notification show in my create app ios Pin
Richard MacCutchan24-Oct-16 2:52
mveRichard MacCutchan24-Oct-16 2:52 
AnswerRe: 2 Notification show in my create app ios Pin
First European12-Dec-16 5:40
MemberFirst European12-Dec-16 5:40 
QuestionTarget Ios with Xcode version Pin
Andy_Bell5-Oct-16 10:53
MemberAndy_Bell5-Oct-16 10:53 
QuestionHow to execute itextsharp Pin
Radiance Cosmedic Centre28-Sep-16 1:32
MemberRadiance Cosmedic Centre28-Sep-16 1:32 
AnswerRe: How to execute itextsharp Pin
Richard MacCutchan28-Sep-16 3:37
mveRichard MacCutchan28-Sep-16 3:37 
QuestionForce change in Wifi connection Pin
StampedePress22-Aug-16 6:55
MemberStampedePress22-Aug-16 6:55 
AnswerRe: Force change in Wifi connection Pin
Afzaal Ahmad Zeeshan22-Aug-16 8:04
mveAfzaal Ahmad Zeeshan22-Aug-16 8:04 
GeneralRe: Force change in Wifi connection Pin
StampedePress22-Aug-16 8:42
MemberStampedePress22-Aug-16 8:42 
GeneralRe: Force change in Wifi connection Pin
Afzaal Ahmad Zeeshan22-Aug-16 9:04
mveAfzaal Ahmad Zeeshan22-Aug-16 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.