Brother Xiaolong’s WeChat mini program is equivalent to 6 in the IE world in the initial stage. Here I will tell you a pit that I just took to.
Photo API.
({ count: 1, // Default 9 sizeType: ['original', 'compressed'], // You can specify whether it is an original or a compressed image, and both are default sourceType: ['album', 'camera'], // You can specify whether the source is an album or a camera, and both are default success: function (res) { // Return the local file path list of the selected photo. TempFilePath can display pictures as the src attribute of the img tag. var tempFilePaths = ; } });
In the above, we clearly give the type of size. We wanted to save trouble, but it was useless...
Let’s talk less nonsense, let me tell you the difference between IOS and Android, and the pitfalls of photo compression.
// Click to take a photo takePictures:function(){ var that = this; ({ count: 1, // Default 9 sizeType: ['compressed'], // You can specify whether it is an original or a compressed image, and both are default sourceType: ['camera'], // You can specify whether the source is an album or a camera, and both are default success: function (res) { // Return the local file path list of the selected photo. TempFilePath can display pictures as the src attribute of the img tag. var tempFilePaths = ; ({ attendSuccessImg:tempFilePaths[0] }); // Upload pictures //Judge the model var model = ""; ({ success:function(res){ model= ; } }) if(("iPhone") <= 0){ (); (111111) }else{ drawCanvas(); } // Zoom the picture function drawCanvas(){ const ctx = ('attendCanvasId'); (tempFilePaths[0], 0, 0, 94, 96); (); (); } } }); }, // Generate pictures prodImageOpt:function(){ var that = this; ({ canvasId: 'attendCanvasId', success: function success(res) { ({ canvasImgUrl: }); // Upload pictures (); }, complete: function complete(e) { } }); },
After clicking to take a photo, IOS performed the image compression function. However, Android still has such a large size, so in this process, we need to judge the current model and then perform canvas compression.
The above code is ready to be used, but a canvas tag is needed to add a small part of the wxml.
Make interface calls. Hope it will be helpful to everyone.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.