Just for fun with graphics

Hi everyone, wherever you are!

I’ve been working on Windows platform with a simple project that grabs image data from the clipboard and passes it to a dialog box image control.

Private oDlg As Object
Private oImg As Object
Private ImgPath As String
Private AltDown As Boolean

Sub ShowDialog
	
    DialogLibraries.LoadLibrary("Standard")
    oDlg = CreateUnoDialog(DialogLibraries.Standard.ClipDlg)
	
    Dim oSize As New com.sun.star.awt.Size, factor As Double
    Dim oCC, oComponentWindow, oTopWindowPosSize
    oCC = ThisComponent.getCurrentController()
    oComponentWindow = oCC.ComponentWindow
    
    With oComponentWindow
        oWindowPosSize	= .getPosSize()
        oToolKitWorkArea = .Toolkit.WorkArea
        oTopWindowPosSize = .Toolkit.ActiveTopWindow.getPosSize()
    End With
    
    With oSize
        .Width	=	oDlg.Model.Width
        .Height	 =	oDlg.Model.Height
    End With 

    factor = oSize.Width/oDlg.convertSizeToPixel(oSize, com.sun.star.util.MeasureUnit.APPFONT).Width
	
    With oDlg.Model
        .PositionX=(factor*oTopWindowPosSize.Width - .Width) / 2
        .PositionY=(factor*oTopWindowPosSize.Height - .Height) / 2
    End With

    factor = oSize.Width /    oDlg.convertSizeToPixel(oSize, com.sun.star.util.MeasureUnit.APPFONT).Width
	
    With oDlg.Model
        .PositionX=(factor*oTopWindowPosSize.Width - .Width) / 2
        .PositionY=(factor*oTopWindowPosSize.Height - .Height) / 2
    End With
    
    oImg=oDlg.getControl("ImageControl1")
	
    oDlg.Execute()
    oDlg.dispose()

End Sub
	
Sub TopListen_WindowClosing
    ThisComponent.setModified(False)
End Sub
Sub  TopListen_windowOpened
End Sub
Sub  TopListen_windowClosed
End Sub
Sub TopListen_windowMinimized
End Sub
Sub  TopListen_windowNormalized
End Sub
Sub  TopListen_windowActivated
End Sub
Sub  TopListen_windowDeactivated
End Sub
Sub  TopListen_disposing
End Sub


Sub GetImageFromClipBoard()

    Dim oClip As Object, oClipContents As Object, oTypes As Object, i%
    Dim oStream As Object
    Dim sText As String
	
    oClip = createUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
    oClipContents = oClip.getContents
    On Error Resume Next
    oTypes = oClipContents.getTransferDataFlavors
	
    If Err <> 0 Then
        Reset : Exit Sub
    End If

For i = LBound(oTypes) To UBound(oTypes)
    
        'MsgBox "MIME-TYPE: " & oTypes(i).MimeType
        If oTypes(i).MimeType = "application/x-openoffice-file;windows_formatname=""FileNameW""" Then
        
        	
            ImgPath = oClipContents.getTransferData(oTypes(i))
            'Of course you could do like this but it's not the idea now	
            'oImg.Model.ImageUrl = ConvertToUrl(ImgPath) 
			
            If EndsWith(LCase(ImgPath), ".jpg") Or EndsWith(LCase(ImgPath), ".jpeg") _
            Or EndsWith(LCase(ImgPath), ".png") Or EndsWith(LCase(ImgPath), ".gif") _
            Or EndsWith(LCase(ImgPath), ".svg") Or EndsWith(LCase(ImgPath), ".tif") _
            Or EndsWith(LCase(ImgPath), ".tiff") Or EndsWith(LCase(ImgPath), ".webp") Then
                isPic = True
            End If
           
		End If
				
		If isPic And oTypes(i).MimeType = "application/x-openoffice-filecontent;windows_formatname=""FileContents""" Then
			oStream = oClipContents.getTransferData(oTypes(i))
			Dim  oInstream As Object
			oInstream=com.sun.star.io.SequenceInputStream.createStreamFromSequence(oStream)
			oStream.CloseInput() : oStream = Nothing
			Dim oProvider As Object
			Dim oObj As Object
			Dim props(0) As New com.sun.star.beans.PropertyValue
			oProvider=createUnoService("com.sun.star.graphic.GraphicProvider")                           
			props(0).Name="InputStream" : props(0).Value = oInstream
			oObj=oProvider.queryGraphic(props)
			oInstream.CloseInput()
			oInstream = Nothing
			oImg=oDlg.getControl("ImageControl1")
			oImg.Model.Graphic=oObj
			oProvider = Nothing
			oObj = Nothing

		End If

        End If

    Next i
    
End Sub


Sub ImgCtlMousUp

    oImg.Model.Graphic = Nothing
    ImgPath = ""
    If Not AltDown Then
        GetImageFromClipBoard
    Else
	'TO DO ... 
	'A routine that grabs the image data from oImg.Model.Graphic object
	'and transfers the data as a Stream to the ClipBoard object
    End If

End Sub

Sub ImgCtlKeyDown(oEvent)

    If oEvent.Modifiers AND com.sun.star.awt.KeyModifier.MOD2 _
    And oEvent.KeyCode = com.sun.star.awt.Key.X Then
        AltDown = True
    End If
	
End Sub

Sub ImgCtlKeyUp(oEvent)
	AltDown = False
End Sub

This no-one-never-needs project works like a charm, but I would like to retrieve the data from a Graphic object and transfer the data back in Stream format to an XTransferable object and further to the clipboard.

Any suggestions?

If the image control is connected to a database field (type BLOB) it is maybe a possible way to copy images into a database. (I usually store only external references like path or url, so I never tried…)

This is not the case, I copy an image file to the clipboard by right-clicking on the image file icon in Windows Explorer and selecting Copy. I have three different systems, to transfer image data to db table OLEObject / LONGVARBINARY fields by using three different systems Dao/ADODB/HSQL, so that’s not what I’m looking for

Here’s the related project
ClipBoardTest.odt (22.3 KB)