ebarellar/LFColoringBook

Restore coloring book view after savedImage write to document folder.

Closed this issue · 3 comments

I have interesting for your project.
It work very well. I have question about restore coloring book view after savedImage write to document folder.

How to draw again coloring book view if savedImage exist?
I have try to draw savedImage in frozen context but it isn't working.

func setSavedImage(_ image: UIImage?) {
        guard let currentImage = image?.cgImage else {
            return
        }
        
        self.savedImage = NSMutableData()
        if let dest = CGImageDestinationCreateWithData(self.savedImage!,
                                                       kUTTypePNG,
                                                       1, nil){
            CGImageDestinationAddImage(dest,
                                       currentImage, nil)
            if CGImageDestinationFinalize(dest){
                self.strokes.removeAll()
            }
        }
        
        redrawInFrozenContext()
    }

Cool.
The implementation looks fine, how does everything look in the debugger? is currentImage not nil? at what time in app lifetime are you calling setSavedImage?

Honestly, if I had known so many people would visit the project I would have tried to implement more features. Maybe I'll work into adding save functionality and proper serialization of the ColoringImage struct to avoid pre-processing if the masks have already been created

I call setSavedImage in function createColoringBookView and currentImage not nil

self.coloringBookView?.currentColor = lastColor
self.coloringBookView?.currentWidth = 20.0
self.coloringBookView?.setSavedImage(currentImage)

After not redraw savedImage. I must try to draw some lines that savedImage is restore but not at all:

This is savedImage that I draw before
savedImage

After call reduceHistory that view draw:
reduceHistoryImage

Seems a clip mask is still in memory

Before calling redrawInFrozenContext I would try to call frozenContext.resetClip() in your method to see if it fixes the bug