【发布时间】:2016-06-14 13:26:57
【问题描述】:
我有一个使用 myView.toImage() 的简单 Android 应用程序
正如预期的那样,这将返回一个 blob,太棒了!
然后我可以将此 blob 编码为 base64,并在应用程序中通过将解码后的字符串加载到 ImageView 中进行测试解码,从而完美地呈现图像。
但是在 php 中解码这个字符串时,base64 字符串有两个问题: 首先,字符串长度并不总是 4 的倍数,即没有添加填充,其次,当手动添加填充时,图像总是空白。
在按钮对象上使用相同的代码但是效果很好,这似乎只在对 Ti.View 对象使用 toImage() 方法时发生
工作代码(生成良好的 base64 字符串)
myButton.toImage(toImageComplete);
function toImageComplete(blob){
Ti.API.info("To image complete" + blob);
var sigBase64 = Ti.Utils.base64encode(blob);
Ti.API.info(sigBase64);
}
无效代码(生成错误的 base64 字符串),注意唯一的变化是调用 toImage 的对象现在是 Ti.UI.View 的实例,而不是 Ti.UI.Button
myView.toImage(toImageComplete);
function toImageComplete(blob){
Ti.API.info("To image complete" + blob);
var sigBase64 = Ti.Utils.base64encode(blob);
Ti.API.info(sigBase64);
}
Appcelerator Studio 4.6 SDK 5.3.0GA 编译成安卓平板和Genymotion模拟器
【问题讨论】:
标签: android appcelerator appcelerator-titanium appcelerator-alloy appcelerator-studio