krzysztofzablocki / LineDrawing

Beatiful and fast smooth line drawing algorithm for iOS - as seen in Foldify.
http://twitter.com/merowing_
Other
1.29k stars 213 forks source link

Drawing and erasing over background image #14

Closed tolgatanriverdi closed 10 years ago

tolgatanriverdi commented 11 years ago

Hi I want to draw on an image which I put as background however let me explained what happened when I followed your suggestions

1.If I put render the background image into renderTexture either only my background picture seemed and my drawings did not or my drawings seemed but not my background picture .I've tried to change their z-order and somehow it worked but then I figured out that when I erase the lines that I draw it erases the background image too 2.I've added the background image like this

        backgroundImage = [CCSprite spriteWithCGImage:bgNativeImage.CGImage key:@"backgroundImage"];
        [self calculateBgImageSize];
        backgroundImage.opacity = 150;
        [self addChild:backgroundImage z:1];

only this time I could be able to draw and erase lines on top of background image but this time my image seems transparent and it iritates the user Can you suggest me a spesific way to handle this ? I thought on this a lot and it seems to me that only way to draw and erase the lines on top of an image is using layers such as photoshop

Then : I've made something like this according to kryzstofz suggestion

if (self.bgNativeImage) {
    if (!backgroundImage) {
        backgroundImage = [CCSprite spriteWithCGImage:bgNativeImage.CGImage key:@"backgroundImage"];
        [self calculateBgImageSize];
        [backgroundImage setBlendFunc:(ccBlendFunc){GL_ONE, GL_ZERO}];
        [backgroundLayer addChild:backgroundImage];
        //backgroundImage.opacity = 150;
        //[self addChild:backgroundImage z:1];
    }
    //[backgroundImage visit];

} 

[renderTexture begin];

NSMutableArray *smoothedPoints = [self calculateSmoothLinePoints]; if (smoothedPoints) { [self drawLines:smoothedPoints withColor:color]; }

if (self.bgNativeImage) { [backgroundLayer setZOrder:1]; [backgroundLayer visit]; } [renderTexture end];

now I can draw on image without any problem however when I try to erase the lines that I already draw.(with below algorithm) it also erases the background image

ccColor4F color = {0, 0, 0, 1}; if (!isPencilActive) { ccColor4F eraserColor = {1,1,1,1}; color = eraserColor; } else { color = drawingColor; } Do you have any idea about it? Thanks Tolga