///
///图片转换成String流///
/// 文件名(不带file://)
///
public static string ImageToString(stringfile_path)
{//待上传图片路径//string uploadFile = file_path;//转化成文件//System.IO.FileInfo imgFile = new System.IO.FileInfo(uploadFile);
文件转化成字节
//byte[] imgByte = new byte[imgFile.Length];
//读文件
//System.IO.FileStream imgStream = imgFile.OpenRead();
//文件写入到字节数组
//imgStream.Read(imgByte, 0, Convert.ToInt32(imgFile.Length));
//字节数组转换成String类型
//string by = Convert.ToBase64String(imgByte);
上传到服务器 后面是文件名fileUp.UpdateFile(imgByte, Guid.NewGuid() + ".png");
//return imgByte;
Bitmap bitmap= BitmapFactory.DecodeFile(file_path); //将图片文件转换成bitmap 格式:/storage/emulated/0/DCIM/Camera/IMG_20180425_105725.jpg
string bitstring =BitmapToString(bitmap);
bitmap= null; //一定要清空,否则会导致OOM问题
GC.Collect();returnbitstring;
}///
///图片缩放处理///
/// Bitmap文件
/// 新图片宽度
/// 新图片高度
///
public static Bitmap zoomImage(Bitmap bgimage, double newWidth, doublenewHeight)
{//获取这个图片的宽和高
float width =bgimage.Width;float height =bgimage.Height;//创建操作图片用的matrix对象
Matrix matrix = newMatrix();//计算宽高缩放率
float scaleWidth = ((float)newWidth) /width;float scaleHeight = ((float)newHeight) /height;//缩放图片动作
matrix.PostScale(scaleWidth, scaleHeight);
Bitmap bitmap= Bitmap.CreateBitmap(bgimage, 0, 0, (int)width,
(int)height, matrix, true);returnbitmap;
}static stringBitmapToString(Bitmap bitmap)
{
Bitmap bit= zoomImage(bitmap, 750, 1000);//小图//质量压缩//MemoryStream stream = new MemoryStream();//bit.Compress(Bitmap.CompressFormat.Jpeg, 50, stream);//byte[] bitmapData = stream.ToArray();//Bitmap map = BitmapFactory.DecodeByteArray(bitmapData, 0, bitmapData.Length);//btn_imagetwo.SetImageBitmap(map);//Bitmap im = zoomImage(bitmap, 800, 900);//大图
MemoryStream big_stream = newMemoryStream();
bit.Compress(Bitmap.CompressFormat.Jpeg,80, big_stream);byte[] big_bitmapData =big_stream.ToArray();returnConvert.ToBase64String(big_bitmapData);
}