Okay, in my app I can add custom markers with images taken from the camera intent, then that image is then displayed full screen when the user taps on the marker. Now for each marker added i had to use :
private Map<String, Bitmap> myMarkers;
then I needed to get the ID of the marker :
private String markerId;
....
markerId = marker.getId();
Then return that image to that specific marker:
Bitmap bitmap = myMarkers.get(marker.getId());
markerIcon.setImageBitmap(bitmap);
All good and working, now my question is what do i need to save to SQlite database?
Is it the myMarkers , the markerID or the bitmap or the imageData (seen in code below)?
baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, baos);
imageData = baos.toByteArray();
Or do I need to save all of them to the database?
Any help on this will be much appreciated!
create a column with imageData(Blob) and tag it to your markerid(Primary key). so that it is easy to get retrieve from the DB.
Related
Good morning, I'm using this Github library: https://github.com/burhanrashid52/PhotoEditor as photo editor. I have a GalleryFragment in which user choose image from his gallery, the I pass correctly the image to the EditImageActivity where user can apply sticker, filters, ecc. and then clicking on a button, user can pass the edited image to InfoActivity, where he can add other info and publish the image.
The problem is that when user edits an image and pass it to InfoActivity it is shown the original image without changes, and also when he publishes it, the image saved is the original, not the modified.
I'm trying to use Bitmap to do that:
This is the code of EditImageActivity where I try to send the edited image in a intent to InfoActivity:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bmp =((BitmapDrawable)mPhotoEditorView.getSource().getDrawable()).getBitmap();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Intent intent = new Intent(EditImageActivity.this, InfoActivity.class);
intent.putExtra("imm", byteArray);
startActivity(intent);
And this is the piece of code of InfoActivity, where I try to retrieve the intent with the edited image from EditImageActivity, to show it in a ImageView:
byte[] byteArray = getIntent().getByteArrayExtra("imm");
assert byteArray != null;
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
immagine.setImageBitmap(bmp);
So it works when user doesn't edit image, while when he edits image, it shows the original.
I think that the problem is in this code (the code that I use in EditImageActivity to get a bitmap of the edited image), because it passes the original image instead of the modified image:
Bitmap bmp =((BitmapDrawable)mPhotoEditorView.getSource().getDrawable()).getBitmap();
Can someone help me please?
Yes, it seems that the problem is when you fetch the edited image from your PhotoEditorView. If you see the documentation, to retrieve this image, is necessary to implement the next approach:
PhotoEditor.saveAsFile(filePath, new PhotoEditor.OnSaveListener() {
#Override
public void onSuccess(#NonNull String imagePath) {
Log.e("PhotoEditor","Image Saved Successfully");
}
#Override
public void onFailure(#NonNull Exception exception) {
Log.e("PhotoEditor","Failed to save Image");
}
});
So the library needs a file to save it and if is success, then returns the path file, with the path file you needs to create the Bitmap object.
I'm downloading some text and images from the server using AsyncTask. I'm storing the texts and images in sq-lite database. I'm storing in the form of byte array.
In post Execute method of AsyncTask I store the convert the images in byte array and store them in database using for loop.
Problem is when I display data in List View from database sometimes it displays the correct images but some times it displays wrong images. I'm using a handler to delay the information into List View by 8 seconds. I've no idea why sometimes it shows the correct images and sometimes it shows wrong images.
What I'm doing wrong? How can I display the correct image every time. Moreover Can anyone help me how can I avoid the log cat message :
"Skipped XXX frames. The application is doing to much work in main thread."
I'm using fragments. As the application starts it will get data from server and which includes URL to Image. I'm using that URL to download images. Storing both the texts and images in database and showing it in List View in onPostExecute method.
Below are the codes I've used:
// convert from bitmap to byte array
public static byte[] getBytes(Bitmap bitmap) {
ByteArrayOutputStream byteArrayOutputStream =
new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
In adapter class where I'm extending CursorAdapter class. I'm getting byte array from sq-lite database and converting it in image and display it to List View.
Code to convert from byte array to bitmap is below:
private static Bitmap getImage(byte[] image) {
return BitmapFactory.decodeByteArray(image, 0, image.length);
}
I'm setting it to list View item like this:
byte [] image = cursor.getBlob(imageColumnIndex);
if(image == null)
{
}else{
Bitmap bitmap = getImage(image);
imageView.setImageBitmap(bitmap);
}
I have successfully integrated facebook login in my android app.So I am displaying user profile data like name,email and picture.
Now I need to store user data such as name,email and profile picture in database. I know how to get the name and email since it can be get from TextViews. But I am struggling to get the profile picture.
The profile picture is displayed using ProfilePictureView.
I tried to convert that image on ProfilePictureView to byte array, but it is not working.(Normally this works with ImageView ,Imagebuttons, but it is not working with ProfilePictureView)
pic.setProfileId(user.getId());
ImageView imageView = (ImageView)pic.getChildAt(0);
Bitmap bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
image_ = convertImageToByte(bmp); //image_ is a byte[]
private byte[] convertImageToByte(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
return stream.toByteArray();
}
I am getting an image like this instead of the real profile picture.
Is there anyway to store the image? (like a link to get the profile picture to store so I can retrieve the image using the link at later time)
Thanks.
Try this. It worked for me
private ProfilePictureView profilepic;
In OnCreate Method type:
profilepic = (ProfilePictureView) findViewById(R.id.<profilepicture id>);
profilepic.setProfileId(id of user (string));
Hope it helps
i used this and it's working ok:
profileImageView = ((ImageView)faceBookProfilePictureView.getChildAt(0));
bitmap = ((BitmapDrawable)profileImageView.getDrawable()).getBitmap();
circular.setImageBitmap(bitmap);
where "circular" it's CircularImageView Object.
I am developing an offline application and I'm not getting any picture from user's gallery.
But I want to display the images to the users that I inserted manually.
The only solution I can think of is to put those images into drawable, then save it to the sqlite database (which I not sure how). Can this be done?
Thank you.
If you're willing to store the images in the drawable folders, you can store a reference to them in your database. Just store a string like com.example.yourapp:drawable/imagefilename and use this to display the image, where yourString contains the string from the database..
int imageResource = this.getResources().getIdentifier(yourString, null, null);
yourimageview.setImageResource(imageResource);
You can Use insert blob for this
public void insertImg(int id , Bitmap img ) {
byte[] data = getBitmapAsByteArray(img); // this is a function
insertStatement_logo.bindLong(1, id);
insertStatement_logo.bindBlob(2, data);
insertStatement_logo.executeInsert();
insertStatement_logo.clearBindings() ;
}
public static byte[] getBitmapAsByteArray(Bitmap bitmap) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, outputStream);
return outputStream.toByteArray();
}
I'm trying to share from my app to Hyves using share intent. If I have hyves app installed and share from gallery it switch to hyves app, and upload image correctly to hyves, so it should work.
Problem is, I can't find it documented how should proper intent for hyves work, but I assume that gallery uploads images only, so I have this:
Bitmap image = BitmapFactory.decodeFile(MyGlobals.INSTANCE.activeSetting.f_image_path);
It's line of code where I pull my "active" or "selected" image within my app. At this point image is saved to SD Card, so I might read uri instead of decoding file, but I want it this way to have same approach for both hyves and facebook.
Then I call:
Intent hyvesIntent = new Intent(Intent.ACTION_SEND);
hyvesIntent.setPackage("com.hyves.android.application");
hyvesIntent.setType("image/jpeg");
hyvesIntent.putExtra("image", image);
startActivityForResult(hyvesIntent, 666);
First of all, I'm not sure if setPackage is OK to be used here, but I'm checking if this package exist to enable / disable share, and this is package name that is visible.
I need Activity result to then notify that Image is shared or not.
What happens here it starts the Hyves app, but I get full white screen, and then the Hyves app times out.
So, Can I use Bitmap in intent, and is it OK to setPackage or should I setClass?
Tnx
Maybe you can not put the bitmap directly in the intent.
First convert the bitmap into a byte array than send another side and convert into bitmap
//convert bitmap to bytearray
public static byte[] getBitmapAsByteArray(Bitmap bitmap, boolean type) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
if (type) {
bitmap.compress(CompressFormat.PNG, 0, outputStream);
} else {
bitmap.compress(CompressFormat.JPEG, 0, outputStream);
}
return outputStream.toByteArray();
}
//convert bitmap to bytearray
public static Bitmap getBitmap(byte[] imgByte){
Bitmap bm = BitmapFactory.decodeByteArray(imgByte, 0, imgByte.length);
return bm;
}
//than intent
Intent hyvesIntent = new Intent(Intent.ACTION_SEND);
hyvesIntent.setPackage("com.hyves.android.application");
hyvesIntent.setType("image/jpeg");
hyvesIntent.putExtra("image", getBitmapAsByteArray(image,true));
startActivityForResult(hyvesIntent, 666);
I hope that is right way to put image