Scale Animation for Image, NOT ImageView - android

I'm able to do a scale animation on an imageview but the view crops the image when it's set.
I need to accomplish a scale animation on the image itself because scaling down the view reveals the cropped edges
Is this possible without a frame-by-frame animated drawable?
I don't have any code to share because I'm not even sure where to start

You should scale it's bitmap like this:
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
//replace first `120` with your target width and second `120` with your target height
imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false));

Related

Converting imageview pixels to bitmap pixels after gesture

I have an imageview, I want to convert the touch event on the image to its corresponding pixel on the orginal bitmap (even after the image has been gesture scaled or flinged).
How can this be achieved?
Thanks

How to screen shot a ImageView without lost quality

I have two ImageView's in a RelativeLayout, the first one is as large as the RelativeLayout size (as background),and the second ImageView has a small image, now I want to combine these to ImageView's image into one by screenshot. not by combine two bitmap directly.
In the snippet below, I successfully take screenshot of the RelativeLayout, but I found the image quality is not as good as the first ImageView's bitmap, can anyone help me please?
view.setDrawingCacheEnabled(true);
view.setDrawingCacheBackgroundColor(Color.TRANSPARENT);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
Bitmap drawCache = view.getDrawingCache(true);
Try to get bitmap using window DecorView :
View window = activity.getWindow().getDecorView()
Canvas bitmapCanvas = new Canvas();
Bitmap bitmap = Bitmap.createBitmap(window.getWidth()*2, window.getHeight()*2, Bitmap.Config.ARGB_8888);
bitmapCanvas.setBitmap(bitmap);
bitmapCanvas.scale(2.0f, 2.0f);
window.draw(bitmapCanvas);
bitmap.compress(Bitmap.CompressFormat.PNG, 0, myOutputStream);
Ref : High resolution screen shot in Android

How do I configure ImageView to display subrect of bitmap in Android?

I have a view that contains an ImageView. The ImageView is populated with a png resource, and fills the width and height of the image view.
Instead of this configuration, I would like to display the image zoomed in by an arbitrary percentage, and translated by an arbitrary coordinate. My question is, how can I configure an image view to display a sub-region of it's src bitmap, with arbitrary translation?
You can do this with matrix scaleType
Make a ImageView to have matrix scaleType, android:scaleType="matrix"
Create and manipulate a Matrix like this,
Matrix matrix = new Matrix();
matrix.postTranslate(-10, -10);
matrix.postScale(2, 2);
set this matrix to ImageView, imageView.setImageMatrix(matrix)

How to get scaled Bitmap from ImageView

I am having a Activity which has a custom ImageView defined in the XML for Pinch Zoom functionality on an image. Now, my problem is that I want to fetch the scaled Bitmap from the Pinch Zoom functionality. For example if the user peforms zooming on the Image, then I want to store the exact size and the position of the Image as Bitmap.
This is my custom ImageView declared in XML.
<com.cam.view.PinchZoom_ImageView
android:id="#+id/gallery_selected_image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/icon"
android:scaleType="center"
/>
UPDATE:
I am trying the below code to get the scaled Image, but It returns a Blank Bitmap.
pinchZoom.setDrawingCacheEnabled(true);
pinchZoom.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
pinchZoom.layout(0, 0, pinchZoom.getMeasuredWidth(), pinchZoom.getMeasuredHeight());
pinchZoom.buildDrawingCache(true);
Bitmap_gallery_Item = Bitmap.createBitmap(pinchZoom.getDrawingCache());
pinchZoom.setDrawingCacheEnabled(false);
Any help would be appreciated. Thanks
Well, finally I can't believe that it was just a one line code. I finally succeeded using the matrix. The solution is very simple that I was storing the translation and scaling of the Image in a matrix. So, I declared that final matrix as public static and used that matrix to create draw a Bitmap on canvas.
Canvas comboImage = new Canvas(cs);
background = Bitmap.createScaledBitmap(background, width, height, true);
comboImage.drawBitmap(background, 0, 0, null);
comboImage.drawBitmap(foreground, PinchZoom_ImageView.matrix, null);
As you can see here PinchZoom_ImageView.matrix. It is a matrix that contains my final position of the scaled and translated image which I had declared as public static.
If you have scaleType="fitxy" then you can use a scaling factor to enlarge or shrink the width/height of the ImageView - It also means that you can pull back the exact height/width of the image because it has the same dimensions as it's container.
HTH
This post includes Cropping the Image from the Gallery and allows user to crop the Image and save the cropped Image and Shows in ImageView.
Seems it will help you some extends
Image Crop and show cropped Image in View

set image size to full screen in android

I'm having an android app in which I'm taking a picture using the android camera.
This picture is taken in the activity A and after that is sent to activity B where is edited.
This is how I receive my image in activity B:
Bundle extras = getIntent().getExtras();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 5;
byte[] imageData = extras.getByteArray("imageData");
Bitmap myImage = BitmapFactory.decodeByteArray(imageData , 0, imageData.length,options);
Matrix mat=new Matrix();
mat.postRotate(90);
bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(), myImage.getHeight(), mat, true);
ImageView imageView = (ImageView) findViewById(R.id.myPic);
imageView.setImageBitmap(bitmapResult);
As you can see I'm rotating the bitmap I receive with 90 using this:
Matrix mat=new Matrix();
mat.postRotate(90);
And here is my imageView in xml file:
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/myPic"
/>
The problem that I'm facing is that my picture is not full screen...it's almoust full screnn but not entirly.As you can see here:
If you could help me to increase a little bit its size I would really apreciate it.Thanks
EDIT:I wanna increase the width of my image only.Sorry!!
You can use ImageView.ScaleType
ImageView.ScaleType="CENTER_CROP"
You might have to crop the image. Because the image is not at its full height, the width of the image is proportionately scaled down, hence the black strips at the sides.
To be more specific, images taken using the phone's camera are probably intended to fit the screen exactly i.e. width-height ratio of image = width-height ratio of the screen. However, in your app the height of the image is constrained by the buttons at the top, so in order to maintain the width-height ratio of the image, the width of the image is scaled down proportionately.
Please refer to setScaleType
You could use CENTER_CROP to get full screen image and maintain the image's aspect ratio.

Categories

Resources