mushanshitiancai / vscode-paste-image

paste image from clipboard to markdown/asciidoc directly!
MIT License
423 stars 128 forks source link

Unable to paste images on win10 #12

Closed elbehery95 closed 7 years ago

elbehery95 commented 7 years ago

In settings i am setting the path property to "pasteImage.path": "${currentFileDir}\\assets" However when i enter the paste command, the "assets" folder is created but the image is not.

image GIF link

mushanshitiancai commented 7 years ago

Hello, I try it in my windows 10, and it's ok

mushanshitiancai commented 7 years ago

You can do a test. First save this powershell script to a file named "ps.pc1":

param($imagePath)

# Adapted from https://github.com/octan3/img-clipboard-dump/blob/master/dump-clipboard-png.ps1

Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()

if ($img -eq $null) {
    "no image"
    Exit 1
}

if (-not $imagePath) {
    "no image"
    Exit 1
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$stream = [IO.File]::Open($imagePath, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb)) | out-null
$encoder.Save($stream) | out-null
$stream.Dispose() | out-null

$imagePath

And then you copy a image, open a powershell window, run this script: powershell -f ps.pc1 "D:\\test.png", observe the output.

elbehery95 commented 7 years ago

image

It just prints out the argument given. And image is created at the given location

elbehery95 commented 7 years ago

I have found the issue;

image

It turns out that if powershell is not added into the system environmental variables the code required for paste will throw an exception since it is not able to launch the powershell script

image

I am doing a pull request to fix this issue. Adding the full powershell path into the variable powershell should fix this problem in case users dont have powershell.exe added to system env. vars

image

mushanshitiancai commented 7 years ago

Very very thank you for you experiment!

I update plugin, fix this bug and enhance the log system. You can try it.