supershowwei / ImgurUploader-MarkdownMonster-Addin

6 stars 4 forks source link

Fix project references and Simplify and Enhance Image Upload #2

Closed RickStrahl closed 6 years ago

RickStrahl commented 6 years ago
supershowwei commented 6 years ago

Actually i can not copy and paste image from Paint or Snagit using Clipboard.GetImage() directly in my case.

I referenced this post https://www.thomaslevesque.com/2009/02/05/wpf-paste-an-image-from-the-clipboard/ and created the ClipboardImageHelper to get a BitmapFrame then my problem was disappeared.

Using Clipboard.GetImage() directly to get a BitmapFrame is works to you ?

RickStrahl commented 6 years ago

Hmmm... yes something isn't working quite right - I'll take another look.

This should work - it was working in fact (i used copied images from Chrome). The reason I think this is a better approach is that the raw clipboard data doesn't maintain transparency which is going to get you a lot of bad image results - especially now when you can't preview to see what you're actually uploading.

Also - Clipboard doesn't work if you're cutting and pasting across user boundaries - if you have one admin process and a user process the WPF clipboard won't allow the data (or drag and drop from the shell either).

However, I use that same method in both the Paste Image dialog and image pasting into the editor in general as well as the Save Image to Asuzre Blob addin and it works well. So the concept is sound but I must have mucked something up in the code.

FWIW - I think it's also bad form to paste and immediately upload the image. I think you should show the image on the form and then upload it. No sense uploading if you pasting the wrong thing.

I suggest you take a look at the Azure Image addin which is pretty much the same feature set with a different service. In fact you can use pretty much the entire UI and just replace the security and actual uploading code.

https://github.com/RickStrahl/SaveToAzureBlob-MarkdownMonster-Addin

I'll take a look later and see why the upload is pulling a blank object (it's getting hte size).

supershowwei commented 6 years ago

This addin started from my needs, and my scenario is I will paste image from clipboard to the image editor (Paint or Snagit), draw some lines, write some comments, save it to storage, and then upload to imgur.

The original idea is only selecting the picture file, and then uploading. But I think that is better if i can directly uploading from clipboard, so i just add the feature.

In my context, I almost do not need to preview the image, because I've done it in the image editor.

That is really worth to think well. Before that, I would prefer to removing the feature than owning it, because it is unessential, just nice to have.

RickStrahl commented 6 years ago

So I fixed the image buffer upload - the code didn't flush the buffer before uploading which resulted in empty images.

I get that you want to keep this simple, but I think Image preview is kind of a must for use outside of your own. Just so you don't upload a bunch of garbage by accident. For me - often times the clipboard holds stuff that I didn't think it should, because I didn't actually capture the snagit image (because snagit is a bit wonky that way) or I've in the meantime pasted something else.

If you want to add this to the Addin registry I think this feature is a requirement, also for consistency's sake with all the other image pasting features in MM (the paste image dialog the Save To Azure Addin).

I can add this if you like - as I said most of the code for this is already in the Save To Azure addin and adding a preview is pretty straight forward. I think the hardest part is getting the image resizing right.

For the moment this patch doesn't change anything from your original behavior it only replaces with simpler image copying that supports transparency and consolidates the configuration settings into a single config file in the standard expected location.

supershowwei commented 6 years ago

Excellent and thank you very much.

I will add image previewer later.

supershowwei commented 6 years ago

After testing, the problem still appears in my context, i decide to remove the feature for avoiding user as same as me use imperfect feature.

But, it doesn't dampen my enthusiasm that share ImgurUploader addin to users who use MarkdownMonster.

The addin still be the handiest tool that you wnat to upload a image to imgur on MarkdownMonster.

Thanks your pr very much.

RickStrahl commented 6 years ago

Fair enough.

Still curious what exactly doesn't work. When you step into that code what actually happens when you get a paste operation?

Could it just be the fact that CTRL-V handler is very unreliable in capturing the keystroke in the first place? I changed that code out because it was unreliable but it might even be worse now. Did you try pasting using the button in the toolbar instead?

I've added another patch and replaced the Ctrl-V handling (which didn't really work reliably for me at any point), with a command on the window and the file textbox.