Converting FrameLayout as Bitmap - android

I have a FrameLayout that consist some Image views & one EditText. I am saving this layout as an image in the memory (external). First time when I set the images in imageviews everything goes fine i.e. the exact image is being saved (same as displaying on screen) but when after saving first time if I change any thing (text, image) it displays correctly on screen but in saved image it displays earlier image (first image).
XML of Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/imageWithoutFrame"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_centerInParent="true" >
<ImageView
android:id="#+id/withoutFrame_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/background" />
<ImageView
android:id="#+id/withoutFrame_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:layout_gravity="center" />
<EditText
android:id="#+id/withoutFrame_editableText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="30dip"
android:hint="Write here"
android:maxLength="60" />
</FrameLayout>
</RelativeLayout>
Code that change it in bitmap is:
Bitmap bm = null;
FrameLayout savedImage = null;
savedImage = (FrameLayout)findViewById(R.id.imageWithoutFrame);
savedImage.setDrawingCacheEnabled(true);
savedImage.buildDrawingCache();
bm = savedImage.getDrawingCache();
I used this bm for saving.
Thanks for helping.

to overcome with this problem I destroy the drawingcache after saving the image.
savedImage.destroyDrawingCache();

Related

How to make image fit the whole width screen without blank space in android?

Tried to make image taken to fit the whole screen size width, and top
Picture output should be like this:
The output on the screen of my app is as below with blank space on top, left and right side.
My XML for the activity layout is below:
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/vestGlavnaSlikaLayout"
android:layoutDirection="ltr">
<ImageView
android:id="#+id/iv"
android:layout_width="match_parent"
android:fitsSystemWindows="false"
android:scaleType="fitXY"
android:layout_marginTop="-20dp"
android:focusable="false"
android:cropToPadding="false"
android:adjustViewBounds="true"
android:layout_alignParentBottom="false"
android:layout_alignParentRight="false"
android:layout_height="wrap_content"
android:layout_marginLeft="-20dp"
android:layout_alignParentEnd="false"
android:layout_marginRight="-20dp" />
<TextView
android:background="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tekstglavnevesti"
android:textColor="#android:color/background_light"
android:textSize="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:textStyle="normal|bold" />
</RelativeLayout>
My code to display the image:
ImageView iv = (ImageView) v. findViewById(R.id.iv);
Picasso.with(getActivity()).load(slikeZaVesti.get(0))
.into(iv); // jpg tag is pasrsed from html
As you l might observe, there are blank spaces at both left and right side of the image. Any way to make the image fit perfectly onto the screen?

Scale and rotate an image in android - image won't appear

I am new to android, and I am having problems making my image appear in my second activity after I use the same scale and rotate code with my first activity.
In first activity I am currently retrieving an image from the photo gallery. This image I then display in an ImageView. Before I actually display the image I have to scale the bitmap and then rotate it. This is working - and I got most of the code from this site - thanks! I then save the details of this image to my SQLite database (as in the path name of image on sd card)
However, in the second activity - I am then trying to retrieve the image immediately for display in an imageview (from it's pathname - which I have saved to SQLite database), and again I use the same code to scale and rotate the same image to display in this ImageView, however this time, the image does not appear.....? If I just execute the code for scaling the bitmap - the image does appear, but it is only when I try to execute the rotate code that the image won't appear. As said - in first activity - the scale AND rotate works, but for second activity - only the scale works.
Here is the code for scaling and rotating
public static void process (String filePath, ImageView imageView) {
Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath);
int h = 250;
int w = 250;
Bitmap scaled = Bitmap.createScaledBitmap(yourSelectedImage, h, w, true);
Matrix matrix = new Matrix();
imageView.setScaleType(ScaleType.MATRIX);
imageView.setImageBitmap(scaled);
matrix.postRotate(90f, imageView.getDrawable().getBounds().width()/2,
imageView.getDrawable().getBounds().height()/2);
imageView.setImageMatrix(matrix);
}
XML of first activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/result"
android:layout_width="250dip"
android:layout_height="250dip"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:contentDescription="#string/desc1"
android:scaleType="matrix" />
<Button
android:id="#+id/selectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/textView2"
android:layout_marginBottom="15dp"
android:text="Select Photo" />
<Button
android:id="#+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/selectButton"
android:layout_alignParentRight="true"
android:layout_marginBottom="15dp"
android:layout_marginRight="27dp"
android:text="Save" />
<LinearLayout
android:id="#+id/addbloglinkcontainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/result" >
<TextView
android:id="#+id/addbloglinktext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_blog_link" />
<EditText
android:id="#+id/blogLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:ems="10"
android:inputType="textUri" />
</LinearLayout>
</RelativeLayout>
XML of second activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView"
android:layout_width="250dip"
android:layout_height="250dip"
android:layout_alignParentTop="true"
android:layout_marginTop="40dp"
android:contentDescription="#string/desc1"
android:onClick="mthdtocall"
android:scaleType="matrix" />
</RelativeLayout
Dont know why the image doesnt appear but... You could try to use LRU cache to reuse the same bitmap image in both activities.
developer.android.com/reference/android/util/LruCache.html

