Visio Guy

Visio Discussions => General Visio => Topic started by: Jennifer on May 07, 2023, 04:52:32 PM

Title: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 07, 2023, 04:52:32 PM
I know Visio can trace the outline of an object in an image using the Arc, Freeform, and Pencil tools. I have used it before so I could calculate the area of an irregular shape. But can it cut irregular shapes out of a photo like shown in this video about Photoshop?

https://www.youtube.com/watch?v=VsSjXNOE7NM

Perhaps I was not using these tools correctly, but it was much more difficult to get as close to the edges as the guy does in that video. Is there an similar online tutorial for Visio?
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 07, 2023, 08:29:16 PM
Not sure I totally understand the question. 

Visio will not do a cutout.  That is most easily done in a photoediting app.  So, if that's the question, answer is no.

Visio will draw.  Which as you know, allows you to make outlines of a shape.  Is there a tutorial?  Not that I'm aware of.  The video makes some good points...didn't watch all of it...and Visio can do most/all, except cut. 

I found the drawing tools work well.  You can almost use line and pencil tools exclusively.  Basically, draw a line between two points on a curve, add an inflection point as needed, and drag it to trace the shape.  Add inflection points to refine the curve.  Repeat as you proceed around the shape.  The curve tool is handy for simple curves, but, line and pencil work equally well.  I RARELY use the free form tool.  It is too detailed.  My preference.

For example of complex tracing, see http://visguy.com/vgforum/index.php?topic=586.msg2496#msg2496 (http://visguy.com/vgforum/index.php?topic=586.msg2496#msg2496).
The two  instrument shapes were tracing based on pix of the guitar and bass.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 07, 2023, 08:59:48 PM
Another trip back in time...
Saw this 2014 post you made, http://visguy.com/vgforum/index.php?topic=6194.msg25243#msg25243 (http://visguy.com/vgforum/index.php?topic=6194.msg25243#msg25243).  That piqued my curiousity.  So, I agree, with newer versions of Visio, it is NOT as easy as it was, and, as i'm using 2019, either the change seems to be here.

But, all is not lost.  The arc tool is usable.  It may be necessary to zoom in on the inflection point and use pencil tool to grab the curve deflection points. 
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 07, 2023, 09:52:35 PM
Quote from: wapperdude on May 07, 2023, 08:29:16 PM
Not sure I totally understand the question. 

Visio will not do a cutout.  That is most easily done in a photoediting app.  So, if that's the question, answer is no.

Doing a cutout in the whole point, so I guess Visio is out. Seems like a fairly simple feature to add.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: vojo on May 08, 2023, 01:44:16 PM
1)  Open a new page
2)  copy your group of shapes
3)  paste special in a new page as bit map or whatever
4) draw a line over the image where you want to cut (straight like or a path)
5) select the image and line
6) Goto drawing operations in developer mode and select fragment
7) take the part you want and use it

Note this results in a static bit map image..not visio editable set of shapes.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 08, 2023, 03:06:46 PM
The problem with fragment is that is destroys the contents. Here's a quick demo.

