Convert view into high quality image - android

i converted a view into image using this
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
this bitmap image is not good quality and distorted, i want high quality image.
please tell me how to make high quality image of a view in Android.
i want image like this
but this which i am getting is distorted

Related

Android ImageView get bitmap after zoom using setImageMatrix

In Android I have an ImageView which user can manipulate the position and zoom level in the UI.
Is it possible to get the zoomed image (changed image) from the ImageView instead of original one.
Here are the methods I tried but no use.
imageView.buildDrawingCache(true);
Bitmap bmp = imageView.getDrawingCache(true);
I can get the Matrix but don't know how to use it.
Matrix m = imageView.getImageMatrix();
The zoom effect is applied at the Canvas level. So, what you can do is get the current Canvas augmentations and then draw your Bitmap into a new one with the changes.
Matrix transformMatrix = imageView.getImageMatrix()
Bitmap original = bmp;
Bitmap adjusted = Bitmap.createBitmap(original.getWidth(),
original.getHeight(),
original.getConfig());
Canvas canvas = new Canvas(adjusted);
canvas.setMatrix(transformMatrix);
canvas.drawBitmap(original, 0, 0, null);
//at this point adjusted bitmap contains the zoomed image
When you get a Matrix from an ImageView, make changes to t, then use imageView.setImageMatrix(m) apply the changes back to the ImageView. You will want to look into using one of the postScale() matrix methods to make a change in the size of image rendered.

How to add rainbow gradient to an Image in android

I want to add Transparent Rainbow or Spectrum Gradient to Bitmap.
In photoshop it is very easy. Now I want to do it programmatically. I have gone through a lot of research. But gradient has only one starting color and one ending. How could I add the rainbow color(multiple color) Gradient in Android.
Or is there a way to add that effect to bitmap in Android? Like given
for this you can use a translucent image with the desired gradient and put it on top of your image view in a FrameLayout. then capture bitmap of the view.
once you get your layout ready use this answer to capture bitmap from it
try this to convert a view (framelayout) into a bitmap:
public Bitmap viewToBitmap(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}

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

Android gradient graphics quality (scaled bitmap)

I want to display a splash screen with an gradient in my app. But the quality of the gradient in the background is pretty bad. So I create a simple radiant gradient to have a closer look.
Edit: Maybe I should have mentioned that I am using BitmapFactory.createScaledBitmap(); and BitmapFactory.decodeStream() (The graphics are in the assets folder.)
Thats the result:
Original *.jpg (Quality 100%)
Screenshot Xperia X10 (I took the screenshot with Eclipse)
You can do it without any jpg file, but using a shape drawable. Create rectangle and provide necessary parmas for gradient tag.
In order to scale a bitmap and keep ARGB_8888 I created a new bitmap in the desired size. Then I use canvas to draw the intrinsic bitmap on the new bitmap with drawBitmap. This method allows me to scale the bitmap before I draw it on the new bitmap.
inputStream = assetManager.open(path);
originalBitmap = BitmapFactory.decodeStream(inputStream, null, opts);
Bitmap resizedBitmap = Bitmap.createBitmap(desiredX, desiredY, Config.ARGB_8888);
Canvas canvas = new Canvas(resizedBitmap);
canvas.drawBitmap(originalBitmap, null, new Rect(0, 0, desiredX, desiredY), null);
inputStream.close();
return resizedBitmap;

how to convert a paint image to bitmap

I am able to save the source image but not able save the image with colorfilter:
paint.setColorFilter(new ColorMatrixColorFilter(cm));
If this image is converted into bitmap it can be saved easily,
but I don't know how to do this. Is there anyone to give solution?
Have your original bitmap.
Create a new clean Bitmap that has the same width/height as your original bitmap.
Create a new Canvas using this clean Bitmap.
Set your paint object, etc for this new Canvas.
Draw your original bitmap into this new Canvas.
Since this new Canvas is backed by a Bitmap (point 3.), any drawing you do in this Canvas will become part of the new Bitmap (point 2.). Now just call 'compress' on this Bitmap from point 2. and the bitmap will be saved as a jpg/png.

Categories

Resources