如何在angularjs应用程序中创建base64编码图像的缩略图

时间:2015-12-04 07:56:23

标签: angularjs google-maps base64 photo

我有一个应用程序,其中的图像来了base64编码字符串,我正在解码它并在谷歌地图上显示,但少数图像只显示图像的一部分,所以我可以创建图像的缩略图和使它更明显可见

enter image description here

图像数据的示例输入:

/9j/4AAQSkZJRgABAQEAeAB4AAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCABOAE4DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD6Rs7owrHIvJaMA+gNbOmXPOX+bI5B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sOVkk65y2wDAGGyceTXnjzXPidrd5feKtV/tzXL5VF3ei2jtxKVUIuI4wFVVVVUAdgCcnJPzDffNE83/AD7yRXAB7lSOPyr6Q0TTfs+uxyBuJEWTHsc8fpXzucVHypH02TYeEJuR0/wX+Gtn/wAJxD/aGm299BIQn7yMOSCc45Hb0Nffnwm+E2j6LbQtY6bZ2Uf3j5dsiYGPYV8q/BvQvL1aKRWUb1DdO1fWHhjxa1vo0cSqwyAnWvz3MMROUrXP0LAU6cI7B8ef2j/Fn7Lnw/1Lxn4Gns7TVdFiLlbm2W4iuLfIMqsp/wBkbsjkbRjHUenfsK/8HB3gT4v22n6H8Vvs/gPxVI/7vUbWB/7CuIHH7uSRmkeS2beGRg+6MFQ3mKG2r8c/8FKvia3gf9nDVII4WkutcC6crbvliDkl2P8AwEMMD1r8+bXV5LDxVosan5bq2NlxwRnDhvwYg19nwmpfVHfa+h8dxPGFTE6b2P60PhL8YvDvxq8IW+ueE/EGh+K9Fkl8gahpF9He25kBBK74yRuGRlc5GRkc12xnDbdv8S7uDX8ovwD/AG5vid+xX8Qm1n4e+LNY8Ox6oqG/tLWVWtb4g5Qy28ivDIVJOC6MQCQMAmvtL4G/8HK3xt8AW1xb+JdP8N/EAMoMUmpWaWM0Bz2azESFcdmjJ/2hjB+r5T5GWHkj/9k=

我正在解码

 var iconResize = new google.maps.MarkerImage(
          "data:image/png;base64,"+data.Photo, //url
          new google.maps.Size(70, 70)//size
        );

请说明如何进行

2 个答案:

答案 0 :(得分:1)

为了缩放图像,需要明确指定scaledSize对象的google.maps.MarkerImage属性,例如:

 var icon = new google.maps.MarkerImage();
 icon.size = new google.maps.Size(128, 128);
 icon.scaledSize = new google.maps.Size(128, 128);
 icon.url = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/...";

Working example

答案 1 :(得分:0)

  var iconScaling = function (base64) {
        return {
            url: base64,
            scaledSize: new google.maps.Size(50, 50),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(0, 0)
        };
    };

    var createMarker = function (info) {

        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(info.Lat, info.Lon),
            map: $scope.map,
            animation: google.maps.Animation.NONE
        });

        marker.setIcon(iconScaling(info.icon_name));

/////----//////
 createMarker({ Lat: value.LocationDetails.Lat, Lon: value.LocationDetails.Lon, icon_name: 'data:image/jpeg;base64,' + value.CustomerInfo.Photo, CustomerID: key });