Indirectly allows Delta Chat to support pasting clipboard pictures from other programs
This method is only available for Windows desktop version.
- Create a new PowerShell script in the path you want, with the extension ps1, paste the following code into this file and modify the specified line, save it after the modification is complete;
Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()
if ($img -eq $null) {
Exit
}
# <tmppath> Replace with the actual temporary directory
$tempFileDir="<tmppath>"
$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$filename = (([guid]::NewGuid()) -replace'[-T:]','')
if(-Not (Test-Path $tempFileDir -PathType Container)){
mkdir $tempFileDir
}
$file = "$tempFileDir\{0}.png" -f $filename
Write-Host ("`n Found picture. {0}x{1} pixel. Saving to {2}`n" -f $img.PixelWidth, $img.PixelHeight, $file)
$stream = [IO.File]::Open($file, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb))
$encoder.Save($stream)
$stream.Dispose()
# <copyqpath> Replace with CopyQ's program path
Push-Location "<copyqpath>"
cmd /C ".\copyq.exe copy image/png - < ""$file"""
Pop-Location
del "$file"
- Visit CopyQ to download CopyQ;
- Start after the download is complete, press F6 in the CopyQ window;
- Click “Add”, then double-click “New command”;
- Click “Automatic” on the right;
- Paste the following command:
copyq:
execute('powershell','-STA','-File','<ps1path>')
- Modify the above command and replace <ps1path> with the actual script path (the backslash in the path needs to be written twice);
- Rename this command and click “Apply”;
- Now you can try to copy a picture from a browser and other programs and paste it into Delta Chat.
Attentions:
- PowerShell script execution will be very slow, you can paste the following code into PowerShell and press Enter twice, wait a while.
$Env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
[AppDomain]::CurrentDomain.GetAssemblies() |% {
$pt = $_.Location
if (! $pt) {continue}
if ($cn++) {''}
$na = Split-Path -Leaf $pt
Write-Host -ForegroundColor Yellow "NGENing $na"
ngen install $pt
}
This code can only be improved to a certain extent.
2. This script may be blocked during execution. At this time, execute the following command and press Y + Enter, and then re-execute the script:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
3. During the copy and paste operation, CopyQ must keep running.
The above method is not perfect, the processed script still takes about 1 second.
Still waiting for developers to perfect the paste function for the Windows version.