iLogic - save Image from windows clipboard to folder

iLogic - save Image from windows clipboard to folder

Curtis_Waguespack
Consultant Consultant
951 Views
4 Replies
Message 1 of 5

iLogic - save Image from windows clipboard to folder

Curtis_Waguespack
Consultant
Consultant

Hello everyone, 

 

Does anyone have a working example of a bit of code that takes the image that is currently on the windows clipboard and saves it to a folder on disk?

 

I'm looking to do this from an iLogic rule.

 

The example does not need to create the picture, it just needs to access the image from whatever is already on the Windows clipboard, seems like it should be pretty easy, but the couple of things I've tried in the past did not work.

 

Thanks in advance!

Curtis

 

EESignature

0 Likes
Accepted solutions (1)
952 Views
4 Replies
Replies (4)
Message 2 of 5

GeorgK
Advisor
Advisor

Hello Curtis,

 

this is VB.net

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
            Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
            If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
                Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
                'To Save as Bitmap
                oImgObj.Save("c:\Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
                'To Save as Jpeg
                oImgObj.Save("c:\Test.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
                'To Save as Gif
                oImgObj.Save("c:\Test.gif", System.Drawing.Imaging.ImageFormat.Gif)
            End If
        End If
    End Sub
Message 3 of 5

Curtis_Waguespack
Consultant
Consultant

Hi @GeorgK 

 

Thanks for the reply. 

 

I recall trying that example, but not being able to work out how to get it to run from an iLogic rule, I'll try to look again if i have time to see what the specifics were ... but the goal here is to incorporate this into an existing iLogic rule. 

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 4 of 5

MjDeck
Autodesk
Autodesk
Accepted solution

Hi Curtis,

Here's a sample rule. Make sure the directory named "C:\Temp" exists before running it.

AddReference "System.Drawing"
Imports System.Drawing
Imports System.Windows.Forms

If Clipboard.ContainsImage() Then
	Clipboard.GetImage.Save("C:\Temp\ClipboardSample.png", Imaging.ImageFormat.Png)
	'Clipboard.GetImage.Save("C:\Temp\ClipboardSample.jpg", Imaging.ImageFormat.Jpeg)
End If

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 5

Curtis_Waguespack
Consultant
Consultant

Thanks Mike!

 

It must have been the AddReference line that I wasn't getting, the rest of it looks like what I'd tried.

 

Thanks again!

Curtis

EESignature

0 Likes