I am new to OpenGl and needed some help.
I have a screen was able to draw a imageon it. Now i want to create a mirror image of the same image i.e i want the screen to be divided in 2 parts(horizontally) and then have the actual image at the bottom and create a duplicate image at the top just like a mirror image so that if a change is made to the bottom image it reflects on the top image too.
Please give suggestions. (I do not want canvas mirror image code)
try this
sprite = BitmapFactory .decodeResource(appContext.getResources(),R.drawable.spritegfx);
Matrix temp1=new Matrix();
temp1.preScale(-1.0f,1.0f);
flipedSprite = Bitmap.createBitmap(sprite , 0, 0,sprite.getWidth(),sprite .getHeight(), temp1, false);
canvas.drawBitmap(flipedSprite , 0,0, null);
http://www.opengl.org/archives/resources/faq/technical/transformations.htm#tran0170
Related
I'm trying build a camera app in android using camera API.
I follow the instructions: https://examples.javacodegeeks.com/android/core/hardware/camera-hardware/android-camera-example/ and I have built one camera app
Now i need to display preview camera inside a frame and take picture include the frame
Please see the two pictures below:
Frame in resource folder : https://i.stack.imgur.com/AaNIQ.png
The photo I want to achieve: https://i.stack.imgur.com/UWXcq.jpg
Anyone can give me suggestions or if possible give me a simple example?
I searched about this but didn't get proper example.
Thank you so much.
Half of the answer can be found here: https://stackoverflow.com/a/47240902/192373.
As for keeping the same layout for full-res picture capture, first of all make sure that you keep preview- and picture- sizes in sync. This does not mean that they must be the same, but the aspect ratios should. Some devices have weird effects when the aspect ratio changes to capture a photo.
Next, you capture the jpeg as usual, unpack it to bitmap, overlay with the frame bitmap (you may need a hi-res version of your frame here) and combine the two (based on https://stackoverflow.com/a/4863551/192373):
public Bitmap combineImages(Bitmap picture, Bitmap frame) {
Bitmap bmp = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(), Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(bmp);
comboImage.drawBitmap(picture, 0f, 0f, null);
comboImage.drawBitmap(frame, 0f, 0f, null);
return bmp;
}
I am developing a photography app in which I want to select a particular section of a photo and stretch that portion only. How to do that?
I have tried to stretch a photo using Canvas but failed to do so. Is it possible from android.graphics.NinePatch class?
Any suggestions?
You can use matrix to apply new dimension to your bitmap.
you could use setscale/postScale methods of a matrix object.
A rather ugly solution would be using a image cropping library. You can use it to temporarily crop a portion of the image and load it into another ImageView and then scaling it up.
Also, you can get things done without using that CropImageView. The idea is whenever user touches the original image view, you will be given a (x, y) at which user's finger resides. So, you can extract a bitmap image centered at (x, y) and with a given radius.
For applying a magnifier effect you could use a round/circular ImageView for showing magnified portion of the image.
Something like this:
Finally i found a solution of my problem below :
Bitmap stretchImage = Bitmap.createBitmap(w, h+progress, Bitmap.Config.ARGB_8888 );
c = new Canvas(stretchImage);
//draw top bit
c.drawBitmap(normalImage, new Rect(0,0,w,75), new Rect(0,0,w,75), null);
//draw middle bit
c.drawBitmap(normalImage, new Rect(0,75,w, 150), new Rect(0,75,w,150+progress), null);
//draw right bit
c.drawBitmap(normalImage, new Rect(0 ,150,w,225), new Rect(0 ,150+progress,w,225+progress), null);
myImage.setImageBitmap(stretchImage);
I have one png image.
Then, I want to flip this triangle as on the next image.
Red region it is our original image which is reflected and turned. And then I want to rotate new region (red region) on different angles.
How can i do it in android?
Thanks in advance!
To rotate an image in android you should look here
Rotate image in android
Or here
Android: Rotate image in imageview by an angle
To get a mirror image of your PNG, do this (taken from the link below, from Dalmas's answer)
Matrix matrix = new Matrix();
matrix.preScale(-1.0f, 1.0f);
Bitmap mirroredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.width(), bmp.height(), matrix, false);
How to mirror an image file? (2.2+)
To rotate a vector look here
Rotating a vector using Matrix.rotateM
I want to use downloaded images as markers on a MapView. I images are all squares but I would like the bottom to also extend to form a triangle marking the exact point.
My approach was to create a canvas which is slightly larger than the image. Then, draw the bitmap on to the canvas and then somehow pick the color from the bottom of the bitmap and draw a triangular shape from the horizontal center of the image to the bottom of the canvas. Something like this...
As you might guess I'm stuck with the last part. So far I have....
Bitmap canvasBitmap = Bitmap.createBitmap(markerBitmap.getWidth(), markerBitmap.getHeight()+10, Bitmap.Config.ARGB_8888);
// The 10 pixels will be the so called "pin"
Canvas canvas = new Canvas(canvasBitmap);
canvas.drawBitmap(markerBitmap, 0.0f, 0.0f, null);
// Can figure out how to draw the 10 px bottom using the color from markerBitmap
Help !!
Is there any specific reason why you want to create the images dynamically? If not, why don't you create them using a graphics editing program, save them as png's or 9-patch images and then simply assign it to the Drawable that's used for the marker.
I want to create a bitmap / image which has many images like "Collage" which has more then one images in a single picture.
I have stored all my images in a grid view but now i want to create a single image from all those images. And even i want to make few images click able
so what can be the road map to do this ? any sort of help / example will be helpful.
reference image
Bitmap pic1 = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);
Bitmap pic2 = BitmapFactory.decodeResource(getResources(), R.drawable.pic2);
Bitmap bg= BitmapFactory.decodeResource(getResources(), R.drawable.background);
Bitmap out1 = Bitmap.createBitmap(bg) ;
Canvas comboImage = new Canvas(out1);
comboImage.drawBitmap(pic1, 10f, 20f, null);
comboImage.drawBitmap(pic2, 30f, 40f, null);
out1 will have pic1 & pic2, with a background image bg.
To create a single image from multiple images look at using Canvas. You can put bitmaps (and drawables) on a canvas. You can commit the changes and then push then to a single bitmap that you can then use. As far as making certain sections clickable after making it one single image, I will leave this up to someone else to explain, I am not worked directly with the ontouch() functions.