(https://i.postimg.cc/d34tq5LC/image.png)

Is there any way to do the fragment and preserve the image? If so, that might just solve my problem.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 08, 2023, 03:25:46 PM
Not that I'm aware of. 

Visio does not preserve content of imported image file after fragment operation..or most (all?) similar operations that involve filled content.  If it is possible, I'd like to know too.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 08, 2023, 03:47:01 PM
Did google search for photo to jigsaw... quite a few options. 

NOT tried any. 

This looks interesting from price standpoint:  https://www.epuzzle.info/en/puzzle-from-photo (https://www.epuzzle.info/en/puzzle-from-photo)
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 08, 2023, 04:06:11 PM
Quote from: wapperdude on May 08, 2023, 03:25:46 PM
Not that I'm aware of. 

Visio does not preserve content of imported image file after fragment operation..or most (all?) similar operations that involve filled content.  If it is possible, I'd like to know too.

When I was creating that example above, I first tried it with a filled shape. Fragment sorta preserves the content there. 🤨🤔🙄

(https://i.postimg.cc/4355cNJV/image.png)

That would not work for what I need.

I'd like to know what the (il)logic is behind the current Fragment behavior. Makes no sense to me.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 08, 2023, 06:28:13 PM
That result is unexpected.  That is not a "true" fragment.   What this looks like the original shape had a radial fill pattern and when it was fragmented, each piece retained the full radial fill definition.  That actually makes some sense, from a simple implementation perspective.  That is, the shape had as its fill a centered, radial pattern. So, each fragment gets that same definition, including all the coloring characteristics.  Not treated as bitmap slice and dice.  Definitely not useful for jigsaw puzzle design.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 08, 2023, 06:55:35 PM
Quote from: wapperdude on May 08, 2023, 06:28:13 PM
That result is unexpected.  That is not a "true" fragment.   What this looks like the original shape had a radial fill pattern and when it was fragmented, each piece retained the full radial fill definition.  That actually makes some sense, from a simple implementation perspective.  That is, the shape had as its fill a centered, radial pattern. So, each fragment gets that same definition, including all the coloring characteristics.  Not treated as bitmap slice and dice.  Definitely not useful for jigsaw puzzle design.

Yup. When I converted the image to an external image, Fragent killed the image.

(https://i.postimg.cc/FRQmDN5G/image.png)
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: vojo on May 09, 2023, 12:52:10 AM
I guess you copy and paste as an image  and use cropping to do what you want
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 09, 2023, 11:13:28 PM
You can do the desired type of fragmenting in Power Point.  For a demonstration, see this video:  https://m.youtube.com/watch?v=d-Ij3ZtIxHU (https://m.youtube.com/watch?v=d-Ij3ZtIxHU).
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 10, 2023, 12:37:03 AM
Quote from: wapperdude on May 09, 2023, 11:13:28 PM
You can do the desired type of fragmenting in Power Point.  For a demonstration, see this video:  https://m.youtube.com/watch?v=d-Ij3ZtIxHU (https://m.youtube.com/watch?v=d-Ij3ZtIxHU).

Ok, thanks. I'll check it out.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 10, 2023, 12:38:03 AM
Quote from: wapperdude on May 08, 2023, 03:47:01 PM
Did google search for photo to jigsaw... quite a few options. 

NOT tried any. 

This looks interesting from price standpoint:  https://www.epuzzle.info/en/puzzle-from-photo (https://www.epuzzle.info/en/puzzle-from-photo)

Ok, thanks
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 10, 2023, 04:44:17 PM
Just a followup...here's link to Affinity Designer 2 showing cutting (fragment):  https://affinity.help/designer2/English.lproj/index.html?page=pages/ObjectControl/cutting.html?title=Cutting%20objects (https://affinity.help/designer2/English.lproj/index.html?page=pages/ObjectControl/cutting.html?title=Cutting%20objects)

Less expensive than Photoshop I believe.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 10, 2023, 05:38:41 PM
Quote from: wapperdude on May 10, 2023, 04:44:17 PM
Just a followup...here's link to Affinity Designer 2 showing cutting (fragment):  https://affinity.help/designer2/English.lproj/index.html?page=pages/ObjectControl/cutting.html?title=Cutting%20objects (https://affinity.help/designer2/English.lproj/index.html?page=pages/ObjectControl/cutting.html?title=Cutting%20objects)

Less expensive than Photoshop I believe.

Thank you
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 10, 2023, 08:50:29 PM
To be honest I wouldn't know how to do it in Photoshop.

But here is a solution in Visio.

Key is the cell "ClippingPath". It allows to define an outer curve for an image shape.
https://learn.microsoft.com/en-us/office/client-developer/visio/clippingpath-cell-foreign-image-info-section (https://learn.microsoft.com/en-us/office/client-developer/visio/clippingpath-cell-foreign-image-info-section)

With a little automation you can select the image shape, then the jigsaw shapes.
Then the macro copies the geometry section of each jigsaw shape into a copy of the image shape and assigns the clippingPath cell to the newly imported geometry section.
Done.


Option Explicit

Private Sub cmProcess_Click()
  Dim frameShp As Shape
  Dim frameShp2 As Shape
  Dim picShp As Shape
  Dim picShp2 As Shape
  Dim JSshp As Shape
  Dim JSshp2 As Shape
  Dim JSshp3 As Shape
  Dim sel As Selection
 
  Dim arShpIDs As Variant
  Dim vShpID As Variant
 
  Dim x1 As Double
  Dim y1 As Double
  Dim x2 As Double
  Dim y2 As Double
 
  Set picShp = ActivePage.Shapes.ItemFromID(tPic.Value)
  getExtends picShp, x1, y1, x2, y2
  Set frameShp = ActivePage.DrawRectangle(x1, y1, x2, y2)
 
  arShpIDs = Split(tShapes.Value, ";")
  For Each vShpID In arShpIDs
    Set JSshp = ActivePage.Shapes.ItemFromID(vShpID)
    Set JSshp2 = duplicateInPlace(JSshp, "JigSawShape2")
    Set frameShp2 = duplicateInPlace(frameShp, "Frame2")
    Set picShp2 = duplicateInPlace(picShp, "PicShape2")
   
    ActiveWindow.DeselectAll
    ActiveWindow.Select frameShp2, visSelect
    ActiveWindow.Select JSshp2, visSelect
    ActiveWindow.Selection.Join
    Set JSshp3 = ActivePage.Shapes.Item(ActivePage.Shapes.Count)
    JSshp3.Name = "JigSawShape3"
   
    picShp2.AddSection visSectionFirstComponent + 1
    picShp2.AddRow visSectionFirstComponent + 1, visRowComponent, visTagComponent
   
    Dim row_ As Integer
    Dim col_ As Integer
    Dim rowType_ As Integer
    For row_ = 1 To JSshp3.RowCount(visSectionFirstComponent)
      rowType_ = JSshp3.rowType(visSectionFirstComponent, row_)
      picShp2.AddRow visSectionFirstComponent + 1, row_, rowType_
      For col_ = 0 To JSshp3.RowsCellCount(visSectionFirstComponent, row_) - 1
        picShp2.CellsSRC(visSectionFirstComponent + 1, row_, col_).Formula = JSshp3.CellsSRC(visSectionFirstComponent, row_, col_).Formula
      Next col_
    Next row_
   
    picShp2.Cells("ClippingPath").Formula = Chr(34) & "Geometry2.path" & Chr(34)
    picShp2.Cells("pinx").Formula = picShp2.Cells("pinx").ResultIU + picShp2.Cells("width").ResultIU + 2
    JSshp3.Delete
   
  Next vShpID
  frameShp.Delete
End Sub

Function duplicateInPlace(shp As Shape, Optional ShapeName As Variant) As Shape
  Dim shp2 As Shape
  Set shp2 = shp.Duplicate
  shp2.Cells("pinx").Formula = shp.Cells("pinx").ResultIU
  shp2.Cells("piny").Formula = shp.Cells("piny").ResultIU
  If Not IsMissing(ShapeName) Then
    shp2.Name = ShapeName
  End If
  Set duplicateInPlace = shp2
End Function

Private Sub cmSelPic_Click()
  If ActiveWindow.Selection.Count <> 1 Then
    MsgBox "Please select one picture shape.", vbOKOnly
    Exit Sub
  End If
  tPic.Value = ActiveWindow.Selection(1).ID
End Sub

Private Sub cmSelShapes_Click()
  Dim shp As Shape
  Dim temp As String
  For Each shp In ActiveWindow.Selection
    temp = temp & shp.ID & ";"
  Next shp
  If Right(temp, 1) = ";" Then
    temp = Left(temp, Len(temp) - 1)
  End If
  tShapes.Value = temp
End Sub

Sub getExtends(ByRef shp As Shape, ByRef x1 As Double, ByRef y1 As Double, ByRef x2 As Double, ByRef y2 As Double)
  x1 = shp.Cells("pinx").ResultIU - shp.Cells("locpinx").ResultIU
  x2 = x1 + shp.Cells("width").ResultIU
  y1 = shp.Cells("piny").ResultIU - shp.Cells("locpiny").ResultIU
  y2 = y1 + shp.Cells("height").ResultIU
End Sub


Downside, each new jigsaw shape has the size of the original shape. Got stuck on this one. May one of the peer members help?
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 10, 2023, 08:51:39 PM
And here the stencil with the macro.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 10, 2023, 08:58:25 PM
Quote from: Yacine on May 10, 2023, 08:51:39 PM
And here the stencil with the macro.

Wow! That will take me a bit of time to get my head around...

Thanks
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 10, 2023, 09:04:44 PM
Quote from: Jennifer on May 10, 2023, 08:58:25 PM
Wow! That will take me a bit of time to get my head around...

No need to get your head around it.
Just start the form in the stencil (Open the VB editor and run the form).

Note - The jigsaw pieces must be placed on top of the image in order to work properly and at the right place.
Place you image, create the jigsaw pieces, move them over the image.
Start the form, select the image shape, click on first button to get its ID, then select all the jigsaw pieces, press the second button, then the 3rd one ("process").
The image shape may be hidden by all the jigsaw shapes. You can move one those shapes to the side to select the image, then move the jigsaw shape back to its position. Alternatively remove the fillings of the jigsaw shapes.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 10, 2023, 10:57:07 PM
Quote from: Yacine on May 10, 2023, 09:04:44 PM
No need to get your head around it.
Just start the form in the stencil (Open the VB editor and run the form).

Ok, thanks
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Visisthebest on May 11, 2023, 10:58:41 AM
Can't this be solved with a bit of VBA?
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 11, 2023, 11:07:41 AM
Quote from: Visisthebest on May 11, 2023, 10:58:41 AM
Can't this be solved with a bit of VBA?

Do you mean cutting out pieces? If there is a VBA solution, I would love to know what it is. I don't have a clue as to how to do it.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 11, 2023, 05:55:10 PM
@Yacine:  not sure I get the point.

The OP wants to take a picture, foreign object if you will, and slice it to make a puzzle.  Very simple objective.  Visio, out-of-the-box, won't do that. 

I admit, I haven't tried your code, but your comment about "original size" was, discouraging, unless I misunderstand. 
PowerPoint and other non-stop programs appear to have solutions.  Unfort, my version of PPt, is lacking key feature shown in videos, so I cannot verify.  Nonetheless, all videos seem to indicate fairly straight forward, built-in solutions.

Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 11, 2023, 07:45:59 PM
@Wapperdude
My sad face palm picture was because of Visisthebest's suggestion to use VBA without having read that I posted already such a solution. Anyway - we are nice people here, so I deleted it.

Regarding my solution, it is indeed not perfect yet. The cut shape looks as needed, but its boundaries are those of the big image.
That is why I asked whether someone else could have a look.
Please have a try.

Meanwhile a muse came flying by. I will try to crop the image first, without relying on the helper rectangle.

Rgds,
Y.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 11, 2023, 07:51:11 PM
Quote from: wapperdude on May 11, 2023, 05:55:10 PM
Visio, out-of-the-box, won't do that.

And that's where Visio shines, why I love it so much. Having the possibility to implement a feature, that wasn't planed, one that belongs to another software group.
Awesome!
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: wapperdude on May 11, 2023, 08:31:17 PM
LOL.

I get the obvious point.  Most of us have either witnessed it, even victim of it, or even guilty of it.  I speak from experience.    Many times, more than a forehead slap comes to mind as an appropriate response.  "My tongue is numb!"
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 11, 2023, 10:10:57 PM
Cropping the image before assigning the ClippingPath worked fine.


PROBLEM: The clipping path seems to have issues with complicated NURBS rows. I don't know how to fix it.
You can compare the geometry sections of the original and the new shape. No difference, but other appearance.
So the tool is obviously limited to simpler shapes. Sorry.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 11, 2023, 10:11:17 PM
And here the drawing and the updated stencil.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Visisthebest on May 12, 2023, 10:15:31 AM
Yes sorry Yacine I did not read the entire forum thread through responded too quickly.
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Yacine on May 12, 2023, 11:43:38 AM
No, I'm sorry.  ;D
Title: Re: Can Visio cut shapes from images like Photoshop?
Post by: Jennifer on May 20, 2023, 07:25:39 AM
After some fiddling around, I came up with a sorta solution:


Here's an example with one of our puzzles. This puzzle has a lot more sihouettes. I just did 4 because the process is kind painful.

(https://i.postimg.cc/gkVMxgg3/image.png)

All in all, it's not bad. And it's a lot cheaper than Photoshop. 👍😀

Comments?