如何在android中通过编程在imageview图像上应用效果?
我想在图像视图图像上应用各种效果。此图像已从主要活动发送。我有效果代码,但不知道如何在单击按钮时应用。请指导我如何在android中通过编程在imageview图像上应用效果?,android,Android,我想在图像视图图像上应用各种效果。此图像已从主要活动发送。我有效果代码,但不知道如何在单击按钮时应用。请指导我 public class PhotoEffect extends Activity implements OnClickListener { ImageView camphoto; Bitmap bmp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedI
public class PhotoEffect extends Activity implements OnClickListener {
ImageView camphoto;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photoeffect);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Bundle extras=getIntent().getExtras();
//b=(Bitmap)extras.get("img");
byte[] byteArray=extras.getByteArray("img");
bmp=BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
camphoto=(ImageView)findViewById(R.id.camimage);
camphoto.setImageBitmap(bmp);
/*if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}*/
}
@Override
public void onClick(View v)
{
Bitmap bitmap = ((BitmapDrawable)camphoto.getDrawable()).getBitmap();
switch (v.getId())
{
case R.id.btnsepia:
//Bitmap bitmap = ((BitmapDrawable)camphoto.getDrawable()).getBitmap();
camphoto.setImageBitmap(createSepiaToningEffect(bitmap, 2, .5, .6, .59));
break;
case R.id.btnhighlight:
camphoto.setImageBitmap(doHighlightImage(bitmap));
break;
}
}
必须像这样定义createSepiaToningEffect函数,在处理后返回位图
public static Bitmap createSepiaToningEffect(Bitmap src, int depth, double red, double green, double blue) {
int width = src.getWidth();
int height = src.getHeight();
Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
final double GS_RED = 0.3;
final double GS_GREEN = 0.59;
final double GS_BLUE = 0.11;
int A, R, G, B;
int pixel;
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
pixel = src.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);
B = G = R = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B);
// apply intensity level for sepid-toning on each channel
R += (depth * red);
if(R > 255) { R = 255; }
G += (depth * green);
if(G > 255) { G = 255; }
B += (depth * blue);
if(B > 255) { B = 255; }
bmOut.setPixel(x, y, Color.argb(A, R, G, B));
}
}
return bmOut;
}此代码有什么问题。它是崩溃了还是有其他问题?我不知道knw,但这段代码不起作用。它也没有给出任何错误。我宁愿使用颜色矩阵,它比逐像素执行要快得多…我已经在同一活动中定义了该函数,但这个代码不起作用。我在alogcat中也没有得到任何错误。实际上这些效果并没有应用到图像上。