Android mask a bitmap with a transparent png

I have a png image with some transparent areas (like gradient-transparent) and I'd like to "add" this image to over a Bitmap and create a new Bitmap from these two.
is this possible in Android?
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="sliding banner here" />
<ImageView
android:id="#+id/slider_des"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginTop="40dp"
android:hint="text"
android:paddingBottom="20dp"
/>
</FrameLayout>
The above code can be modified to achieve what you want! the first imageview would be for your bitmap and 2nd for overlapping image view that you can placeyour transparent png in.

How to increase size of posted pictures from facebook api?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dip"
android:background="#drawable/greybox"
>
<ImageView
android:id="#+id/profile_pic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/profile_pic">
<TextView
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Kumar"
android:textSize="18dp"
android:textColor="#4c3f38"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="#+id/msg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_below="#+id/name"
android:textColor="#7b7674"
/>
<LinearLayout
android:id="#+id/picpostlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_marginTop="5dp"
android:layout_below="#+id/msg"
android:orientation="vertical" >
<ImageView
android:id="#+id/picpost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#null" />
</LinearLayout>
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/picpostlayout"
android:layout_alignParentRight="true"
android:textColor="#000000"
/>
</RelativeLayout>
</RelativeLayout>
Here is my complete xml.I am using the linearlayout to show the posted picture,but it is still showing very small size.I used two relative layouts, one for complete xml and another for name,message,postpicture.
Here is also my screenshot to the above given xml file.I am getting the large image but I cant able to show the same size,it is showing very small size.
I got an post picture from facebook api,I am getting very large image as I used _n.jpg,but when I tried to display using imageview it is showing very small size.
][1]
[1]: http://i.stack.imgur.com/63nTO.png
Here is the code of getting posted picture from facebook api.If the post object has picture field then I get that picture and changed that into large image and I added that to my ArrayList pic.
if(jsonObject.has("picture"))
{
String fetchedURL = jsonObject.getString("picture");
String getFeedPicture = fetchedURL.replaceAll("_s.jpg", "_n.jpg");
pic.add(getFeedPicture);
}
Then I send that ArrayList to my Adapter where I set that image to imageview by sending to imageloader class.
Here is my loader class reference imageloader and I am setting image to imageview.I am setting this in my adapter class.
imageLoader.DisplayImage(postimage.get(position).replace(" ", "%20"), postimg) ;
Make this modification to your current code:
String fetchedURL = JOFeeds.getString("picture");
String getFeedPicture = fetchedURL.replaceAll("_s.jpg", "_n.jpg");
pic.add(getFeedPicture);
This is the simplest way to get a better quality picture from your Feeds. The whole point of this piece of code is that by default, the Facebook API returns a small version of the image. By replacing the _s.jpg with _n.jpg gives you a bigger image.
I use this code throughout my application and it works like a charm every single time.
And the corresponding code for this is:
<LinearLayout
android:id="#+id/linlaFeedPicture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:layout_margin="1dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imgvwFeedPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#null" />
</LinearLayout>

filling whole screen with background image!

hii! i am trying to fill an image onto my screen, but it is just covering around 75-80% part of whole screen, not whole screen .the codeblock i am using is as:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
and main.xml code snippt:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/homepage_image"
android:gravity="center"
><ImageButton
android:id="#+id/btnSequence"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/btn_sequence"
android:gravity="center_vertical"/>
<ImageButton
android:id="#+id/btnVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/btn_video"
android:gravity="center_vertical"
/>
<ImageButton
android:id="#+id/btnInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/btn_info"
android:gravity="center_vertical"
/>
</LinearLayout>
thanks
If image is less than device screen size android will default to that android:gravity="center" command that you gave it..is the image centered on screen? If so than that might be what is occurring..in which case you need to edit image to screen size of the device.
On my xml I do this to fill the hole screen with an image view:
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
**android:scaleType="fitXY"**
android:src="#drawable/*drawablename*" />
Of course be careful about the size and resolution of you image.

Categories

Resources