cats-oss / android-gpuimage

Android filters based on OpenGL (idea from GPUImage for iOS)
8.98k stars 2.26k forks source link

GPUImage saving problem #78

Open gasstan opened 10 years ago

gasstan commented 10 years ago

package com.example.edgedetect;

import jp.co.cyberagent.android.gpuimage.GPUImage; import jp.co.cyberagent.android.gpuimage.GPUImageFilter; import jp.co.cyberagent.android.gpuimage.GPUImageSobelEdgeDetection; import jp.co.cyberagent.android.gpuimage.GPUImageView;

import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent photoPickerIntent = new Intent(
            Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, 100);     

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 100 && resultCode == RESULT_OK) {            

        Uri imageUri = data.getData();
        GPUImage mGPUImage = new GPUImage(this);            
        mGPUImage.setFilter(new GPUImageSobelEdgeDetection());
        mGPUImage.setImage(imageUri);
        Toast.makeText(getApplicationContext(), imageUri.getPath(), Toast.LENGTH_LONG).show();
        // Later when image should be saved saved:
        mGPUImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);          
    } 
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

hi this is my cod but when i try to run it it show me an error: Android Runtime FATAL EXCEPTION: AsyncTask #2 An error occured while executing doInBackground() at java.lang.Thread.run(Thread.java:856) Caused by: java.lang.NullPointerException at jp.co.cyberagent.android.gpuimage.GPUImage.getBitmapWithFilterApplied(GPUImage.java:279)

when i move mGPUImage.saveToPictures to comment block it doesn't crash so i think ther is some problem ...can you help me ?

jeetdholakia commented 10 years ago

i have the same issue, how did you manage to solve it,if you could ?

AndreiD commented 8 years ago

up ? anyone knows how to work with the save ?

wakedeer commented 8 years ago

i have some problem!!!

imandaliya commented 8 years ago

saveToPictures is depricated.

use object of GPUImageView and capture as bitmap.

Bitmap bitmap = gpuImageView.capture();

now save bitmap as image in any of location.

Hitexroid commented 7 years ago

for save image , use this :

private void saveImage() {

    String FileName = System.currentTimeMillis() + ".jpg";
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File file = new File(path, "GPUImage" + "/" + FileName);
    file.getParentFile().mkdirs();`

    FileOutputStream out = null;
    Bitmap bitmap = mGPUImageView.getGPUImage().getBitmapWithFilterApplied();
    try {
        out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}`
developer-- commented 6 years ago

mGPUImageView.getGPUImage().getBitmapWithFilterApplied(); thows NullPointerException

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at jp.co.cyberagent.android.gpuimage.GPUImage.getBitmapWithFilterApplied(GPUImage.java:308) at jp.co.cyberagent.android.gpuimage.GPUImage.getBitmapWithFilterApplied(GPUImage.java:272)