赞
踩
Pillow是python的图像处理库,可以从github下载。pillow中部分代码使用C编写,如果需要在android环境中使用,则需要编译为android的共享库。编译过程与编译环境相关,这里使用redhat 7.0,已经安装了python 2.7,android的ndk。
Pillow使用了jpeg, png, freetype库,首先需要编译它们为静态库.
jpeg使用版本jpegsrc.v9b;png使用版本libpng-1.6.26
export ANDROID_NDK="/usr/local/android/android-ndk-r10d"
export PATH="$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/:$ANDROID_NDK:$ANDROID_NDK/tools:/usr/local/bin:/usr/bin:/bin:$PATH"
export ARCH="armeabi"
export CFLAGS="-DANDROID -mandroid -fomit-frame-pointer --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm"
export CXXFLAGS="$CFLAGS"
export CC="arm-linux-androideabi-gcc $CFLAGS"
export CXX="arm-linux-androideabi-g++ $CXXFLAGS"
export AR="arm-linux-androideabi-ar"
export RANLIB="arm-linux-androideabi-ranlib"
export STRIP="arm-linux-androideabi-strip --strip-unneeded"
export READELF="arm-linux-androideabi-readelf"
export MAKE="make -j4 CROSS_COMPILE_TARGET=yes"
export LAPACK=
解压jpegsrc.v9b.tar.gz
./configure LDFLAGS="-llog -lm" CFLAGS="-mandroid -fomit-frame-pointer -Wno-format" --disable-shared --host=arm-linux --build=i686-pc-linux-gnu --prefix="/usr/local/android/install/jpeg9b.armeabi"
make
make install
解压libpng-1.6.26.tar.gz
./configure LDFLAGS="-llog -lm" CFLAGS="-mandroid -fomit-frame-pointer -Wno-format" --disable-shared --host=arm-linux --build=i686-pc-linux-gnu --prefix="/usr/local/android/install/libpng1626.armeabi"
make
make install
./configure LDFLAGS="-llog -lm" LIBPNG_LIBS="-L/usr/local/android/install/libpng1626.armeabi/lib" CFLAGS="-mandroid -fomit-frame-pointer -Wno-format" LIBPNG_CFLAGS="-I/usr/local/android/install/libpng1626.armeabi/include" --disable-shared --host=arm-linux --build=i686-pc-linux-gnu --prefix="/usr/local/android/install/freetype265.armeabi"
make
make install
diff -ruN ../version/Pillow-master/setup.py Pillow-master/setup.py
--- ../version/Pillow-master/setup.py 2016-11-02 01:10:30.000000000 +0800
+++ Pillow-master/setup.py 2016-11-03 20:27:54.905900300 +0800
@@ -182,6 +182,7 @@
library_dirs = []
include_dirs = []
+ self.compiler.linker_so[0] = os.environ.get('CC')
_add_directory(include_dirs, "libImaging")
#
@@ -380,7 +381,9 @@
# between Python PYD stub libs and real libraries
self.compiler.library_dirs = library_dirs + self.compiler.library_dirs
- self.compiler.include_dirs = include_dirs + self.compiler.include_dirs
+ self.compiler.include_dirs = include_dirs # + self.compiler.include_dirs
+ self.compiler.include_dirs.remove('/usr/local/include')
+ self.compiler.include_dirs.remove('/usr/include')
#
# look for available libraries
@@ -395,7 +398,8 @@
elif (sys.platform == "win32" and
_find_library_file(self, "zlib")):
feature.zlib = "zlib" # alternative name
-
+ feature.zlib = "z" #====================
+
if feature.want('jpeg'):
_dbg('Looking for jpeg')
if _find_include_file(self, "jpeglib.h"):
@@ -559,7 +563,7 @@
exts = [(Extension("PIL._imaging",
files,
libraries=libs,
- define_macros=defs))]
+ define_macros=defs,extra_link_args = ['-Wl,-soname,_imaging.so']))]
#
# additional libraries
@@ -567,7 +571,7 @@
if feature.freetype:
exts.append(Extension("PIL._imagingft",
["_imagingft.c"],
- libraries=["freetype"]))
+ libraries=["freetype","png"],extra_link_args = ['-Wl,-soname,_imagingft.so']))
if feature.lcms:
extra = []
@@ -575,7 +579,7 @@
extra.extend(["user32", "gdi32"])
exts.append(Extension("PIL._imagingcms",
["_imagingcms.c"],
- libraries=[feature.lcms] + extra))
+ libraries=[feature.lcms] + extra,extra_link_args = ['-Wl,-soname,_imagingcms.so']))
if feature.webp:
libs = [feature.webp]
@@ -589,7 +593,7 @@
exts.append(Extension("PIL._webp",
["_webp.c"],
libraries=libs,
- define_macros=defs))
+ define_macros=defs,extra_link_args = ['-Wl,-soname,_webp.so']))
tk_libs = ['psapi'] if sys.platform == 'win32' else []
exts.append(Extension("PIL._imagingtk",
@@ -597,8 +601,8 @@
include_dirs=['Tk'],
libraries=tk_libs))
- exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"]))
- exts.append(Extension("PIL._imagingmorph", ["_imagingmorph.c"]))
+ exts.append(Extension("PIL._imagingmath", ["_imagingmath.c"],extra_link_args = ['-Wl,-soname,_imagingmath.so']))
+ exts.append(Extension("PIL._imagingmorph", ["_imagingmorph.c"],extra_link_args = ['-Wl,-soname,_imagingmorph.so']))
self.extensions[:] = exts
使用python2.7编译,首先设置交叉编译环境
export ANDROID_NDK="/usr/local/android/android-ndk-r10d"
export PATH="$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/:$ANDROID_NDK:$ANDROID_NDK/tools:/usr/local/bin:/usr/bin:/bin:$PATH"
export ARCH="armeabi"
export CFLAGS="-DANDROID -mandroid -fomit-frame-pointer --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm -I../starcore_for_android.2.5.1/python.files/python-2.7/armeabi/include/python2.7 -I/usr/local/android/install/jpeg9b.armeabi/include -I/usr/local/android/install/freetype265.armeabi/include"
export CXXFLAGS="$CFLAGS"
export CC="arm-linux-androideabi-gcc"
export LDFLAGS="-lm -L../starcore_for_android.2.5.1/python.files/python-2.7/armeabi -L/usr/local/android/install/jpeg9b.armeabi/lib -L/usr/local/android/install/freetype265.armeabi/lib -L/usr/local/android/install/libpng1626.armeabi/lib"
export CXX="arm-linux-androideabi-g++"
export AR="arm-linux-androideabi-ar"
export RANLIB="arm-linux-androideabi-ranlib"
export STRIP="arm-linux-androideabi-strip --strip-unneeded"
export READELF="arm-linux-androideabi-readelf"
export MAKE="make -j4 CROSS_COMPILE_TARGET=yes"
export LAPACK=
- import os, sys
- import traceback
- try:
- from PIL import Image
- print(Image)
- print(AppPath)
-
- im=Image.open(AppPath+"/dir.jpg")
- print(im.size)
- print(im.mode)
- print("===end===")
-
- except Exception,e:
- traceback.print_exc()
- python._Set("AppPath", "/data/data/"+getPackageName()+"/files");
- Service._DoFile("python", "/data/data/"+getPackageName()+"/files/test.py", "");
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。