I follow this http://www.androidhub4you.com/2012/07/how-to-crop-image-from-camera-and.html to crop image.
I have 4-5 ImageView in a collage frame.In All Imageview i have set a default image.On click on particular imageview, I am selecting Image from gallery then crop the Image. Now I have to set the cropped Image in my ImageView. So after setting the cropped Image my ImageView get re-size, and because of it other ImageView's size also differ. I want while i am setting the cropped image in Imageview my ImageView must not re-size.
The size of resulted cropped Image may different so I took the ImageView Size before cropping, And after cropping I am scaling result bitmap as the same size of my Image view.
Coding sample is given blow.
I am getting height and width of my Imageview like this
viewhight = tempView.getMeasuredHeight();
viewWidth = tempView.getMeasuredWidth();
After cropping Image I scaled Image according to height and width of my view like this
Bitmap photobitmap1 = Bitmap.createScaledBitmap(photobitmap, viewWidth,viewhight, true);
After this i changed it into drawable like this and set it on my Imageview.
Drawable drawble = new BitmapDrawable(getResources(),photobitmap1);
tempView.setBackground(drawble);
but on setting the hight and width of my view get resized and because of this near Image view also get resized why I don't know.because i converted my imageview in the same size of view.
I also tried this to scale bitmap :
Bitmap photobitmap1 = Bitmap.createScaledBitmap(photobitmap, (viewWidth-30), (viewhight-30), true);
and this to set bitmap :
tempView.setImageBitmap(photobitmap1);
tempView.setBackgroundColor(Color.TRANSPARENT);
but nothing worked.
my xml code is like this:
<LinearLayout
android:id="#+id/fst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/frame"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="85dp"
android:paddingRight="85dp"
android:paddingTop="10dp"
>
<ImageView
android:id="#+id/viw_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="2.5dp"
android:layout_weight="1"
android:background="#drawable/rec"
/>
<ImageView
android:id="#+id/viw_2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="2.5dp"
android:background="#drawable/rec"
/>
</LinearLayout>
can any one help me please .....
Are you setting a fixed height and width for the imageview in the XML ?
Example:
<ImageView
android:layoutWidth="60dp"
android:layoutHeight="60dp" />
Related
I use TextView and drawableRight:
<TextView
android:id="#+id/text1_2"
android:drawableRight="#drawable/star"
android:layout_width="match_parent"
android:layout_height="20dp"
android:textColor="#color/grey_500"
android:textSize="#dimen/category_bottom_text_size" />
But the image does not scale according to the textView's height and just crops. I tried different solutions, such as using a bitmap file for this image and making the image .9, but the result was the same.
Try to used.. textview in image scale
android:scaleX="0.5"
android:scaleY="0.5"
I'm trying to set drawable at ImageView where I'm generation drawable by image bitmap of intrinsicWidth and height 160 and imageview width is 36dp but still image not setting in 36dp imageview.
Image is looking more smaller than imageview.
Please help me.
<ImageView
android:id="#+id/img_doctor"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_centerVertical="true"
android:scaleType="centerCrop" />
Drawable drawable11 = new BitmapDrawable(getResources(),myBitmap);
Log.e("", ""+drawable11.getIntrinsicWidth()+"::"+drawable11.getIntrinsicHeight());
imgView.setImageDrawable(drawable11);
Here I'm getting 160::160 in logcat.
if you have bitmap already then use imgView.setImageBitmap(myBitmap) instead of converting bitmap to drawable.
I am trying to set bitmap to imagebutton but image size change
My Image xml is
<ImageButton
android:id="#+id/button_ChoosePicFIrst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#drawable/choose_pic"
android:tag="PIC1" />
i want to set image size accoring to the "#drawable/choose_pic" size
after choosing image from gallery i am convertin it to bitmap and it change the imagebutton size please give me some solution ?
//for that use ImageView with src
<ImageView
android:id="#+id/button_ChoosePicFIrst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="#drawable/choose_pic"
android:tag="PIC1" />
As you are using ImageButton you need to set your image in property android:src="" not as background of your ImageButton.
So set your image in src property and remove background as below:
<ImageView
android:id="#+id/button_ChoosePicFIrst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:src="#drawable/choose_pic"
android:tag="PIC1" />
EDITED:
Difference between android:background" and android:src"
android:background exists for all the view. As the name suggests this is what is going to be there in the background.
android:src exists for ImageViews and its subclasses. You can think of this as the foreground. Because ImageView is a subclass of View you even have android:background for that.
If you set an image to be the background of your ImageView, then the image will scale to whatever size the ImageView is. Other than that, src is a foreground image and background is a background image.
The src to an ImageView has additional features:
different scaling types
adjustViewBounds for setting bounds to match image dimensions
some transformations such as alpha-setting
And more that you may find in the docs.
I have image view inside frame layout ,i put random sticker on image view at run time but when i save image bitmap using frame layout drawing-catch then image save but with unnecessary black part comes in saved image.
i want bitmap without this black part.Please help.Here is my layout and code.
<FrameLayout
android:id="#+id/fl_effect_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_title"
android:layout_marginBottom="83dp" >
<ImageView
android:id="#+id/im_gselected_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
</ImageView>
</FrameLayout>
Here is code that i use to create bitmap.
FrameLayout fl=(FrameLayout) findViewById(R.id.fl_effect_view);
f1.setDrawingCacheEnabled(true);
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache());
f1.setDrawingCacheEnabled(false);
Try to set the size of the view before you get the Drawing Cache:
ImageView bottomImage = (ImageView) findViewById(R.id.im_gselected_image);
f1.layout(0, 0, bottomImage.getMeasuredWidth(), bottomImage.getMeasuredHeight());
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache(true));
This will force your result to have a specific size and position, and will crop everything that is out of your defined bounds.
Please, let me now if this worked for you.
I have downloaded a Bitmap from a WebService, and set it to an ImageView. The ImageView has a set height of 120dip and a width set to FILL_PARENT, so it fills the complete width of the screen. Now i want to stretch the Bitmap to fit the width of the ImageView, but the if the height of the Bitmap is greater then the height of the ImageView, i want the remainder of the image to flow off the top and bottom of the ImageView. So in way, like i have a frame infront of the image and the only portion of the image visible is the contents of the frame. How can i do this ?
See Android Developers on ImageView ScaleType
You are interested in the scale_type enum. Use CENTER_CROP.
Here is complete example:
<ImageView android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_gravity="center"
android:src="#drawable/eureka"
android:scaleType="centerCrop">
</ImageView>
Here is also a cool visualization of all possible options for ImageView.