package com.jacp.image.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.util.Log;
import com.jacp.image.R;
public class ImageSpecific
{
private Context mContext;
public static final int FLAG_OLD_REMEMBER = 0;
public static final int FLAG_BLUR = FLAG_OLD_REMEMBER + 1;
public static final int FLAG_SHARPEN = FLAG_OLD_REMEMBER + 2;
public static final int FLAG_OVERLAY = FLAG_OLD_REMEMBER + 3;
public static final int FLAG_FILM = FLAG_OLD_REMEMBER + 4;
public static final int FLAG_EMBOSS = FLAG_OLD_REMEMBER + 5;
public static final int FLAG_SUNSHINE = FLAG_OLD_REMEMBER + 6;
public static final int FLAG_NEON = FLAG_OLD_REMEMBER + 7;
public static final int FLAG_ALPHA_LAYER = FLAG_OLD_REMEMBER + 8;
public ImageSpecific(Context context)
{
mContext = context;
}
/**
* 图片特效处理
* @param bmp
* @param flag
* @return
*/
public Bitmap imageSpecific(Bitmap bmp, int flag)
{
Bitmap bm = null;
switch (flag)
{
case FLAG_OLD_REMEMBER:
// bm = oldRemeber(bmp);
// bm = halo(bmp, 0, 0, 0);
// bm = stria(bmp);
// bm = chessbord(400);
bm = cropBitmap(bmp);
break;
case FLAG_BLUR:
// bm = blurImage(bmp, 3);
bm = blurImageAmeliorate(bmp);
break;
case FLAG_SHARPEN:
// bm = sharpenImage(bmp, 3);
bm = sharpenImageAmeliorate(bmp);
break;
case FLAG_OVERLAY:
// bm = overlay(bmp);
bm = overlayAmeliorate(bmp);
break;
case FLAG_FILM:
// bm = film(bmp);
bm = filmAmeliorate(bmp);
break;
case FLAG_EMBOSS:
// bm = emboss(bmp);
bm = embossAmeliorate(bmp);
break;
case FLAG_SUNSHINE:
// bm = sunshine(bmp);
bm = sunshineAmeliorate(bmp);
break;
case FLAG_NEON:
bm = neon(bmp);
break;
case FLAG_ALPHA_LAYER:
bm = alphaLayer(bmp);
break;
}
return bm;
}
/**
* 怀旧效果(相对之前做了优化快一倍)
* @param bmp
* @return
*/
private Bitmap oldRemeber(Bitmap bmp)
{
// 速度测试
long start = System.currentTimeMillis();
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
int pixColor = 0;
int pixR = 0;
int pixG = 0;
int pixB = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < height; i++)
{
for (int k = 0; k < width; k++)
{
pixColor = pixels[width * i + k];
pixR = Color.red(pixColor);
pixG = Color.green(pixColor);
pixB = Color.blue(pixColor);
newR = (int) (0.393 * pixR + 0.769 * pixG + 0.189 * pixB);
newG = (int) (0.349 * pixR + 0.686 * pixG + 0.168 * pixB);
newB = (int) (0.272 * pixR + 0.534 * pixG + 0.131 * pixB);
int newColor = Color.argb(255, newR > 255 ? 255 : newR, newG > 255 ? 255 : newG, newB > 255 ? 255 : newB);
pixels[width * i + k] = newColor;
}
}
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
long end = System.currentTimeMillis();
Log.d("may", "used time="+(end - start));
return bitmap;
}
/**
* 模糊效果
* @param bmp
* @return
*/
private Bitmap blurImage(Bitmap bmp)
{
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
int pixColor = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int newColor = 0;
int[][] colors = new int[9][3];
for (int i = 1, length = width - 1; i < length; i++)
{
for (int k = 1, len = height - 1; k < len; k++)
{
for (int m = 0; m < 9; m++)
{
int s = 0;
int p = 0;
switch(m)
{
case 0:
s = i - 1;
p = k - 1;
break;
case 1:
s = i;
p = k - 1;
break;
case 2:
s = i + 1;
p = k - 1;
break;
case 3:
s = i + 1;
p = k;
break;
case 4:
s = i + 1;
p = k + 1;
break;
case 5:
s = i;
p = k + 1;
break;
case 6:
s = i - 1;
p = k + 1;
break;
case 7:
s = i - 1;
p = k;
break;
case 8:
s = i;
p = k;
}
pixColor = bmp.getPixel(s, p);
colors[m][0] = Color.red(pixColor);
colors[m][1] = Color.green(pixColor);
colors[m][2] = Color.blue(pixColor);
}
for (int m = 0; m < 9; m++)
{
newR += colors[m][0];
newG += colors[m][1];
newB += colors[m][2];
}
newR = (int) (newR / 9F);
newG = (int) (newG / 9F);
newB = (int) (newB / 9F);
newR = Math.min(255, Math.max(0, newR));
newG = Math.min(255, Math.max(0, newG));
newB = Math.min(255, Math.max(0, newB));
newColor = Color.argb(255, newR, newG, newB);
bitmap.setPixel(i, k, newColor);
newR = 0;
newG = 0;
newB = 0;
}
}
return bitmap;
}
/**
* 柔化效果(高斯模糊)(优化后比上面快三倍)
* @param bmp
* @return
*/
private Bitmap blurImageAmeliorate(Bitmap bmp)
{
long start = System.currentTimeMillis();
// 高斯矩阵
int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 1 };
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
int pixR = 0;
int pixG = 0;
int pixB = 0;
int pixColor = 0;
int newR = 0;
int newG = 0;
int newB = 0;
int delta = 16; // 值越小图片会越亮,越大则越暗
int idx = 0;
int[] pixels = new int[width * height];
bmp.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 1, length = height - 1; i < length; i++)
{
for (int k = 1, len = width - 1; k < len; k++)
{
idx = 0;
for (int m = -1; m <= 1; m++)
{
for (int n = -1; n <= 1; n++)
{
pixColor = pixels[(i + m) * width + k + n];
pixR = Color.red(pixColor);
pixG = Color.green(pixColor);
pixB = Color.blue(pixColor);
newR = newR + (int) (pixR * gauss[idx]);
newG = newG + (int) (pixG * gauss[idx]);
newB = newB + (int) (pixB * gauss[idx]);
idx++;
}
}
newR /= delta;
newG /= delta;
newB /= delta;
newR = Math.min(255, Math.max(0, newR));
newG = Math.min(255, Math.max(0, newG));
newB = Math.min(255, Math.max(0, newB));
pixels[i * width + k] = Color.argb(255, newR, newG, newB);
newR = 0;
newG = 0;
newB = 0;
}
}
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
long end = System.currentTimeMillis();
Log.d("may", "used time="+(end - start));
return bitmap;
}
/**
* 锐化效果
* @param bmp
* @return
*/
private Bitmap sharpenImage(Bitmap bmp, float sharpen)
{
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
int pixR = 0;
int pixG = 0;
int pixB = 0;
int pixColor = 0;
int newR = 0;
int newG = 0;
int newB = 0;
float alpha = 0.9F;
int newColor = 0;
int[][] colors = new int[8][3];
for (int i = 1, length = width - 1; i < length; i++)
{
for (int k = 1, len = height - 1; k < len; k++)
{
for (int m = 0; m < 8; m++)
{
int s = 0;
int p = 0;
switch(m)
{
case 0:
s = i - 1;
p = k -
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android平台上的图像编辑软件 (157个子文件)
resources.ap_ 923KB
ImageHandleV4.2.apk 974KB
proguard.cfg 1KB
.classpath 288B
Thumbs.db 96KB
Thumbs.db 4KB
classes.dex 98KB
ImageSpecific.java 36KB
MainActivity.java 22KB
HighlightView.java 14KB
SecondaryListMenuView.java 14KB
MenuView.java 14KB
ImageViewTouchBase.java 12KB
EditImage.java 12KB
ImageFrameAdder.java 11KB
CropImageView.java 10KB
ToneView.java 7KB
R.java 7KB
MenuItem.java 6KB
ChooseImageActivity.java 3KB
ImageMoveView.java 3KB
RotateBitmap.java 3KB
ToneMenuView.java 2KB
ImageHandler.java 2KB
ReverseAnimation.java 2KB
ImageUtil.java 2KB
ImageSwitch.java 1KB
MenuAdapter.java 848B
OnMenuClickListener.java 486B
SecondaryMenuView.java 77B
black.jpg 111KB
mm.jpg 56KB
a2.jpg 49KB
rainbow_overlay.jpg 24KB
a0.png 336KB
a0.png 329KB
a1.png 134KB
frame_big1.png 123KB
frame_big1.png 117KB
a1.png 112KB
old_remember.png 9KB
old_remember.png 9KB
frame_small1.png 8KB
frame_small1.png 7KB
ic_menu_rotate_left.png 5KB
ic_menu_rotate_right.png 5KB
cloudy.png 5KB
cloudy.png 5KB
icon.png 4KB
icon.png 4KB
frame_around1.png 4KB
btn_view_back_press.png 4KB
btn_view_back_press.png 4KB
popup_bottom_tip.9.png 4KB
frame_around2.png 3KB
popup_bottom_tip.9.png 3KB
frame_around1_left_top.png 3KB
frame_around1_left_bottom.png 3KB
frame_around1_right_top.png 3KB
ic_menu_mapmode.png 3KB
frame_around1_right_bottom.png 3KB
btn_view_ok_press.png 3KB
btn_view_ok_press.png 3KB
indicator_autocrop.png 3KB
frame_around2_left.png 3KB
frame_around2_top.png 3KB
frame_around2_bottom.png 3KB
frame_around1_bottom.png 3KB
frame_around1_top.png 3KB
qipao2.png 3KB
frame_around2_right.png 3KB
ic_menu_rotate_left.png 3KB
frame_around1_left.png 3KB
frame_around1_right.png 3KB
indicator_autocrop.png 3KB
frame_around2_left_bottom.png 3KB
frame_around2_right_bottom.png 3KB
frame_around2_left_top.png 3KB
frame_around2_right_top.png 3KB
ic_menu_rotate_right.png 3KB
qipao2.png 3KB
ic_menu_crop.png 3KB
btn_mainmenu_edit_normal.png 3KB
btn_mainmenu_edit_normal.png 3KB
icon.png 3KB
qipao1.png 2KB
btn_mainmenu_color_normal.png 2KB
btn_mainmenu_color_normal.png 2KB
camera_crop_height.png 2KB
btn_view_back_normal.png 2KB
btn_view_back_normal.png 2KB
camera_crop_width.png 2KB
ic_menu_crop.png 2KB
icon.png 2KB
qipao0.png 2KB
camera_crop_height.png 2KB
camera_crop_width.png 2KB
ic_menu_mapmode.png 2KB
btn_mainmenu_edit_press.png 2KB
btn_mainmenu_edit_press.png 2KB
共 157 条
- 1
- 2
资源评论
- Y先生y2017-06-15还可以吧 很多地方有点卡顿 只适合初学者
- nishi51512013-06-05适合初学者?、
lanfacaiba
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功