使用 jpeglib 压缩图片

#include <jpeglib.h>
void writeJPEG(unsigned char* pixs, int  width, int height, char* file) {
    struct jpeg_compress_struct jcs;
    struct jpeg_error_mgr jem;
    jcs.err = jpeg_std_error(&jem);
    jpeg_create_compress(&jcs);
    FILE* fp = fopen(file, "wb");
    if(fp == NULL) {
        perror("writeJPEG");
        return;
    }

    jpeg_stdio_dest(&jcs, fp);
    jcs.image_width = width;
    jcs.image_height = height;
    jcs.input_components = 3; //RGB
    jcs.in_color_space = JCS_RGB;
    jpeg_set_defaults(&jcs);
    jpeg_set_quality(&jcs, 100, TRUE); //输出图片质量

    jpeg_start_compress(&jcs, TRUE);
    JSAMPROW row_pointer[1];
    int row_stride;
    row_stride = jcs.image_width * 3; //RGB

    while(jcs.next_scanline < jcs.image_height) {
        row_pointer[0] = &pixs[jcs.next_scanline * row_stride];
        jpeg_write_scanlines(&jcs, row_pointer, 1);
    }
    
    jpeg_finish_compress(&jcs);
    jpeg_destroy_compress(&jcs);
    fclose(fp);
}

Android NDK 中的 LOCAL_LDLIBS and LOCAL_SHARED_LIBRARIES

  • LOCAL_LDLIBS : 不会重新编译所依赖的库
  • LOCAL_SHARED_LIBRARIES : 如果所依赖的库代码有更新,会重新编译该依赖库

Git RPC faild 解决方法

在git pull一个很大的库时发生了如下的错误:

macbookpro:Experiments sss$ git pull
remote: Counting objects: 3466, done.
remote: Compressing objects: 100% (2172/2172), done.
error: RPC failed; result=56, HTTP code = 200B | 17.00 KiB/s    
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

解决方法 增加git的post缓存大小:

git config --global http.postBuffer 500000000 #增加到约500MB

不同项目生命周期类型的比较

Alt none Alt none Alt none Alt none Alt none Alt none Alt none Alt none

ref: 《项目管理修炼之道》

ViewGroup使用补间动画

res/anim/layout_anim.xml

<?xml version="1.0" encoding="utf-8"?>

<layoutAnimation
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:delay="0.5"
    android:animationOrder="random"
    android:animation="@anim/popin"/>

res/anim/popin.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_interpolator" >

    <scale
        android:duration="2000"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>

res/layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutAnimation="@anim/layout_anim"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <TextView
        android:id="@+id/t2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/t1"
        android:text="@string/hello_world" />

    <TextView
        android:id="@+id/t3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/t2"
        android:text="@string/hello_world" />

</RelativeLayout>