有什么办法将位图转换为棕褐色? 我知道要转换为grayScale是要在ColorMatrix中设置setSaturation。 但是棕褐色呢?在Android中将位图转换为棕褐色
回答
我知道答案,但也许如果一些有其他更好的解决办法..
public Bitmap toSephia(Bitmap bmpOriginal)
{
int width, height, r,g, b, c, gry;
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
int depth = 20;
Bitmap bmpSephia = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmpSephia);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setScale(.3f, .3f, .3f, 1.0f);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
canvas.drawBitmap(bmpOriginal, 0, 0, paint);
for(int x=0; x < width; x++) {
for(int y=0; y < height; y++) {
c = bmpOriginal.getPixel(x, y);
r = Color.red(c);
g = Color.green(c);
b = Color.blue(c);
gry = (r + g + b)/3;
r = g = b = gry;
r = r + (depth * 2);
g = g + depth;
if(r > 255) {
r = 255;
}
if(g > 255) {
g = 255;
}
bmpSephia.setPixel(x, y, Color.rgb(r, g, b));
}
}
return bmpSephia;
}
如果您有图像的情况下,那么你可以使用ColorMartix绘制它的棕褐色。让我描述一下如何使用Drawable来完成这个任务。
public static void setSepiaColorFilter(Drawable drawable) {
if (drawable == null)
return;
final ColorMatrix matrixA = new ColorMatrix();
// making image B&W
matrixA.setSaturation(0);
final ColorMatrix matrixB = new ColorMatrix();
// applying scales for RGB color values
matrixB.setScale(1f, .95f, .82f, 1.0f);
matrixA.setConcat(matrixB, matrixA);
final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrixA);
drawable.setColorFilter(filter);
}
示例项目从Bitbucket移动到GitHub。请检查Release section下载APK二进制文件,无需编译即可测试。
如何获得ColorMatric以获得更多效果,如霓虹灯,indiglow,aqua,vivid等, 等待相关链接/提示/指导... – 2012-12-01 16:47:42
你需要找到相应的颜色矩阵值来获得这些效果。对不起,但我不知道任何资源,你可以找到它。如果您发现任何有用的信息,请在此发布。谢谢 – rude 2012-12-03 22:06:16
我发现这个ColorMatrix,并为我需要的颜色效果设置simillar值。 http://docs.rainmeter.net/tips/colormatrix-guide – 2012-12-05 12:11:28
我上the OP's answer提高。与the ColorMatrix
method相比,这款产品运行速度快,但产生更好的棕色色调。 (在我看来)
public Bitmap toSepiaNice(Bitmap color) {
int red, green, blue, pixel, gry;
int height = color.getHeight();
int width = color.getWidth();
int depth = 20;
Bitmap sepia = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int[] pixels = new int[width * height];
color.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < pixels.length; i++) {
pixel = pixels[i];
red = (pixel >> 16) & 0xFF;
green = (pixel >> 8) & 0xFF;
blue = pixel & 0xFF;
red = green = blue = (red + green + blue)/3;
red += (depth * 2);
green += depth;
if (red > 255)
red = 255;
if (green > 255)
green = 255;
pixels[i] = (0xFF << 24) | (red << 16) | (green << 8) | blue;
}
sepia.setPixels(pixels, 0, width, 0, 0, width, height);
return sepia;
}
- 1. 如何将棕褐色的弧度转换为度数
- 2. 通过Renderscript应用棕褐色ScriptIntrinsicColorMatrix将图像转换为绿色阴影
- 3. 棕褐色在相机预览视图
- 4. 如何将普通视图颜色更改为棕褐色?
- 5. easeljs棕褐色和灰度
- 6. ImageMagick棕褐色效果
- 7. 将视频音调变成棕褐色
- 8. 这个棕褐色调转换算法有什么问题?
- 9. 棕褐色在黑莓中的图像效果
- 10. 操纵照片到棕褐色
- 11. 如何创建棕褐色调?
- 12. 任何NSImage的棕褐色版本
- 13. 徘徊时获取棕褐色效果图像和全彩色?
- 14. Android:将位图转换为单色位图(每像素1位)
- 15. 在Android中将位图转换为GrayScale
- 16. 在iPhone转换图像为黑白,深褐色,灰度等SDK
- 17. android将位图转换为ascii位图
- 18. 如何将一个棕褐色效果添加到UIImageView?
- 19. 使用OpenGL固定管线(例如多纹理)转动图像棕褐色
- 20. 将位图转换为单色
- 21. 在Android中运行时转换时将SVG转换为位图
- 22. LINQ将“TheQuickBrownFox”转换为“快速棕色狐狸”的方法
- 23. Android将位图转换为灰度,但保留一种颜色
- 24. 在Android中将视图转换为位图图像
- 25. android将位图转换为bufferedinputstream
- 26. 将位图转换为byteArray android
- 27. Android:将字符串转换为位图
- 28. Android Studio - 将位图转换为java.io.File
- 29. 对UIImage应用棕褐色,RGB,GrayScale效果
- 30. 将256色位图转换为RGBA位图
这是要更多的处理时间,当图像像素更有这样的任何其他方式吗? – blackjack 2013-05-06 08:47:56
查看此主要https://gist.github.com/pmcfernandes/8261130 – pedrofernandes 2014-01-04 21:49:03
此方法在透明像素上失败 – 2015-03-11 10:33:04