Git Product home page Git Product logo

Comments (23)

acerbetti avatar acerbetti commented on July 1, 2024

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

from acedrawingview.

ToddManUtah avatar ToddManUtah commented on July 1, 2024

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:
Screen Shot 2013-03-12 at 9 20 08 AM
Screen Shot 2013-03-12 at 9 19 16 AM

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.

from acedrawingview.

acerbetti avatar acerbetti commented on July 1, 2024

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

from acedrawingview.

ToddManUtah avatar ToddManUtah commented on July 1, 2024

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?

from acedrawingview.

acerbetti avatar acerbetti commented on July 1, 2024

Email is fine. You can use [email protected]

I'm happy to integrate your improvements to my library. You can fork the project and send me a pull request

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@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?

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@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.

from acedrawingview.

acerbetti avatar acerbetti commented on July 1, 2024

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

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@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:

  1. Remove the readonly attribute from the image.
  2. In your ViewController, in the 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! :)

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@acerbetti - can you see my issue here: #1 (comment)

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

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 [email protected] 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 [email protected]
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//issues/2#issuecomment-30061174
.

from acedrawingview.

acerbetti avatar acerbetti commented on July 1, 2024

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" ?

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@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:

  1. When a user leaves the ViewController showing the drawingView, I save the drawingView.image data to NSUserDefaults.
  2. Then, when the load views, I load this image as self.drawingView.image to set the initial content.
  3. If the user then draws, everything is fine. But the first time they touch the "Undo" button, the last line drawn along with the initial image is cleared.

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:#1 (comment)) 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.

from acedrawingview.

acerbetti avatar acerbetti commented on July 1, 2024

I did a commit to add support to load an external image, let me know if that will work for you

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@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"?

from acedrawingview.

kiserrolls avatar kiserrolls commented on July 1, 2024

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.

from acedrawingview.

adamdehaven avatar adamdehaven commented on July 1, 2024

@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];
}

from acedrawingview.

kiserrolls avatar kiserrolls commented on July 1, 2024

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.

from acedrawingview.

a363211861 avatar a363211861 commented on July 1, 2024

I encountered this problem,I changed line 121(in the ACEDrawingView) to [self.image drawInRect:self.bounds]. it's ok....

from acedrawingview.

Shivaseachange avatar Shivaseachange commented on July 1, 2024

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

from acedrawingview.

Shivaseachange avatar Shivaseachange commented on July 1, 2024

i resolved these....i want to zoom these editing image.help me

from acedrawingview.

acerbetti avatar acerbetti commented on July 1, 2024

@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

from acedrawingview.

viveksoniji avatar viveksoniji commented on July 1, 2024

@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 ?

from acedrawingview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.