android生成缩略图
package com.forwork.thumbnail;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
public class Thumbnail extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
saveMyBitmap("ooo");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void saveMyBitmap(String bitName) throws IOException {
File originalFile = new File("sdcard/pic/ll.jpg");
Bitmap bmp = decodeFile(originalFile);
File f = new File("/sdcard/" + bitName + ".jpg");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//BitmapFactory.Options options=new BitmapFactory.Options();
//options.inTempStorage = new byte[16*1024];
//Bitmap bmp = BitmapFactory.decodeFile("/sdcard/pic/sd.jpg");
//Bitmap bmp = BitmapFactory.decodeFile("/sdcard/pic/ll.jpg", options);
//bmp = Bitmap.createScaledBitmap(bmp, 800, 480, true);
bmp.compress(Bitmap.CompressFormat.JPEG, 30, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//decodes image and scales it to reduce memory consumption
private Bitmap decodeFile(File f){
}
}