I am working on AndEngine, and stuck to know the exact height and width of the PhysicsWorld which I used in meters.
this.mScene = new Scene();
this.mScene.setBackground(new Background(0, 0, 0));
this.mScene.setOnSceneTouchListener(this);
this.mScene.setOnAreaTouchListener(this);
this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 10), false);
this.mScene.registerUpdateHandler(this.mPhysicsWorld);
I solved it in my way.. thank you #LearnCocos2D.
this.mScene = new Scene();
this.mScene.setBackground(new Background(0, 0, 0));
this.mScene.setOnSceneTouchListener(this);
this.mScene.setOnAreaTouchListener(this);
this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 10), false);
this.mScene.registerUpdateHandler(this.mPhysicsWorld);
final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager);
final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
final Rectangle right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
Body g =PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef2);
Body l =PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef1);
final float width = 2*g.getWorldCenter().x;
final float height = 2*l.getWorldCenter().y;
Related
I'm trying to perform a signing and want to generate the same multiple appearances. Is there a way to achieve a custom appearance as we can generate in normal cases?
PdfSignatureFormField sigField = (PdfSignatureFormField) acroForm.getField(fieldName);
sigField.addKid(
createSubField(pdfPage, 40, 700, 100, 40, "sig1", signatureDictionary, document));
sigField.addKid(
createSubField(pdfPage, 400, 600, 100, 40, "sig2", signatureDictionary, document));
The following is the method which is generating subfields.
public static PdfFormField createSubField(PdfPage page, float x, float y, float width,
float height, String name, PdfDictionary signatureDictionary, PdfDocument pdfDocument) {
PdfFormXObject appearance = new PdfFormXObject(new Rectangle(width, height));
PdfCanvas pdfCanvas = new PdfCanvas(appearance, pdfDocument);
try (Canvas canvas = new Canvas(pdfCanvas, new Rectangle(width, height))) {
canvas.showTextAligned(name, 2, 2, TextAlignment.LEFT);
}
PdfDictionary ap = new PdfDictionary();
ap.put(PdfName.N, appearance.getPdfObject());
PdfWidgetAnnotation widget = new PdfWidgetAnnotation(new Rectangle(x, y, width, height));
widget.setFlags(PdfAnnotation.PRINT | PdfAnnotation.LOCKED);
widget.setPage(page);
widget.put(PdfName.AP, ap);
PdfSignatureFormField sigField = PdfFormField.createSignature(pdfDocument);
sigField.setFieldName(name);
sigField.addKid(widget);
sigField.put(PdfName.V, signatureDictionary);
page.addAnnotation(widget);
return sigField;
}
I try to only detect eyes inside the face rectangle. Eyes are actually only detected, when there is an face recognized, but the corresponding rectangle are misplaced:
The green rectangle correctly catches the face. But the cyan-colored eye rectangles are misplaced to the top left. Seems they are originating from coords 0,0 and not from the top-left corner of the face rectangle.
// detect faces
this.faceCascade.detectMultiScale(grayFrame, faces, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE, new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());
Rect[] facesArray = faces.toArray();
MatOfRect eyes = new MatOfRect();
this.eyeCascade.load("resources/haarcascades/haarcascade_eye.xml");
for (int i = 0; i < facesArray.length; i++) {
Rect currentFace = facesArray[i];
Imgproc.rectangle(frame, currentFace.tl(), currentFace.br(), new Scalar(0, 255, 0), 3);
Imgproc.putText(frame, "face", currentFace.tl(), 2, 2, new Scalar(0, 255, 0));
Mat faceROI = grayFrame.submat(currentFace);
this.eyeCascade.detectMultiScale(faceROI, eyes, 1.1,2,0 | Objdetect.CASCADE_SCALE_IMAGE, new Size(this.absoluteFaceSize/5, this.absoluteFaceSize/5), new Size());
Rect[] eyesArray = eyes.toArray();
for (Rect eye : eyesArray) {
Point tl = new Point(currentFace.x+eye.tl().x, currentFace.y+eye.tl().y);
Point br = new Point(currentFace.x + eye.br().x, currentFace.y + eye.br().y);
Imgproc.rectangle(faceROI, tl, br, new Scalar(0, 0, 255), 3);
Imgproc.putText(faceROI, "Eye", tl, 2, 2, new Scalar(0, 0, 255));
}
}
public BufferedImage detectAndDisplay(BufferedImage img, CascadeClassifier faceCascade) {
Mat frameGray = new Mat();
BufferedImage imgout = null;
Mat image = ImagePreProcessing.bufferedImageToMat(img);
// -- Detect faces
MatOfRect faces = new MatOfRect();
faceCascade.detectMultiScale(image, faces);
List<Rect> listOfFaces = faces.toList();
for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);
Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);
System.out.println("OpenCV: " +center);
}
return imgout;
}
that code I have..but I don't know where the code for setting crop output image.
I want to have the picture like original version with circle template..NOT to be crop
Can give me suggestion, please:)
input:
output:
In your code, you returned a cropped image of the original image, so if you want the original image, draw the circle and convert it to the BufferedImage and return.
for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);
// dot not crop!!!
/*Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);*/
System.out.println("OpenCV: " +center);
imgout = ImagePreProcessing.Mat2BufferedImage(image);
}
public class CrossAndCircles extends ApplicationAdapter{
OrthographicCamera camera;
SpriteBatch batch;
ShapeRenderer renderer;
Array<Rectangle> array;
Vector3 touchPos;
int turn, cellSize, touchCount;
float tempX, tempY;
#Override
public void create () {
batch = new SpriteBatch();
renderer = new ShapeRenderer();
camera = new OrthographicCamera();
camera.setToOrtho(false, 480, 480);
touchCount = 0;
cellSize = 480/3-5;
array = new Array<Rectangle>();
//cell's coordinates
Rectangle oneOne = new Rectangle(0, 0 ,cellSize, cellSize);
Rectangle oneTwo = new Rectangle(0, cellSize+5, cellSize, cellSize);
Rectangle oneThree = new Rectangle(0, 480-cellSize, cellSize, cellSize);
Rectangle twoOne = new Rectangle(cellSize+5, 0 , cellSize, cellSize);
Rectangle twoTwo = new Rectangle(cellSize+5, cellSize+5, cellSize, cellSize);
Rectangle twoThree = new Rectangle(cellSize+10, 480-cellSize, cellSize, cellSize);
Rectangle threeOne = new Rectangle(480-cellSize, 0 , cellSize, cellSize);
Rectangle threeTwo = new Rectangle (480-cellSize, cellSize+5, cellSize, cellSize);
Rectangle threeThree = new Rectangle(480-cellSize, 480-cellSize, cellSize, cellSize);
array.add(oneOne); array.add(oneTwo); array.add(oneThree); array.add(twoOne);
array.add(twoTwo); array.add(twoThree); array.add(threeOne); array.add(threeTwo); array.add(threeThree);
}
#Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
//our field
batch.setProjectionMatrix(camera.combined);
renderer.begin(ShapeType.Filled);
renderer.setColor(Color.BLACK);
renderer.rect(480/3-5, 0, 10, 480);
renderer.rect(480/3*2-5, 0, 10, 480);
renderer.rect(0, 480 / 3 - 10, 480, 10);
renderer.rect(0, 480 / 3 * 2 - 10, 480, 10);
renderer.end();
//if user touch a rectangle draw a circle or a cross
if(Gdx.input.isTouched()){
for (Rectangle rect:array) {
if (rect.contains(Gdx.input.getX(), Gdx.input.getY())) {
tempX = rect.x;
tempY = rect.y;
break;
}}
touchCount++;
}
if (touchCount>0 && touchCount<=9){
renderer.begin(ShapeType.Filled);
renderer.rect(tempX+20,tempY+20,0, 0, 10, cellSize, 1, 1, -45);
renderer.end();}
}
public void dispose(){super.dispose(); renderer.dispose();}
}
Help me with my Tic tac toe game. I've still added only one stick but it appears only twice, and when I'm clicking to the upper cells it appears in lowers. And I don't know why the first stick is not saved, it just change it's place. What's wrong in my logic?
there is difference in touch and screen coordinates,
refer :
https://github.com/libgdx/libgdx/wiki/Coordinate-systems
Im trying to create a round frame around my bitmap!
With this code im able to make my bitmap round:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff4242DB;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = bitmap.getWidth()/2;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
//canvas.drawCircle(0, 0, bitmap.getWidth(), paint);
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
What i've tried is to draw a circle(the outcommented line) with canvas, but It had no result.
Does anyone know how I can add a circular border around it?
EDIT
When I use the line:
canvas.drawCircle(0, 0, bitmap.getWidth(), paint);
The effect is, that 3 corners get rounded but the upper left stays the same(90 degrees)
But I can't see any line or circle!
Update
There now is RoundedBitmapDrawable and a corresponding factory in the Support library I recommend to use that, unless more flexibility is required.
Original Answer
You have to draw the circle after the bitmap. This is what did the trick for me.
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int radius = Math.min(h / 2, w / 2);
Bitmap output = Bitmap.createBitmap(w + 8, h + 8, Config.ARGB_8888);
Paint p = new Paint();
p.setAntiAlias(true);
Canvas c = new Canvas(output);
c.drawARGB(0, 0, 0, 0);
p.setStyle(Style.FILL);
c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, p);
p.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
c.drawBitmap(bitmap, 4, 4, p);
p.setXfermode(null);
p.setStyle(Style.STROKE);
p.setColor(Color.WHITE);
p.setStrokeWidth(3);
c.drawCircle((w / 2) + 4, (h / 2) + 4, radius, p);
return output;
This does of course not include the fancy shadow of your example.
You might want to play around a little bit with the additional pixels.