Open ToddManUtah opened 11 years ago
Thank you for the positive feedback. I'm not sure what exactly are you trying to do, but if I've understand it right here is my suggestion
You can put the drawing view on the top of an imageview that loads the saved image. Drawing view is transparent, so it could do the trick
Let me know if that will solve your problem
Thanks for that idea. I was looking at doing that in another section of code. The "other" section of code where I want to integrate your code would allow me to draw on an existing PDF.
BUT... that's not exactly what I'm looking to do here. Here is what I'm doing. I have extended your code to write out to file (the "Documents" directory). I simply replaced your code that takes a snapshot and saved it to file instead.
This works fine. The problem is when I want to load that file again. I have placed a new method in your class that allows me to set private "imageview" property. This works fine as well. The problem is that as soon as I add touch the screen (with any tool) to edit the previously saved imageview, it messes up.
Let's say I had drawn a square that aligned itself with the edges of my iPad. And then I saved that picture (as stated above). When I reload that picture the square is there just like I left it. It looks great. But... I add a scribble in the middle of the square and then it goes all wrong. The scribble stays where I put it, but the original square is zoomed out. All I see of the original square is the top lefthand corner of the square. It seems like it's using point 0,0 as an origin for its expansion.
See screen shots:
If I save this image and then reload it, the same thing happens as soon as I draw on the screen. It zooms out and moves down and to the right.
I guess I could overlay and then blend the two layers when saving, but seems like overkill for editing an image. Maybe not though. I'll concede to your opinion on this.
Any help/guidance you could give me would be greatly appreciated.
This is interesting. Is it possible to have the code that you are using so I can reproduce the issue ? Sorry for the delay, super busy at work
Absolutely. Can me give me an email address and I'll zip up the module. I really appreciate it, especially when you're busy. Once we get it figured out, I'd be more than willing to add my changes to you library if you want (you may not want them). But having a way to initialize the drawing is critical for many uses.
If not email, how would you like me to send the code?
Email is fine. You can use acerbetti@gmail.com
I'm happy to integrate your improvements to my library. You can fork the project and send me a pull request
@acerbetti - So is there a way to not clear the drawingView on load?
I have included the drawingView with files into an app I'm working on, but I would like the drawing to persist even if the user exits the ViewController. Is there a way to not clear the drawingView on load/appear?
@ToddManUtah - did you ever figure out a solution? I am trying to accomplish the same thing (load a previous drawing from device files) but the image appears zoomed and offset to the right.
Sorry Adam for the delay. I've been super busy with other projects and I'm not currently working on the component anymore.
I know loading an image from disk and import in the view can be tricky.
What about saving each step in a text/XML/Json format that can be exported and reimported later ? It will also allow you to edit or undo the draw
@ToddManUtah - In case you're still wondering how to correct the "zoom" issue, I figured it out.
What is happening, is that instead of scaling the image to 2.0 on your retina device, it automatically assumes the scale should be 1.0, which means it shows the full @2x saved image, appearing huge [zoomed].
FIX:
readonly
attribute from the image.viewWillAppear
method, add the following code to add your initial image content:if(savedInitialImage) {
// Detect and set scale
int imageScale;
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0) {
// Retina
imageScale = 2.0;
} else {
// Not Retina
imageScale = 1.0;
}
NSData *imageData = savedInitialImage;
self.drawingView.image = [UIImage imageWithData:imageData scale:imageScale];
}
I don't think I left out any details, but if I'm missing something, feel free to comment back. Hope this helps! :)
@acerbetti - can you see my issue here: https://github.com/acerbetti/ACEDrawingView/issues/1#issuecomment-30750118
Can you check the issues I posted on the GitHub project? I figured everything out except why the initial image is cleared if the user draws a line on top, and then hits 'Undo'
Thanks so much!
Adam Dehaven
On Sat, Dec 7, 2013 at 5:13 PM, Adam Dehaven abdehaven@gmail.com wrote:
To be honest, all I really need is to know how to not clear the drawing if the user moves to another view and then comes back?
Adam Sent from my iPhone
On Dec 7, 2013, at 1:20 PM, Stefano Acerbetti notifications@github.com wrote:
Sorry Adam for the delay. I've been super busy with other projects and I'm not currently working on the component anymore.
I know loading an image from disk and import in the view can be tricky.
What about saving each step in a text/XML/Json format that can be exported and reimported later ? It will also allow you to edit or undo the draw
— Reply to this email directly or view it on GitHubhttps://github.com/acerbetti/ACEDrawingView/issues/2#issuecomment-30061174 .
Hi Adam, I'm trying to understand your request.
The code snipped that you provided above is for the ViewController... do you mean my demo ViewController ? I don't think that is complete, I don't see where you store the UIImage.
so, do you only want to remove readonly from the property "image" ?
@acerbetti - The code above goes in my ViewController that displays the drawingView. I could, however, place it in the configure
setup in the ACEDrawingView.m
file.
Basically, my question is this:
drawingView.image
data to NSUserDefaults
. self.drawingView.image
to set the initial content. How can I load my image data from NSUserDefaults
into the ACEDrawingView.m
file as initial content, without it being cleared if the user draws and then hits "Undo"? Or if this isn't the correct way, how can I accomplish loading a saved image into the drawingView that is still present when saved? (not just a background image)
I tried your method for blending (here:https://github.com/acerbetti/ACEDrawingView/issues/1#issuecomment-12473823) but the same problem (# 3 above in my list) still occurs.
If that doesn't make sense, I can create a project you can run to see the behavior.
I did a commit to add support to load an external image, let me know if that will work for you
@acerbetti - I tested your loadImageData
method.
It loads the image properly on initial load, however, if I then draw on that image, and then press "Undo" once, it still clears both the last drawn line, as well as the initial image. What is causing it to clear when pressing "Undo"?
I had this same issue. Inititialized the view with a default image (landscape diagram). Perform actions, hit undo, and it clears the last step AND the loaded image. Here was my fix:
Add a variable for prev_image to your property declarations:
@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) UIImage *prev_image;
Under the loadImage method, copy the loaded image to this new property:
self.image = image;
//save the loaded image to persist after an undo step
self.prev_image = [image copy];
Inside the updateCacheImage method add the drawInRect call right after you clear the initial image in the redraw condition:
self.image = nil;
[[self.prev_image copy] drawInRect:self.bounds];
This will keep whatever image you initially load.
@iaretyler - that works perfectly! Thanks!
The only thing I added was in my clearSketch
method in my ViewController to also clear the prev_image
from screen.
Here's my clearSketch:
- (void)clearSketch
{
[self.drawingView clear];
[self.drawingView loadImageData:nil]; // **ADDED** clear prev_image
[self updateButtonStatus];
}
Good catch. We don't allow our guys to clear the diagram if its been save from the drawing view, jus delete the old one elsewhere in the code.
I encountered this problem,I changed line 121(in the ACEDrawingView) to [self.image drawInRect:self.bounds]. it's ok....
Hi acerbett, This code is very very helpful as per my requirement. i kept the drawing view on the top of an imageview that loads the saved image. Drawing view is transparent. Then after when i click on save button how to store edited image into my document directory. Please help me in this regard i am Thankfull if you help in this regard. Thank in advance
i resolved these....i want to zoom these editing image.help me
@Shivaseachange You can save the image from the ACEDrawingView and merge to your image http://stackoverflow.com/questions/4374188/merge-two-uiimages
please open a new issue for that
@acerbetti I'm using this code, which is very use full as per my requirement, only facing one challenge there.
When i draw or write something on view then it escape few starting character, for example if i write Hello then half H will cut off. Do you have any suggestion for this issue ?
I am trying to use you code to expand a simple app I'm working on. This code is really helpful!!!!
Questions: I'm saving the image to file and then reloading it. The problem I'm running into is setting the ACEDrawingView image with default content. It assumes an empty drawing surface. Is there something I'm missing? Did you allow for initial content?
I changed the code to allow (removed read-only setting on image in ACEDrawingView). I then set it in viewDidLoad of the controller class. This sort-of works. The image loads from file just fine. The problem is as soon as I draw on the image, it zooms out and moves the image down-and-to-the-right. This isn't ideal (obviously). Any ideas on how to make this more flexible (and still work)?