本文实例为大家分享了Android剪切和上传图片的具体代码,供大家参考,具体内容如下
1、从Android系统相册选择一张图片getImageFromAlbum():
protected void getImageFromAlbum() {
isImgs = true;
// MainApplication.changeSettingStateus = true;
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image
public void CutPic(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image
public static Bitmap zoomImage(Bitmap bgimage, double newWidth,
double newHeight) {
// 获取这个图片的宽和高
float width = bgimage.getWidth();
float height = bgimage.getHeight();
// 创建操作图片用的matrix对象
Matrix matrix = new Matrix();
// 计算宽高缩放率
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);
return bitmap;
}
5、上传图片文件至服务器uploadImg(bitMaps);
private void uploadImg(final Bitmap bitP) {
// 将Bitmap转换成字符串
String string = null;
ByteArrayOutputStream bStream = new ByteArrayOutputStream();
bitP.compress(CompressFormat.JPEG, 100, bStream);
byte[] bytes = bStream.toByteArray();
string = base64.encodeToString(bytes, base64.DEFAULT);
try {
bStream.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//string 文件上传服务器...
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



