android gpuimage
1.0.0
想法來自:iOS GPUImage框架
目標是擁有盡可能類似於 GPUImage 的東西。頂點著色器和片段著色器完全相同。這樣可以更輕鬆地將濾鏡從 GPUImage iOS 移植到 Android。
repositories {
mavenCentral()
}
dependencies {
implementation ' jp.co.cyberagent.android:gpuimage:2.x.x '
}
爪哇:
@ Override
public void onCreate ( final Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity );
Uri imageUri = ...;
gpuImage = new GPUImage ( this );
gpuImage . setGLSurfaceView (( GLSurfaceView ) findViewById ( R . id . surfaceView ));
gpuImage . setImage ( imageUri ); // this loads image on the current thread, should be run in a thread
gpuImage . setFilter ( new GPUImageSepiaFilter ());
// Later when image should be saved saved:
gpuImage . saveToPictures ( "GPUImage" , "ImageWithFilter.jpg" , null );
}
科特林:
public override fun onCreate ( savedInstanceState : Bundle ? ) {
super .onCreate(savedInstanceState)
setContentView( R .layout.activity_gallery)
val imageUri : Uri = .. .
gpuImage = GPUImage ( this )
gpuImage.setGLSurfaceView(findViewById< GLSurfaceView >( R .id.surfaceView))
gpuImage.setImage(imageUri) // this loads image on the current thread, should be run in a thread
gpuImage.setFilter( GPUImageSepiaFilter ())
// Later when image should be saved saved:
gpuImage.saveToPictures( " GPUImage " , " ImageWithFilter.jpg " , null )
}
< jp .co.cyberagent.android.gpuimage.GPUImageView
android : id = " @+id/gpuimageview "
android : layout_width = " match_parent "
android : layout_height = " match_parent "
app : gpuimage_show_loading = " false "
app : gpuimage_surface_type = " texture_view " /> <!-- surface_view or texture_view -->
爪哇:
@ Override
public void onCreate ( final Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState );
setContentView ( R . layout . activity );
Uri imageUri = ...;
gpuImageView = findViewById ( R . id . gpuimageview );
gpuImageView . setImage ( imageUri ); // this loads image on the current thread, should be run in a thread
gpuImageView . setFilter ( new GPUImageSepiaFilter ());
// Later when image should be saved saved:
gpuImageView . saveToPictures ( "GPUImage" , "ImageWithFilter.jpg" , null );
}
科特林:
public override fun onCreate ( savedInstanceState : Bundle ? ) {
super .onCreate(savedInstanceState)
setContentView( R .layout.activity_gallery)
val imageUri : Uri = .. .
gpuImageView = findViewById< GPUImageView >( R .id.gpuimageview)
gpuImageView.setImage(imageUri) // this loads image on the current thread, should be run in a thread
gpuImageView.setFilter( GPUImageSepiaFilter ())
// Later when image should be saved saved:
gpuImageView.saveToPictures( " GPUImage " , " ImageWithFilter.jpg " , null )
}
爪哇:
public void onCreate ( final Bundle savedInstanceState ) {
public void onCreate ( final Bundle savedInstanceState ) {
Uri imageUri = ...;
gpuImage = new GPUImage ( context );
gpuImage . setFilter ( new GPUImageSobelEdgeDetection ());
gpuImage . setImage ( imageUri );
gpuImage . saveToPictures ( "GPUImage" , "ImageWithFilter.jpg" , null );
}
科特林:
public override fun onCreate ( savedInstanceState : Bundle ? ) {
super .onCreate(savedInstanceState)
setContentView( R .layout.activity_gallery)
val imageUri : Uri = .. .
gpuImage = GPUImage ( this )
gpuImage.setFilter( GPUImageSepiaFilter ())
gpuImage.setImage(imageUri)
gpuImage.saveToPictures( " GPUImage " , " ImageWithFilter.jpg " , null )
}
確保在使用 Maven 時運行乾淨的目標。
gradle clean assemble
Copyright 2018 CyberAgent, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.