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;
}
Related
I am using a custom view in which I have a rectangle and need to draw a VectorDrawable between the bounds.
I need to resize the size of the vectorDrawable on the go.
I am already using canvas to set the outer rectangle, so I cannot create another canvas using a bitmap.
This is what I am doing inside onDraw():
canvas!!.drawRect(mRect, mRadius!!,mRadius!!, mPaint)
vectorDrawable.mutate()
vectorDrawable.setBounds(mRect)
vectorDrawable.draw(canvas)
If I try to create a bitmap and create a new canvas object:
var bmp = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888)
var can : Canvas = Canvas(bmp)
Then my vectorDrawable is not seen.
Please let me know the best way to resize the vectorDrawable.
I would like to get the following effect. I have an image on my screen. When a navigation drawer (or another obstructing view) comes over the top of my image, I want to instead of having it cover the image, show the negative of the image.
The pictures below may help to show what I mean.
Any ideas on how to accomplish this? I'd like to get the same effect for the menu icon.
The way I would go about this is:
Enable the drawing cache on the view you want to apply the negative:
view.setDrawingCacheEnabled(true);
Get a snapshot of the view when the drawer is clicked or dragged with :
Bitmap bmp = view.getDrawingCache();
Finally override the onDraw() method of the drawer and draw the bitmap on it. Apply a shader to do the "negative" effect. See: http://chiuki.github.io/android-shaders-filters/#/
canvas.drawColor(Color.WHITE);
BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.your_drawable);
Bitmap bm = bd.getBitmap();
Paint paint = new Paint();
Where the INT ranges from 0 (fully transparent) to 255 (fully opaque).
paint.setAlpha(0);
canvas.drawBitmap(bm, 0, 0, paint);
I want to crop shape in Hexagon,Octagon and in circle shape.I have used Custom Image view class and use in xml for showing image. It works properly for different shapes.
Now i need to crop the image in user selected shape in next activity.i get image in next activity.
I tried this example:
Masking(crop) image in frame But the image didn't fit in shape.only part of the image get masked.
How i can achieve this?
Read this blog post by Romain Guy on how to make images with rounded corners. Using this technique you can create a variety of shapes.
How would this work?
If you have a predefined number of shapes, I'd suggest you create a class with a few Shapes defined by Paths. Now whenever your user asks for a different shape to be used on an ImageView, you create a Bitmap and return a bitmap from that class and put it on your ImageView.
For example a octagon shape would be something like this:
public static Bitmap drawOctagonShapedBitmap(Bitmap src) {
Bitmap dst = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
//Create an output as big as the actual bitmap.
Path octagon = null; //Create an octagon shape, it should be big enough to crop enough of the bitmap.
Canvas canvas = new Canvas(dst);
Paint mPaint = new Paint();
BitmapShader mBitmapShader = new BitmapShader(src, Shader.TileMode.CLAMP,
Shader.TileMode.CLAMP);
mPaint.setAntiAlias(true);
mPaint.setShader(mBitmapShader);
canvas.drawPath(octagon, mPaint);
return dst;
}
I want to inflate layout xml file on 3d cube one side, for next side another layout xml, for next another etc.
I just need on side of 3d cube put gridView and in gridview put some buttons, images, texts.
Is it possible and how?
There are two ways you can accomplish this:
Create a Camera and create transformations for the different sides of your cube.
Here is an example of how to use the camera object to achieve a 3d-effect with a view.
This way don't explicitly use OpenGL, but it should be hardware accelerated on newer versions of Android.
Use the draw()-method of your layout to draw to a custom Canvas, and make an OpenGL texture out of the canvas content:
Bitmap layoutBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
Canvas tmpCanvas = new Canvas(layoutBitmap);
//Load layoutBitmap to a texture and recycle it.
Then draw your cube with the new texture.
Unfortunately these solutions won't allow any events on the layout (possibly the first option, but I don't think so) so if you need to be able to click or perform some other action this will not work.
I use this to create a bitmap image from layout, maybe help you.
private Bitmap imageXML(View view) {
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
final Bitmap bp = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
bp.eraseColor(Color.WHITE);
Canvas canvas = new Canvas(bp);
view.draw(canvas);
return bp;
}
I would like to merge a "drawRectF-like thing" with a Bitmap OR simple apply a border to a Bitmap in some way.
I don't want something like this:
Canvas.drawRectF(bitmap.x, bitmap.y, bitmap.x1, bitmap.y1)
Canvas.draw(bitmap)
I want to be able to apply the border to the Bitmap only once, then when I simply call Canvas.draw(bitmap) the border will be there around the bitmap.
It is preferable that the border has rounded corners.
First create a new canvas with the specified bitmap to draw into:
Canvas canvas1 = new Canvas(bitmap);
Then draw the border using this canvas:
canvas1.drawRectF(x, y, x1, y1);
Finally draw the bitmap to the first canvas.
canvas.draw(bitmap);
Note: For this to work, the bitmap must be mutable.