如何镜像位图然后旋转

时间:2015-11-04 13:58:57

标签: android bitmap

我有使用矩阵镜像的位图

import java.io.*;
/**Cound lines, characters and words Assumes all non white space are words so even () is a word*/
public class ChrCounts{

    String data;
    int chrCnt;
    int lineCnt;
    int wordCnt;
    public static void main(String args[]){
        ChrCounts c = new ChrCounts();
        try{
            InputStream data = null;
            if(args == null || args.length < 1){
                data = new ByteArrayInputStream("quick brown foxes\n\r new toy\'s a fun game.\nblah blah.la la ga-ma".getBytes("utf-8"));
            }else{
                data = new BufferedInputStream( new FileInputStream(args[0]));
            }
            c.process(data);
            c.print();
        }catch(Exception e){
            System.out.println("ee " + e);
            e.printStackTrace();
        }
    }

    public void print(){
        System.out.println("line cnt " + lineCnt + "\nword cnt " + wordCnt + "\n chrs " + chrCnt);
    }

    public void process(InputStream data) throws Exception{
        int chrCnt = 0;
        int lineCnt = 0;
        int wordCnt = 0;
        boolean inWord = false;
        boolean inNewline = false;
        //char prev = ' ';
        while(data.available() > 0){
            int j = data.read();
            if(j < 0)break;
            chrCnt++;
            final char c = (char)j;
            //prev = c;
            if(c == '\n' || c == '\r'){
                chrCnt--;//some editors do not count line seperators as new lines
                inWord = false;
                if(!inNewline){
                    inNewline = true;
                    lineCnt++;
                }else{
                    //chrCnt--;//some editors dont count adjaccent line seps as characters
                }
            }else{
                inNewline = false;
                if(Character.isWhitespace(c)){
                    inWord = false;
                }else{
                    if(!inWord){
                        inWord = true;
                        wordCnt++;
                    }
                }
            }
        }
        //we had some data and last char was not in new line, count last line
        if(chrCnt > 0 && !inNewline){
            lineCnt++;
        }
        this.chrCnt = chrCnt;
        this.lineCnt = lineCnt;
        this.wordCnt = wordCnt;
    }
}

并且可以使用

“取消镜像”
   mMirror.postScale(-1.0f, 1.0f);

但是,现在当我使用 mMirror.postScale(1.0f, 1.0f); 旋转位图时,镜像会丢失。为什么?

修改 为你创建一个Bitmap对象时,我们会在内部使用并创建一个Identity矩阵来校正所有镜像等。

现在问题变成了如何镜像然后旋转矩阵。

0 个答案:

没有答案