Closed Odaym closed 9 years ago
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.
I'll check it asap. :+1:
Hi, @Odaym show me your code to obtain the bitmap, I'm trying saving the bitmap with the sample and is working Ok.
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();
}
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
Ok, re-open this if the issue returns.
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 :+1:
thanks to you for using it :)
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);
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!