package me.zq.youjoin.model;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.ByteArrayOutputStream;

import me.zq.youjoin.utils.FileUtils;
import me.zq.youjoin.utils.MimeUtils;

/**
 * YouJoin
 * Created by ZQ on 2015/11/12.
 */
public class ImageInfo {

    //参数的名称
    private String paraName ;
    //文件名
    private String fileName ;
    //文件的 mime，需要根据文档查询
    private String mime ;
    //需要上传的图片资源，因为这里测试为了方便起见，直接把 bitmap 传进来
    //真正在项目中一般不会这般做，而是把图片的路径传过来，在这里对图片进行二进制转换
    //private Bitmap bitmap;
    private String imagePath;

//    public ImageInfo(Bitmap bitmap) {
//        this.bitmap = bitmap;
//    }

    public ImageInfo(String filePath){
        this.imagePath = filePath;
        this.fileName = FileUtils.getFileName(filePath);
        this.mime = MimeUtils.guessMimeTypeFromExtension(FileUtils.getFileExtension(filePath));
    }

//    public String getName() {
//        //        return mName;
//        //测试，把参数名称写死
//        return "uploadedfile" ;
//    }

    //对图片进行二进制转换
    public byte[] getValue() {
        if(imagePath == null){
            return new ByteArrayOutputStream().toByteArray();
        }
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
        bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos) ;
        return bos.toByteArray();
    }

    public String getFileName() {
        //测试，直接写死文件的名字
        //return "lufei.jpg";
        return fileName;
    }

    public String getMime() {
        //return "image/jpg";
        return mime;
    }

    public String getParaName() {
        return paraName;
    }

    public void setParaName(String paraName) {
        this.paraName = paraName;
    }

    public String getImagePath() {
        return imagePath;
    }

}

@@ -292,50 +292,8 @@
  %7B%0A%0A
-    //%E5%8F%82%E6%95%B0%E7%9A%84%E5%90%8D%E7%A7%B0%0A    private String paraName ;%0A
     
@@ -388,231 +388,43 @@
   //
-%E9%9C%80%E8%A6%81%E4%B8%8A%E4%BC%A0%E7%9A%84%E5%9B%BE%E7%89%87%E8%B5%84%E6%BA%90%EF%BC%8C%E5%9B%A0%E4%B8%BA%E8%BF%99%E9%87%8C%E6%B5%8B%E8%AF%95%E4%B8%BA%E4%BA%86%E6%96%B9%E4%BE%BF%E8%B5%B7%E8%A7%81%EF%BC%8C%E7%9B%B4%E6%8E%A5%E6%8A%8A bitmap %E4%BC%A0%E8%BF%9B%E6%9D%A5%0A    //%E7%9C%9F%E6%AD%A3%E5%9C%A8%E9%A1%B9%E7%9B%AE%E4%B8%AD%E4%B8%80%E8%88%AC%E4%B8%8D%E4%BC%9A%E8%BF%99%E8%88%AC%E5%81%9A%EF%BC%8C%E8%80%8C%E6%98%AF%E6%8A%8A%E5%9B%BE%E7%89%87%E7%9A%84%E8%B7%AF%E5%BE%84%E4%BC%A0%E8%BF%87%E6%9D%A5%EF%BC%8C%E5%9C%A8%E8%BF%99%E9%87%8C%E5%AF%B9%E5%9B%BE%E7%89%87%E8%BF%9B%E8%A1%8C%E4%BA%8C%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2%0A    //private Bitmap bitmap;%0A    private String imagePath;%0A%0A//    public ImageInfo(Bitmap bitmap) %7B%0A//        this.bitmap = bitmap;%0A//    %7D
+%E6%96%87%E4%BB%B6%E7%9A%84%E8%B7%AF%E5%BE%84%0A    private String imagePath;
 %0A%0A  
@@ -659,140 +659,8 @@
  %7D%0A%0A
-//    public String getName() %7B%0A//        //        return mName;%0A//        //%E6%B5%8B%E8%AF%95%EF%BC%8C%E6%8A%8A%E5%8F%82%E6%95%B0%E5%90%8D%E7%A7%B0%E5%86%99%E6%AD%BB%0A//        return %22uploadedfile%22 ;%0A//    %7D%0A%0A
     
@@ -1075,61 +1075,8 @@
 ) %7B%0A
-        //%E6%B5%8B%E8%AF%95%EF%BC%8C%E7%9B%B4%E6%8E%A5%E5%86%99%E6%AD%BB%E6%96%87%E4%BB%B6%E7%9A%84%E5%90%8D%E5%AD%97%0A        //return %22lufei.jpg%22;%0A
     
@@ -1145,201 +1145,17 @@
     
-//return %22image/jpg%22;%0A        return mime;%0A    %7D%0A%0A    public String getParaName() %7B%0A        return paraName;%0A    %7D%0A%0A    public void setParaName(String paraName) %7B%0A        this.paraName = paraNa
+return mi
 me;%0A

change ImageInfo