Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obtainBitmap() not returning the drawn image #6

Closed
Odaym opened this issue Mar 29, 2015 · 9 comments
Closed

obtainBitmap() not returning the drawn image #6

Odaym opened this issue Mar 29, 2015 · 9 comments
Labels

Comments

@Odaym
Copy link

Odaym commented Mar 29, 2015

I use the drawableView to draw something and it works fine and everything but when I want to grab the bitmap from the drawableView I do not get the bitmap back correctly.

I have verified this by saving the bitmap from obtainBitmap() into a file on the device and uploaded to dropbox to see the picture. The file always has the size of 0.91 KB and consists of a rectangular, background-less area.

If you want, here's a link to the image, it's empty of course but you can save it and check the size and how the predefined rectangular shape is there: http://i.imgur.com/0EZn7Gz.png

Any ideas? Thanks!

@Odaym
Copy link
Author

Odaym commented Mar 29, 2015

Just to be clear, I try this with the press of a button after I've drawn some lines I call drawableView.obtainBitmap(), that's it.

@PaNaVTEC
Copy link
Owner

I'll check it asap. 👍

@PaNaVTEC
Copy link
Owner

PaNaVTEC commented Apr 3, 2015

Hi, @Odaym show me your code to obtain the bitmap, I'm trying saving the bitmap with the sample and is working Ok.

@Odaym
Copy link
Author

Odaym commented Apr 4, 2015

What I'm trying to do with this is allow the user to draw something over an ImageView with a picture loaded in the Activity. Upon pressing Save, I grab the bitmap from drawableView and I grab the picture loaded into the ImageView and I combine them and save them as one image.

For now, the code below stores the bitmap from the drawableView onto the device and loads it instead of the picture in the ImageView (instead of the picture that was there), this is just for testing whether the bitmap will be saved or not.

And the file I linked to above I got it from going to the device and seeing the saved file of the bitmap, but it was empty

fabActionUndo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Picasso.with(Test_Activity.this).load(new File(storeImage(drawableView.obtainBitmap()))).into(tstImageView);

                //sometimes I call clear just to see only the imageview without the stuff I've just drawn on the bitmap. Whether it's there or not, same outcome happens with empty image file
                //drawableView.clear();
            }
        });

private String storeImage(Bitmap image) {
        File pictureFile = createImageFile();
        if (pictureFile == null) {
            Log.d("TAG",
                    "Error creating media file, check storage permissions: ");
            return "";
        }
        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            image.compress(Bitmap.CompressFormat.PNG, 90, fos);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d("TAG", "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d("TAG", "Error accessing file: " + e.getMessage());
        }

        Log.d("IMAGE", "PATH OF DRAWABLE VIEW IS : " + pictureFile.getAbsoluteFile());

        return pictureFile.getAbsolutePath();
    }

@Odaym
Copy link
Author

Odaym commented Apr 4, 2015

Chris, the feature/limit_canvas_size branch included the fix for this issue. I didn't change any code at all from what I pasted above when I ran the project. I just wanted to test the canvas height and thought I'd also try the obtainBitmap() cause you said it was working fine. So I found it working fine, strangely

@PaNaVTEC
Copy link
Owner

PaNaVTEC commented Apr 5, 2015

Ok, re-open this if the issue returns.

@PaNaVTEC PaNaVTEC closed this as completed Apr 5, 2015
@Odaym
Copy link
Author

Odaym commented Apr 8, 2015

Hi Chris, today I just pulled 0.6.0 and it worked fine and included both fixes that were in limit_canvas_size, I don't have to import that branch as a library anymore. Just wanna thank you 👍

@PaNaVTEC
Copy link
Owner

PaNaVTEC commented Apr 8, 2015

thanks to you for using it :)

@imsocb
Copy link

imsocb commented Dec 19, 2016

Hi Chris, Sorry for bringing up the topic again. I'm having similar issue saving the background image with the drawn paint together onto the same bitmap. Hope you can offer me some advice on that. Thanks

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode == RESULT_OK){
            if(requestCode == CAMERA_REQUEST){
                                OriginalBitmap = getRotatedBitmap(bitmap,90);

                                drawableView.setBackground(new BitmapDrawable(getResources(), OriginalBitmap));
                                config.setStrokeColor(Color.BLUE);
                                config.setShowCanvasBounds(true); 
                                config.setStrokeWidth(50.0f);
                                config.setCanvasHeight(height);
                                config.setCanvasWidth(width);
                                drawableView.setConfig(config);
}
}
}

ivSavesetOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {

                    OriginalBitmap = ImageLoader.init().from(selectedPhoto).requestSize(512,512).getBitmap();

                    try {
                        OriginalBitmap = drawableView.obtainBitmap(OriginalBitmap);  
// Tried OriginalBitmap = drawableView.obtainBitmap(); however, on the server it store only the drawn bitmap and internal memory only the background image.
                        storeImage(OriginalBitmap);
                    }
                    catch (IOException e) {
e.printStackTrace();  
                    }
}
String encodedImage = ImageBase64.encode(OriginalBitmap);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants