private View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), SELECT_VIDEO);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_SELECT_VIDEO) {
if (resultCode == RESULT_OK) {
Uri videoUri = data.getData();
filePath = getRealFilePath(videoUri);
}
}
}
public List<Bitmap> createBitmaps(String path) {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(path);
double inc = 1000 * 1000 / fps;
for (double i = begin; i < end; i += inc) {
Bitmap frame = mmr.getFrameAtTime((long) i, MediaMetadataRetriever.OPTION_CLOSEST);
if (frame != null) {
bitmaps.add(scale(frame));
}
}
return bitmaps;
}
private Bitmap scale(Bitmap bitmap) {
return Bitmap.createScaledBitmap(bitmap,
width > 0 ? width : bitmap.getWidth(),
height > 0 ? height : bitmap.getHeight(),
true);
}
protected void getImagePixels() {
int w = image.getWidth();
int h = image.getHeight();
pixels = new byte[w*h*3];
for (int i = 0; i < h; i++) {
int stride = w * 3 * i;
for (int j = 0; j < w; j++) {
int p = image.getPixel(j, i);
int step = j * 3;
int offset = stride + step;
// blue
pixels[offset+0] = (byte) ((p & 0x0000FF) >> 0);
// green
pixels[offset+1] = (byte) ((p & 0x00FF00) >> 8);
// red
pixels[offset+2] = (byte) ((p & 0xFF0000) >> 16);
}
}
}
// 写入文件头
protected void writeHeader() throws IOException {
writeString("GIF89a");
}
protected void writeString(String s) throws IOException {
for (int i = 0; i < s.length(); i++) {
out.write((byte) s.charAt(i));
}
}
// 写入逻辑屏幕标识符
protected void writeLSD() throws IOException {
writeShort(width); // 写入图像宽度
writeShort(height); // 写入图像高度
out.write((0x80 | // 全局颜色列表标志置 1
0x70 | // 确定图象的颜色深度(7+1=8)
0x00 | // 全局颜色列表分类排列置为 0
0x07)); // 颜色列表的索引数(2的7+1次方)
out.write(0); // 背景颜色(在全局颜色列表中的索引)
out.write(0); // 像素宽高比默认 1:1
}
protected void writeShort(int value) throws IOException {
out.write(value & 0xff);
out.write((value >> 8) & 0xff);
}
// 写入颜色表
protected void writePalette() throws IOException {
out.write(colorTab, 0, colorTab.length);
int n = (3 * 256) - colorTab.length;
for (int i = 0; i < n; i++) {
out.write(0);
}
}
protected void writeGraphicCtrlExt() throws IOException {
out.write(0x21); // 扩展块标识,固定值 0x21
out.write(0xf9); // 图形控制扩展标签,固定值 0xf9
out.write(4); // 块大小,固定值 4
out.write(0 | // 1:3 保留位
0 | // 4:6 不使用处置方法
0 | // 7 用户输入标志置 0
0); // 8 透明色标志置 0
writeShort(delay); // 延迟时间
out.write(0); // 透明色索引值
out.write(0); // 块终结器,固定值 0
}
protected void writeImageDesc() throws IOException {
out.write(0x2c); // 图象标识符开始,固定值为 0x2c
writeShort(0); // x 方向偏移
writeShort(0); // y 方向偏移
writeShort(width); // 图像宽度
writeShort(height); // 图像高度
out.write((
0x80 | // 局部颜色列表标志置 1
0x00 |
0x00 |
0x07)); // 局部颜色列表的索引数(2的7+1次方)
}
protected void writePixels() throws IOException {
LZWEncoder encoder = new LZWEncoder(
width, height, indexedPixels, colorDepth);
encoder.encode(out);
}
public void finish() throws IOException {
out.write(0x3b);
out.flush();
out.close();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有