Commit ce480af8 by jscat

nyx: 发现

功能更新:
1. 因为iphone不同机型具备不同的缩放因子,充分考虑不同缩放因子下canvas绘制图像的尺寸问题
(因为checkPic过大会报错)
2. 添加springboot上传文件的filesize问题
3. 添加上传延迟,否则上传图片会不完成。
parent 2efbd11a
//app.js //app.js
...@@ -258,8 +258,23 @@ App({ ...@@ -258,8 +258,23 @@ App({
return "s" + str return "s" + str
}, },
saveFile(pic) {
var _this = this;
//保存文件到本地缓存文件
wx.saveFile({
tempFilePath: pic,
success(res) {
//下载的文件路径
const savedFilePath = res.savedFilePath;
console.log("下载图片的参数", res)
}
})
},
//小程序图片检测主函数 //小程序图片检测主函数
checkPic(strUrl, pic, index, resolve, reject) { checkPic(strUrl, pic, index, resolve, reject) {
var _this = this;
console.log("===checkPic_picName: "+pic)
wx.uploadFile({ wx.uploadFile({
url: strUrl, url: strUrl,
filePath: pic, filePath: pic,
...@@ -268,9 +283,10 @@ App({ ...@@ -268,9 +283,10 @@ App({
}, },
name: 'file', name: 'file',
success: function (checkres) { success: function (checkres) {
var checkResult = JSON.parse(checkres.data); var i = index + 1
console.info(checkResult); console.log("\n===第" + i + " 张图片检验过程")
var i = index + 1 console.info(checkres);
var checkResult = JSON.parse(checkres.data);
if (checkResult.data.errcode == '0') { if (checkResult.data.errcode == '0') {
//校验没有违法违规进行自己业务代码处理 //校验没有违法违规进行自己业务代码处理
resolve("第" + i + "张图片状态码_" + checkResult.data.errcode) resolve("第" + i + "张图片状态码_" + checkResult.data.errcode)
...@@ -294,9 +310,10 @@ App({ ...@@ -294,9 +310,10 @@ App({
} }
} }
}, },
fail() { fail: function(e) {
reject("failed on checkPic") var i = index + 1
console.log("failed", checkres); console.log("===第" + i + " 张图片检验失败", e)
reject("===第" + i + " 张图片检验失败")
} }
}) })
}, },
......
// pages/post/post.js // pages/post/post.js
...@@ -74,7 +74,7 @@ Page({ ...@@ -74,7 +74,7 @@ Page({
//then后的括号里应该是参数param //then后的括号里应该是参数param
//https://www.cnblogs.com/qlongbg/p/11603328.html //https://www.cnblogs.com/qlongbg/p/11603328.html
promise.then(function (value) { promise.then(function (value) {
console.log("===enter promise then_" + value) console.log("===checkPic_enter promise then_" + value)
//同步更新全局变量 //同步更新全局变量
app.globalData.postData.photoArray = newFilePaths app.globalData.postData.photoArray = newFilePaths
wx.navigateTo({ url: './edit/edit' }) wx.navigateTo({ url: './edit/edit' })
...@@ -107,6 +107,7 @@ Page({ ...@@ -107,6 +107,7 @@ Page({
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) { success: function (res) {
var canvasId = "photoCanvasId"; var canvasId = "photoCanvasId";
console.log("===addPhoto_上传图片参数", res)
_this.onEditPic(res, canvasId) _this.onEditPic(res, canvasId)
} }
}) })
...@@ -139,6 +140,8 @@ Page({ ...@@ -139,6 +140,8 @@ Page({
src: pic, //图片的路径,可以是相对路径,临时文件路径,存储文件路径,网络图片路径, src: pic, //图片的路径,可以是相对路径,临时文件路径,存储文件路径,网络图片路径,
success: function (res) { success: function (res) {
// util.imageUtil 用于计算长宽比 // util.imageUtil 用于计算长宽比
var i = index + 1
console.log("第"+i+"张上传图片参数", res)
var imageSize = util.imageUtil(res); var imageSize = util.imageUtil(res);
console.log("success on getImageInfo_"+index); console.log("success on getImageInfo_"+index);
console.log(imageSize) console.log(imageSize)
...@@ -147,32 +150,39 @@ Page({ ...@@ -147,32 +150,39 @@ Page({
}) })
const ctx = wx.createCanvasContext(canvasId); const ctx = wx.createCanvasContext(canvasId);
ctx.drawImage(pic, 0, 0, imageSize.imageWidth, imageSize.imageHeight); ctx.drawImage(pic, 0, 0, imageSize.imageWidth, imageSize.imageHeight);
ctx.draw(false, function () { // 需要注意的是 draw 方法是异步的,如果图片还没加载成功,有可能画出来的是空的
console.log("==enter draw_"+index); // 所以 draw 方法通常都会带有定时器这样的回调
ctx.draw(false, setTimeout(function () {
//ctx.draw(false, function () {
var i = index + 1
console.log("==enter draw_"+i);
wx.canvasToTempFilePath({ wx.canvasToTempFilePath({
canvasId: canvasId, canvasId: canvasId,
fileType:"jpg", fileType:"jpg",
success: function (res) { success: function (res) {
console.log("===success_", res) console.log("===success_", res)
console.log("===第"+index+"图处理成功") console.log("===第"+i+"图处理成功")
index = index + 1
_this.editPic(tempFilePaths, index, canvasId); // 用于多个图片压缩
photoArray.push(res.tempFilePath) photoArray.push(res.tempFilePath)
_this.setData({ _this.setData({
photoArray: photoArray photoArray: photoArray
}) })
index = index + 1
_this.editPic(tempFilePaths, index, canvasId); // 用于多个图片压缩
}, },
fail: function (e) { fail: function (e) {
console.log("===第"+index+"图处理失败") var i = index + 1
console.log("===第"+i+"图处理失败")
} }
}); });
}); },1000));
//});
}, },
fail: function(e) { fail: function(e) {
console.log("failed", e); console.log("failed", e);
}, },
complete: function(e) { complete: function(e) {
console.log("complete on getImageInfo_"+index, e); var i = index + 1
console.log("complete on getImageInfo_"+i, e);
} }
}) })
} }
......
function formatTime(date) { function formatTime(date) {
...@@ -43,9 +43,11 @@ function imageUtil(e) { ...@@ -43,9 +43,11 @@ function imageUtil(e) {
//获取屏幕宽高 //获取屏幕宽高
wx.getSystemInfo({ wx.getSystemInfo({
success: function (res) { success: function (res) {
// 想要适应其他尺寸的屏幕时其实需按照iPhone6(375x667)的绘制大小按比例进行换算即可
var rpx = res.windowWidth / 375;
// canvas 基础宽高调为 2 倍,避免图片压缩程度过高导致图片字体显示不清楚 // canvas 基础宽高调为 2 倍,避免图片压缩程度过高导致图片字体显示不清楚
var windowWidth = res.windowWidth * 2; var windowWidth = res.windowWidth;
var windowHeight = res.windowHeight * 2; var windowHeight = res.windowHeight;
var windowscale = windowHeight / windowWidth;//屏幕高宽比 var windowscale = windowHeight / windowWidth;//屏幕高宽比
// 图片尺寸大于设备 // 图片尺寸大于设备
......
package cn.com.fun.nyxkey.api.service.impl; package cn.com.fun.nyxkey.api.service.impl;
...@@ -22,6 +22,11 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -22,6 +22,11 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.*; import java.util.*;
...@@ -108,6 +113,7 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService { ...@@ -108,6 +113,7 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService {
* } * }
*/ */
public JSONResult checkPic(String accessToken, MultipartFile multipartFile) { public JSONResult checkPic(String accessToken, MultipartFile multipartFile) {
getPicInfo(multipartFile);
try { try {
CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpClient httpclient = HttpClients.createDefault();
...@@ -160,4 +166,20 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService { ...@@ -160,4 +166,20 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService {
return checkPic(token, multipartFile); return checkPic(token, multipartFile);
} }
public void getPicInfo(MultipartFile multipartFile) {
System.out.println("图片名称: "+multipartFile.getName());
System.out.println("图片原名: "+multipartFile.getOriginalFilename());
System.out.println(String.format("图片大小: %.1fM",multipartFile.getSize()/1024.0/1024.0));
try {
BufferedImage image = ImageIO.read(multipartFile.getInputStream());
if (image != null) {//如果image=null 表示上传的不是图片格式
System.out.println("图片宽度: "+image.getWidth());//获取图片宽度,单位px
System.out.println("图片高度: "+image.getHeight());//获取图片高度,单位px
}
} catch (IOException e) {
System.out.println("===getPicInfo failed");//获取图片宽度,单位px
e.printStackTrace();
}
}
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
...@@ -249,7 +249,7 @@ limitations under the License. ...@@ -249,7 +249,7 @@ limitations under the License.
<if test="createDatetime != null"> <if test="createDatetime != null">
AND DATE_FORMAT(create_datetime, '%Y-%m-%d') &gt;= DATE_FORMAT(#{createDatetime,jdbcType=DATE}, '%Y-%m-%d') AND DATE_FORMAT(create_datetime, '%Y-%m-%d') &gt;= DATE_FORMAT(#{createDatetime,jdbcType=DATE}, '%Y-%m-%d')
</if> </if>
order by num_like desc, create_datetime desc order by create_datetime desc, num_like desc
<if test="pagination != null "> <if test="pagination != null ">
<include refid="pagination"/> <include refid="pagination"/>
</if> </if>
......
server: server:
...@@ -18,6 +18,10 @@ spring: ...@@ -18,6 +18,10 @@ spring:
group-id: udsp group-id: udsp
thymeleaf: thymeleaf:
cache: false cache: false
servlet:
multipart:
max-file-size: 100MB
max-request-size: 1000MB
logging: logging:
file: log/server.log file: log/server.log
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论