android api里自带了一个Bitmap类,用于处理图片。不是很难,直接上代码
view plaincopy to clipboardprint?
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 {
/** Called when the activity is first created. */
@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.inSampleSize = 10;
//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){
try {
//Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f),null,o);
//The new size we want to scale to
final int REQUIRED_HEIGHT=800;
final int REQUIRED_WIDTH=480;
//Find the correct scale value. It should be the power of 2.
int width_tmp=o.outWidth, height_tmp=o.outHeight;
System.out.println(width_tmp+" "+height_tmp);
Log.w("===", (width_tmp+" "+height_tmp));
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_WIDTH && height_tmp/2<REQUIRED_HEIGHT)
break;
width_tmp/=2;
height_tmp/=2;
scale++;
Log.w("===", scale+"''"+width_tmp+" "+height_tmp);
}
//Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
}
分享到:
相关推荐
android 录制视频并生成缩略图。
先添加桌面小部件,然后保存桌面小部件图片,最后从相应的目录获取缩略图。
在 Android 的一些界面中,有时候我们需要为一副图片生成大小为 n * n 的缩略图,有时候需要的缩略图特殊一些,比如: 1、带圆角的缩略图: 如果我们需要带圆角的缩略图,但提供的图片是 n * n 的正方形的图片,该...
测试可用,效果很好,android-调用系统相册和系统照相机功能实例。
Android生成视频预览缩略图播放指定视频,学习一下如何获取界面上VideoView组件,如何创建MediaController对象,设置videoView与mController建立关联,设置mController与videoView建立关联,让VideoView获取焦点等...
录制视频,播放视频,生成缩略图。
参考博客:http://blog.csdn.net/joe_storm/article/details/49868155 使用android自带的MediaStore可以方便的操作本地的媒体文件。但是某些设备不能生成视频缩略图,所以要使用本方案完善
Cache生成并检索缩略图图像功能,Android-Image-Cache是一个能够自动判断从内存还是网络获取图片、缓存可以自动回收、自动判断如何有效地生成并检索各种尺寸缩略图的图像download-and-cacher,喜欢的朋友可以研究...
最近要搞一个项目,需要上传相册和拍照的图片,不负所望,终于完成了... 不过需要说明一下,其实网上很多教程拍照的图片,都是缩略图不是很清晰,所以需要在调用照相机的时候,事先生成一个地址,用于标识拍照的图片URI
主要介绍了Thinkphp调用Image类生成缩略图的方法,实例分析了Thinkphp调用Image类生成缩略图的使用原理与相关技巧,需要的朋友可以参考下
图片的加载方法也如其他的一样是写死了的,这就限制了其使用范围,只可通过InputStream来decode图片,而像生成缩略图或其他一些图片处理的异步处理就无法用途。修改现有类库总比自己从头写来的简单,于是稍微修改了...
一个 Flutter 插件,用于从本地存储上的视频生成缩略图。 兼容性 仅限安卓操作系统 用法 依赖它 在 pubspec.yaml 文件中添加thumbnails作为依赖项。 thumbnails : ^1.0.1 更新 Android 权限 将这些行添加到 ...
主要包含三个方面,Android启动系统相机生成缩略图、Android启动系统相机生成原图以及Android自定义相机等。 博客地址:http://blog.csdn.net/chenzheng8975/article/details/53943775
android选择图片或拍照图片上传到服务器(包括上传参数) ... 不过需要说明一下,其实网上很多教程拍照的图片,都是缩略图不是很清晰,所以需要在调用照相机的时候,事先生成一个地址,用于标识拍照的图片URI
录制视频并生成缩略图的简单源码是一个使用系统录像界面录制视频并生成一个视频缩略图的小例子,看了下源码实现主要使用了ThumbnailUtils.createVideoThumbnail(imgPath,Video.Thumbnails.MINI_KIND)没其他亮点,...
Cache生成并检索缩略图图像功能,Android-Image-Cache是一个能够自动判断从内存还是网络获取图片、缓存可以自动回收、自动判断如何有效地生成并检索各种尺寸缩略图的图像download-and-cacher,喜欢的朋友可以研究...
质量压缩一般可用于上传大图前的处理,这样就可以节省一定的流量,毕竟现在的手机拍照都能达到3M左右了,尺寸压缩一般可用于生成缩略图。 两种方法都实装在了我的项目中,结果却发现在质量压缩的模块中,本来1.9M的...
通过摄像头拍摄视频,切割成gif图片,并且生成缩略图。真的很好用。
Android生成视频预览缩略图播放指定视频