MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 208 forks source link

Add pasteImage API to handle paste image #138

Open hfcorriez opened 9 years ago

hfcorriez commented 9 years ago

The API will return BASE64 string format of Image. You can add "data:image/png;base64," prefix and set to src attribute, it will be shown as html5 data uri image.

If you want to mock a html5 File Object to upload or do some other things. There is the code:

var imgData = window.macgap.clipboard.pasteImage();
if (!imgData) return;
var byteString = window.atob(imgData);
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
  ia[i] = byteString.charCodeAt(i);
}
var file = new Blob([ia], {type: 'image/png', encoding: 'utf-8'});
hfcorriez commented 9 years ago

@ifavo This is the PR you want.