Let Delta Chat indirectly support the clipboard and paste images from other programs

Indirectly allows Delta Chat to support pasting clipboard pictures from other programs

This method is only available for Windows desktop version.

  1. 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"
  1. Visit CopyQ to download CopyQ;
  2. Start after the download is complete, press F6 in the CopyQ window;
    {C6ACF59E-CABC-B5CF-232E-2B476B81ED15}
  3. Click “Add”, then double-click “New command”;
    {BF18F123-09D5-2A74-6609-E477047EDCCD}
  4. Click “Automatic” on the right;
    {D7381CC8-6A81-784C-52AC-8C943519479F}
  5. Paste the following command:
copyq:
execute('powershell','-STA','-File','<ps1path>')
  1. Modify the above command and replace <ps1path> with the actual script path (the backslash in the path needs to be written twice);
    {C0D91097-6CE4-04B5-6446-411E0BE8D43A}
  2. Rename this command and click “Apply”;
    {FDC25428-7FB3-5DBF-EC18-6A235B3CEB19}
  3. Now you can try to copy a picture from a browser and other programs and paste it into Delta Chat.

Attentions:

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

2 Likes

Is this what I think it is? I can just copy an image from say Signal or Telegram or wherever on the web to my clipboard and just CTRL + V into the input field in Delta and it’ll auto attach inline the image? Or does it add as attachment?

Cool!

This article has expired, please update to 1.22.x.

1 Like

it adds it as attachment