#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>

#ifdef NOT_EMULATOR
#define TAG "for_test"
#include <android/log.h>
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#endif


void myFunc(){
#ifdef NOT_EMULATOR
    //FILE *stream;
    //stream=fopen("/storage/sdcard0/srx/2.txt","w+");
    int i=0;
    int j=0;
    int k=0;
    //int m =0;

#define BUF_SIZE 512
    for(i=0;i<64;i++){
        for(j=0;j<60;j++){
            int len =0;
            char buf[BUF_SIZE];
            memset(buf,0x0,BUF_SIZE);
            for(k=0;k<64;k++){
                //printf("k=%d,kaddr=%p\n", k, &k);//method1
                //LOGD("t_k=%d,kaddr=%p\n",k,&k);//method2
//len=欲写入的值,即para4的长度,para2是max can write值,para2不一定等于len(k长度('1212345')>para2(=3)),len=7
//para1=dest ptr,para3格式化,para4等于src ptr.
//这句作用是把每次for循环中的k,存到数组buf中,不是串成字串
len+=snprintf(buf+len,BUF_SIZE-len,"%d ",k);//method3 // fprintf(stream,k); } LOGD("tt_k=%s\n",buf);//打印此指针指向的串,%s } } // fclose(stream); #endif } int main() { myFunc(); return 0; }

 

2.log中打印两个指针对应的两行,

#include <stdio.h>
#include <stdlib.h>

#define BUF_SIZE 512 //注意这个要适时调整,>=rowbytes*3
#ifdef NOT_EMULATOR
#define TAG "png_for_test"
#include <android/log.h>
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#endif

void printbefore(png_size_t rowbytes, png_bytep row, png_const_bytep prev_row) {
    //srx s
    png_bytep trow = row;
    png_const_bytep prow = prev_row;
    int k = 0;
    int lenp = 0;
    int lent = 0;
    char bufp[BUF_SIZE];
    char buft[BUF_SIZE];
    memset(bufp, 0x0, BUF_SIZE);
    memset(buft, 0x0, BUF_SIZE);
    for (k = 0; k < rowbytes; k++) {
//每次读prow的一个字节(char类型),然后存到数组bufp的第lenp个位置,不是字串拼接,而是把for循环中的prow存到数组bufp中
lenp
+= snprintf(bufp + lenp, BUF_SIZE - lenp, "%x ", *prow); lent += snprintf(buft + lent, BUF_SIZE - lent, "%x ", *trow); if (k < (rowbytes - 1)) { trow++; prow++; } } trow = trow - (rowbytes - 1); prow = prow - (rowbytes - 1); #ifdef NOT_EMULATOR LOGD("11before-pre-row=%s\n",bufp); LOGD("11before-curr-row=%s\n",buft); #endif }

3. c中打印一个指针

 

xxx.c
...
extern void printbefore(uInt rowbytes, png_bytep row);
...
...
printbefore(num_print,byte_pointer);

//print.c,do not forget add print.c to Android.mk to compile.
#include <stdio.h> #include <stdlib.h> #include "pngconf.h" typedef unsigned int uInt; #define BUF_SIZE 51200//should at least 3*rowbytes #ifdef NOT_EMULATOR #define TAG "png_for_test" #include <android/log.h> #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) #endif void printbefore(uInt rowbytes, png_bytep row) { #ifdef NOT_EMULATOR LOGD("printbefore-1111--curr-rowbytes=%d,row=%p\n",rowbytes,row); #endif //srx s png_bytep trow = row; int k = 0; int lent = 0; char buft[BUF_SIZE]; memset(buft, 0x0, BUF_SIZE); for (k = 0; k < rowbytes; k++) { lent += snprintf(buft + lent, BUF_SIZE - lent, "%x ", *trow); if (k < (rowbytes - 1)) { trow++; } } trow = trow - (rowbytes - 1); #ifdef NOT_EMULATOR
LOGD("11print-curr-row=%s\n",buft);
#endif
}

 

4.Java层打印stream流某几个字节,再把stream流恢复回去。

    InputStream is = xxx;
if(is.markSupported()){ try{ is.mark(10);//设置mark limit,读小于此数时,reset后,能读取跟此次一样的值。让后面读的小于次数,mark才有效。 int byteRead = 0; //byte[] buffer = new byte[8]; byte[] buffer_one = new byte[1]; for(int i =0;i < 8;i++){ is.read(buffer_one);//每次往数组中存1个字节 Log.v(TAG,"byte="+Integer.toHexString(buffer_one[0]));//此处也可以不转16进制,查看10进制 } is.reset();//reset保证下面读到与mark之前一样的内容 }catch(IOException e){ Log.v(TAG,"bitmapfactory thow ioexception"); } }

 


 

posted on 2014-09-16 17:17  snowdrop  阅读(956)  评论(0编辑  收藏  举报