0
這裏是C#的方法和js函數:的getContext(2D)的drawImage> toDataURL> undefiend問題
public static string JsGetImgBase64String(Awesomium.Windows.Forms.WebControl wb, string getElementQuery, bool leaveOnlyBase64Data = true)
{
string data = wb.ExecuteJavascriptWithResult(@"
function getImgBase64String(img)
{
alert(img.attr('src'));
var cnv = document.createElement('CANVAS');
var ctx = cnv.getContext('2d');
ctx.drawImage(img, 0, 0);
return cnv.toDataURL();
}
" + String.Format("getImgBase64String({0});", getElementQuery));
if (data == "undefined")
return string.Empty;
if (leaveOnlyBase64Data && data.Contains(","))
{
data = data.Substring(data.IndexOf(",") + 1);
}
return data;
}
這裏是圖像:
@"$(""img[src$='/Appointment/ShowCaptchaImage']"")"
下面是警報結果:/Appointment/ShowCaptchaImage
這裏是該函數的結果(無錯誤):The return value of that function is undefiend
。
現在是什麼問題?
如何修復undefiend
使用jquery或javascript的問題?
這是該方法的C#調用?
string imgBase64 = JsGetImgBase64String(webControl_1, @"$(""img[src$='/Appointment/ShowCaptchaImage']"")");
byte[] imgBytes = Convert.FromBase64String(imgBase64);
我在byte[] imgBytes =
上有錯誤!
這裏是相關的線程:https://stackoverflow.com/questions/31654964/awesomium-how-save-a-loaded-image-without-redownload-it – MoonLight