【问题标题】:Image flip and image filter android图像翻转和图像过滤器android
【发布时间】:2021-06-18 17:10:17
【问题描述】:

我正在尝试图像翻转和图像过滤但是我有一个问题当我在图像上放置过滤器然后当我翻转图像时过滤器被删除

public void Flipimg(View v1){
    img1.setImageBitmap(fliph(scaledBitmap));
    }
    public  Bitmap fliph(Bitmap bms){
    Matrix mat = new Matrix();
    mat.setScale(-1, 1);
    Bitmap bit1=Bitmap.createBitmap( bms, 0, 0, bms.getWidth(), bms.getHeight(), mat, true);
    return bit;         
public void Filterimg(View v2){
    img1.setImageBitmap(applyGreyscaleEffect(scaledBitmap));
    }
    public Bitmap applyGreyscaleEffect(Bitmap src) {
    final double GS_RED = 0.299;
    final double GS_GREEN = 0.587;
    final double GS_BLUE = 0.114;
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    int A, R, G, B;
    int pixel;
    int width = src.getWidth();
    int height = src.getHeight();
    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);
    R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
    bmOut.setPixel(x, y, Color.argb(A, R, G, B));}
    }
    return bmOut; 

looking images THIS image flip

THIS image apply filter

【问题讨论】:

    标签: android image filter bitmap flip


    【解决方案1】:

    如果您想按顺序应用效果,请通过 BitmapDrawable 获取 ImageView 上的当前位图。

    public void Flipimg(View v1)
    {
        //img1.setImageBitmap(fliph(scaledBitmap));
        Bitmap currentBitmap = ((BitmapDrawable) img1.getDrawable()).getBitmap();
        img1.setImageBitmap(fliph(currentBitmap));
    }
    
    
    public void Filterimg(View v2)
    {
        //img1.setImageBitmap(applyGreyscaleEffect(scaledBitmap));
        Bitmap currentBitmap = ((BitmapDrawable) img1.getDrawable()).getBitmap();
        img1.setImageBitmap(applyGreyscaleEffect(currentBitmap));
    }
    

    【讨论】:

    • 非常感谢您的帮助。你的回答对我帮助很大
    猜你喜欢
    • 2015-05-06
    • 2011-05-15
    • 1970-01-01
    • 2016-06-07
    • 2011-08-02
    • 2012-01-14
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多