android – 圆形鱼眼扭曲扭曲270度,逆时针扭转90度?

android – 圆形鱼眼扭曲扭曲270度,逆时针扭转90度?,第1张

概述我有一个应用程序扭曲位图上的圆圈与鱼眼失真.圆圈似乎旋转了180度并且扭曲了.有任何想法吗?关于为什么在过滤器类中,我没有任何线索.谢谢马特. import java.io.BufferedInputStream;import java.io.DataInputStream;import java.io.File;import java.io.FileInputStream;import 我有一个应用程序扭曲位图上的圆圈与鱼眼失真.圆圈似乎旋转了180度并且扭曲了.有任何想法吗?关于为什么在过滤器类中,我没有任何线索.谢谢马特.

import java.io.BufferedinputStream;import java.io.DatainputStream;import java.io.file;import java.io.fileinputStream;import java.io.inputStream;import com.tecmark.HorizontalSlIDer.OnProgresschangelistener;import androID.content.Context;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.graphics.BitmapShader;import androID.graphics.Canvas;import androID.graphics.color;import androID.graphics.Paint;import androID.graphics.PorterDuffXfermode;import androID.graphics.PorterDuff.Mode;import androID.graphics.Shader.TileMode;import androID.os.Environment;import androID.util.AttributeSet;import androID.util.Log;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.vIEw.VIEw.OnClickListener;import androID.Widget.button;import androID.Widget.ImageVIEw;public class touchVIEw extends VIEw{    private file tempfile;    private byte[] imageArray;    private Bitmap bgr;    private Bitmap bm;    private Bitmap bgr2 = null;;    private Paint ptouch;    private int centreX = 1;    private int centreY = 1;    private int radius = 50;    private int Progress;    private static final String TAG = "*********touchVIEw";    private Filters f = null;    public touchVIEw(Context context) {        super(context);       // touchVIEw(context,null);    }    public touchVIEw(Context context,AttributeSet attr) {        super(context,attr);        tempfile = new file(Environment.getExternalStorageDirectory().                getabsolutePath() + "/"+"image.jpg");        imageArray = new byte[(int)tempfile.length()];     try{            inputStream is = new fileinputStream(tempfile);            BufferedinputStream bis = new BufferedinputStream(is);            DatainputStream dis = new DatainputStream(bis);            int i = 0;            while (dis.available() > 0) {            imageArray[i] = dis.readByte();            i++;            }            dis.close();       } catch (Exception e) {               e.printstacktrace();            }        BitmapFactory.Options bfo = new BitmapFactory.Options();        bfo.inSampleSize = 1;        bm = BitmapFactory.decodeByteArray(imageArray,imageArray.length,bfo);        bgr = Bitmap.createBitmap(bm.getWIDth(),bm.getHeight(),bm.getConfig());        bgr = bm.copy(bm.getConfig(),true);        bgr2 = Bitmap.createBitmap(bm.getWIDth(),bm.getConfig());      f = new Filters();      //bgr2 = f.barrel(bgr,0.00022F);        ptouch = new Paint(Paint.ANTI_AliAS_FLAG);                 ptouch.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));         ptouch.setcolor(color.transparent);        ptouch.setStyle(Paint.Style.stroke);    }// end of touchVIEw constructor    public voID findCirclePixels(){     /*  for (int i=centreX-50; i < centreX+50; ++i) {            for (int y=centreY-50; y <centreY+50 ; ++y) {    if( Math.sqrt( Math.pow(i - centreX,2) + ( Math.pow(y - centreY,2) ) ) <= radius ){                    bgr.setPixel(i,y,color.rgb(Progress+50,Progress,Progress+100));                }            }        }*/        float prog = (float)Progress/2000000;        bgr2 = f.barrel(bgr,prog);        }// end of changePixel()    @OverrIDe    public boolean ontouchEvent(MotionEvent ev) {        switch (ev.getAction()) {            case MotionEvent.ACTION_DOWN: {                centreX = (int) ev.getX();                centreY = (int) ev.getY();                findCirclePixels();                invalIDate();                break;            }            case MotionEvent.ACTION_MOVE: {                    centreX = (int) ev.getX();                    centreY = (int) ev.getY();                    findCirclePixels();                    invalIDate();                    break;            }                       case MotionEvent.ACTION_UP:                 break;        }        return true;    }//end of ontouchEvent    public voID initSlIDer(final HorizontalSlIDer slIDer)    {        Log.e(TAG,"******setting up slIDer*********** ");        slIDer.setonProgresschangelistener(changelistener);    }    private OnProgresschangelistener changelistener = new OnProgresschangelistener() {        @OverrIDe        public voID onProgressChanged(VIEw v,int progress) {            // Todo auto-generated method stub            setProgress(progress);            Log.e(TAG,"***********progress = "+Progress);        }    };    @OverrIDe    public voID onDraw(Canvas canvas){        super.onDraw(canvas);        canvas.drawBitmap(bgr2,null);        canvas.drawCircle(centreX,centreY,radius,ptouch);    }//end of onDraw    protected voID setProgress(int progress2) {        this.Progress = progress2;        findCirclePixels();        invalIDate();    }}

.

import androID.graphics.Bitmap;import androID.util.Log;class Filters{    float xscale;    float yscale;    float xshift;    float yshift;    int [] s;    private String TAG = "Filters";    public Filters(){        Log.e(TAG,"***********insIDe constructor");    }    public Bitmap barrel (Bitmap input,float k){        Log.e(TAG,"***********insIDe barrel method ");        float centerX=input.getWIDth()/2; //center of distortion        float centerY=input.getHeight()/2;        int wIDth = input.getWIDth(); //image bounds        int height = input.getHeight();        Bitmap dst = Bitmap.createBitmap(wIDth,height,input.getConfig() ); //output pic        Log.e(TAG,"***********dst bitmap created ");          xshift = calc_shift(0,centerX-1,centerX,k);          float newcenterX = wIDth-centerX;          float xshift_2 = calc_shift(0,newcenterX-1,newcenterX,k);          yshift = calc_shift(0,centerY-1,centerY,k);          float newcenterY = height-centerY;          float yshift_2 = calc_shift(0,newcenterY-1,newcenterY,k);          xscale = (wIDth-xshift-xshift_2)/wIDth;          yscale = (height-yshift-yshift_2)/height;          Log.e(TAG,"***********about to loop through bm");          /*for(int j=0;j<dst.getHeight();j++){              for(int i=0;i<dst.getWIDth();i++){                float x = geTradialX((float)i,(float)j,k);                float y = geTradialY((float)i,k);                sampleImage(input,x,y);                int color = ((s[1]&0x0ff)<<16)|((s[2]&0x0ff)<<8)|(s[3]&0x0ff);    //            System.out.print(i+" "+j+" \");                dst.setPixel(i,j,color);              }            }*/          int origPixel;          for(int j=0;j<dst.getHeight();j++){              for(int i=0;i<dst.getWIDth();i++){                 origPixel= input.getPixel(i,j);                float x = geTradialX((float)i,y);                int color = ((s[1]&0x0ff)<<16)|((s[2]&0x0ff)<<8)|(s[3]&0x0ff);    //            System.out.print(i+" "+j+" \");                if( Math.sqrt( Math.pow(i - centerX,2) + ( Math.pow(j - centerY,2) ) ) <= 85 ){                dst.setPixel(i,color);                }else{                    dst.setPixel(i,origPixel);                }              }            }        return dst;    }    voID sampleImage(Bitmap arr,float IDx0,float IDx1)    {        s = new int [4];      if(IDx0<0 || IDx1<0 || IDx0>(arr.getHeight()-1) || IDx1>(arr.getWIDth()-1)){        s[0]=0;        s[1]=0;        s[2]=0;        s[3]=0;        return;      }      float IDx0_fl=(float) Math.floor(IDx0);      float IDx0_cl=(float) Math.ceil(IDx0);      float IDx1_fl=(float) Math.floor(IDx1);      float IDx1_cl=(float) Math.ceil(IDx1);      int [] s1 = getARGB(arr,(int)IDx0_fl,(int)IDx1_fl);      int [] s2 = getARGB(arr,(int)IDx1_cl);      int [] s3 = getARGB(arr,(int)IDx0_cl,(int)IDx1_cl);      int [] s4 = getARGB(arr,(int)IDx1_fl);      float x = IDx0 - IDx0_fl;      float y = IDx1 - IDx1_fl;      s[0]= (int) (s1[0]*(1-x)*(1-y) + s2[0]*(1-x)*y + s3[0]*x*y + s4[0]*x*(1-y));      s[1]= (int) (s1[1]*(1-x)*(1-y) + s2[1]*(1-x)*y + s3[1]*x*y + s4[1]*x*(1-y));      s[2]= (int) (s1[2]*(1-x)*(1-y) + s2[2]*(1-x)*y + s3[2]*x*y + s4[2]*x*(1-y));      s[3]= (int) (s1[3]*(1-x)*(1-y) + s2[3]*(1-x)*y + s3[3]*x*y + s4[3]*x*(1-y));    }    int [] getARGB(Bitmap buf,int x,int y){        int rgb = buf.getPixel(y,x); // Returns by default ARGB.        int [] scalar = new int[4];        scalar[0] = (rgb >>> 24) & 0xFF;        scalar[1] = (rgb >>> 16) & 0xFF;        scalar[2] = (rgb >>> 8) & 0xFF;        scalar[3] = (rgb >>> 0) & 0xFF;        return scalar;    }    float geTradialX(float x,float y,float cx,float cy,float k){      x = (x*xscale+xshift);      y = (y*yscale+yshift);      float res = x+((x-cx)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));      return res;    }    float geTradialY(float x,float k){      x = (x*xscale+xshift);      y = (y*yscale+yshift);      float res = y+((y-cy)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));      return res;    }    float thresh = 1;    float calc_shift(float x1,float x2,float k){      float x3 = (float)(x1+(x2-x1)*0.5);      float res1 = x1+((x1-cx)*k*((x1-cx)*(x1-cx)));      float res3 = x3+((x3-cx)*k*((x3-cx)*(x3-cx)));      if(res1>-thresh && res1 < thresh)        return x1;      if(res3<0){        return calc_shift(x3,x2,cx,k);      }      else{        return calc_shift(x1,x3,k);      }    }}
解决方法 你确定没有旋转90°镜像吗?这可能是由于移调X轴和Y轴造成的.例如,我看到你正在调用buf.getPixel(y,x),尽管 Bitmap’s getPixel取x和y而不是y和x. 总结

以上是内存溢出为你收集整理的android – 圆形鱼眼扭曲扭曲270度,逆时针扭转90度?全部内容,希望文章能够帮你解决android – 圆形鱼眼扭曲扭曲270度,逆时针扭转90度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1124225.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存