Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在spring controller中将图像文件格式更改为jpeg格式吗 品名 --%> 产品文件上传 品名 ${ProductNameList.productName} 文件类型 ${FiletypeList.filetype} 选择文件_Spring - Fatal编程技术网

我可以在spring controller中将图像文件格式更改为jpeg格式吗 品名 --%> 产品文件上传 品名 ${ProductNameList.productName} 文件类型 ${FiletypeList.filetype} 选择文件

我可以在spring controller中将图像文件格式更改为jpeg格式吗 品名 --%> 产品文件上传 品名 ${ProductNameList.productName} 文件类型 ${FiletypeList.filetype} 选择文件,spring,Spring,您可以在控制器中导入文件并将其转换。转换类示例: <form name="myForm1" method="post" enctype="multipart/form-data" action="singlesave1"> <div id="tab2" style ="width: 860px; height: 140px; float: left; margin-top: 25px;margin-left: 140px;"> &

您可以在控制器中导入文件并将其转换。转换类示例:

 <form name="myForm1" method="post" enctype="multipart/form-data" action="singlesave1">  
        <div id="tab2"  style ="width: 860px; height: 140px; float: left; margin-top: 25px;margin-left: 140px;">

        <label class="Date1">Product Name &nbsp;&nbsp;  
        <input id="product_name" style="width: 210px;margin-left: 50px;  height: 30px;" type="text" name="productname" required  value="">
        <input type="submit" value="Insert"  onclick="upload1();" style=" width:100px;margin-left: 163px;margin-top: 15px;" >
</div> </form> --%>

<form name="myForm" method="post" enctype="multipart/form-data" action="singlesave">    

<div id="table3"  style ="width: 860px; height: 320px; float: left; margin-top: 25px;margin-left:140px;">
<h2 align="center"><u><b>Product File Upload</b></u></h2>
<label class="Date1">Product Name &nbsp;&nbsp;          
            <form:select path="ProductNameList" id="product_name1" name="productname1" style="width: 250px; margin-left: 50px; height: 30px;">
                        <option value="" label="---  Select Product Name ---" />
                        <c:forEach var="ProductNameList" items="${ProductNameList}" varStatus="loop">
                            <option value="${ProductNameList.productcode}">${ProductNameList.productName}</option>
                        </c:forEach>
                    </form:select></label>

<label class="Date2">File Type &nbsp;&nbsp;
            <form:select path="FiletypeList" id="file_type1"  name="filetype1"  style="width: 250px; margin-left: 84px; height: 30px;">
                        <option value="" label="---  Select File Type ---" />
                        <c:forEach var="FiletypeList" items="${FiletypeList}" varStatus="loop">
                            <option value="${FiletypeList.id}">${FiletypeList.filetype}</option>
                        </c:forEach>
                    </form:select></label>

<label class="Date3">Select  File &nbsp;&nbsp;
        <input type="file" id="up_file" name="files" size="40" style= "padding-right: 15px;margin-top:-32px;margin-left:164px;" ></label>

        <input type="submit" value="Upload" onclick="return upload2();"  style=" width:94px;margin-left: 378px;margin-top: 10px;">
</div>      
    </form>

字符串file1=files.getOriginalFilename().split(“\”)[0]//将任何类型的文件格式转换为.jpg和.mp4。。。 if(fileinsert.getFiletype1().equals(“1”)|| fileinsert.getFiletype1().equals(“2”)){ file2=file1+“.jpg”;} else if(fileinsert.getFiletype1().equals(“3”)){ file2=file1+“.mp4”; }else{}
fileinsert.setUploadfilename(file2)

当我选择.png和其他格式文件上传时,它将仅转换为jpg格式。如何操作。。
package com.mkyong;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class ConvertImageFile {

    public static void main(String[] args) {
        BufferedImage bufferedImage;
        try {
          //read image file
          bufferedImage = ImageIO.read(new File("img.png"));
          // create a blank, RGB, same width and height, and a white background
          BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(), 
                bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
          newBufferedImage.createGraphics()
                .drawImage(bufferedImage, 0, 0, Color.WHITE, null);

          // write to jpeg file
          ImageIO.write(newBufferedImage, "jpg", new File("img.jpg"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}