AndEngine, how to get the width of a sprite on runtime? - andengine

I have a sprite for a png file. ( Dimensions of the png file is 432x10 ). The png file is in drawable-xxhdpi folder. When i run on emulator with hdpi density mySprite.getWidth() returns 432. ( mySprite.getWidthScaled() also returns 432.) But the png file is looked just about 200 pixel width. Which method gives right value. ( not the width of the png file.) The value that how many pixel the png file is monitorized in? Thank you very much.
Note : My English is insufficient, sorry.

`public Engine onLoadEngine () {
....
SCR_WIDTH = getResources().getDisplayMetrics().widthPixels;
SCR_HEIGHT = getResources().getDisplayMetrics().heightPixels;
MyCamera = new Camera (0, 0, SCR_WIDTH, SCR_HEIGHT);
......
}`

Related

How to get depth images from the camera in pyBullet

In pyBullet, I have struggled a bit with generating a dataset. What I want to achieve is to get pictures of what the camera is seeing: img = p.getCameraImage(224, 224, renderer=p.ER_BULLET_HARDWARE_OPENGL)
Basically: to get the images that are seen in Synthetic Camera RGB data and Synthetic Camera Depth Data (especially this one), which are the camera windows you can see in the following picture on the left.
p.resetDebugVisualizerCamera(cameraDistance=0.5, cameraYaw=yaw, cameraPitch=pitch, cameraTargetPosition=[center_x, center_y, 0.785])
img = p.getCameraImage(224, 224, renderer=p.ER_BULLET_HARDWARE_OPENGL)
rgbBuffer = img[2]
depthBuffer = img[3]
list_of_rgbs.append(rgbBuffer)
list_of_depths.append(depthBuffer)
rgbim = Image.fromarray(rgbBuffer)
depim = Image.fromarray(depthBuffer)
rgbim.save('test_img/rgbtest'+str(counter)+'.jpg')
depim.save('test_img/depth'+str(counter)+'.tiff')
counter += 1
I already run the following, so I don't know if it is related to the settings. p.configureDebugVisualizer(p.COV_ENABLE_DEPTH_BUFFER_PREVIEW, 1)
I have tried several methods because the depth part is complicated. I don't understand if it needs to be treated separately because of the pixel color information or if I need to work with the project matrixes and view matrixes.
I need to save it as a .tiff because I get some cannot save F to png errors. I tried playing a bit with the bit information but acomplished nothing. In case you asked,
# depthBuffer[depthBuffer > 65535] = 65535
# im_uint16 = np.round(depthBuffer).astype(np.uint16)
# depthBuffer = im_uint16
The following is an example of the the .tiff image
And to end, just to remark that these depth images keep changing (looking at all of them, then to the RGB and passing again to the depth images, shows different images regardless of being the same image. I have never ever seen something like this before.
I thought "I managed to fix this some time ago, might as well post the answer found".
The data structure of img has to be taken into account!
img = p.getCameraImage(224, 224, shadow = False, renderer=p.ER_BULLET_HARDWARE_OPENGL)
rgb_opengl = (np.reshape(img[2], (IMG_SIZE, IMG_SIZE, 4)))
depth_buffer_opengl = np.reshape(img[3], [IMG_SIZE, IMG_SIZE])
depth_opengl = far * near / (far - (far - near) * depth_buffer_opengl)
seg_opengl = np.reshape(img[4], [IMG_SIZE, IMG_SIZE]) * 1. / 255.
rgbim = Image.fromarray(rgb_opengl)
rgbim_no_alpha = rgbim.convert('RGB')
rgbim_no_alpha.save('dataset/'+obj_name+'/'+ obj_name +'_rgb_'+str(counter)+'.jpg')
# plt.imshow(depth_buffer_opengl)
plt.imsave('dataset/'+obj_name+'/'+ obj_name+'_depth_'+str(counter)+'.jpg', depth_buffer_opengl)
# plt.show()
Final Images:

FreeText Annotation Appearance Stream In Landscape PDF Using iText

This is my code to create appearance stream for a free text annotation.
cs.rectangle(bbox.getLeft() , bbox.getBottom(), bbox.getWidth(), bbox.getHeight());
cs.fill();
String[] text = new String[1];
text[0] = "BAC"
cs.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED), pdfJSAnnotation.getFontSize());
cs.beginText();
cs.setLeading(fontSize + 1.75f);
cs.moveText(0, bbox.getHeight() - fontSize + .75f);
for (String s : text) {
if (s.equals("\n"))
cs.newlineText();
else
cs.showText(s);
}
cs.endText();
where cs is PdfAppearance, bbox is Rectangle. This works okay when pdf is portrait. however, im having problems when it is in landscape, say if page rotation is 270.
The text shown is vertical. and even if i use cs.transform() to rotate, it does not even rotate properly. I also tried to save the state, do a rotate then display text and then call cs.restoreState() after cs.endText() but the outcome is still not correct.
any ideas?
the rectangle is correct since the 1st 2 lines where it fills a rectangle shape is correctly displayed. it is the text i am having problems with.
The solution to this is:
- set appearance dimension to (height,width) since it is 270 degrees.
Then in the PdfAppearance object:
translate it to (height, 0);
rotate to 270
translate to (-height,-height);
(Tried to remove this post but there is no option available)

Use an huge image as a sprite

I'd like to use an huge image as a sprite in my game made with corona SDK. The image dimensions are 4172x320, for a total of 28 frames.
The fact is that when I load the scene that contains this image, the physics engine turns off. I read that the dimensions limits for a sprite is set to 2048x2048 and in fact it works as it should, but I lost the smoothness that 28 frames give to the sprite.
The code I've used to declare the spritesheet is:
local sheet2 = graphics.newImageSheet( "immagini/profDonnaCOMP.png", { width=149, height=320, numFrames=28 } )
local instance2 = display.newSprite( sheet2, { name="profDonna", start=1, count=28, time=800 } )
instance2.x = _W/2
instance2.y = _H/2+150
instance2.myName = "instance2"
instance2:play()
physics.addBody( instance2, "dynamic", { friction=0.5, bounce=0 } )
What can I do to fix this issue?
Hi try making other sprite which will be 7x4 instead of 28x1 and you will get 1043x960 image which is good to go.

Using resources directly from Expansion file

How to create texture directly from expansion files.
We get InputStream, now how to use this Input Stream. If I convert in bitmap and then use it start giving outofmemory.
I have tried
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(appContext,
mainVersion, patchVersion);
InputStream fileStream = expansionFile.getInputStream(pathToFileInsideZip);
You can create as follows:
File imageFile = new File(imagePath);
BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(
activity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
IBitmapTextureAtlasSource fileTextureSource = FileBitmapTextureAtlasSource
.create(imageFile);
ITextureRegion textureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromSource(mBitmapTextureAtlas, fileTextureSource, 0, 0);
Memory management:
Give the texture Atlas size relative to your image size.
For Example if your image size is 200X200 then give as 256 X 256 otherwise giving texture more makes wastage of memory.
And also unload the textures when ever these are not needed.

How to resolve Circos SVG placing text incorrectly?

I have the following Circos diagram, which I rendered as an SVG file and then converted to PNG, for the purposes of illustration:
The text labels that circle the outer rim are oriented correctly from 12 o'clock to 9 o'clock, oriented outwards, away from the grey arcs.
Between 9 and 12, the text labels are oriented inwards, overlapping the grey arc. This is not expected.
Here's a close-up, to clarify the issue:
If I output a PNG from Circos, instead of SVG, the labels are drawn correctly, but then I lose the ability to mark up the vector-formatted SVG figure in Adobe Illustrator or Inkscape. So I need the SVG output.
Here's a snippet of the circos.conf file relevant to the addition of the labels:
<image>
dir = /tmp
file = circos.png
png = yes
radius = 3000p
background = white
angle_offset = -176
</image>
...
<plots>
<plot>
type = text
color = black
file = factorList.txt
r0 = 1r
r1 = 1r+200p
label_size = 12p
label_font = condensedbold
padding = 0p
rpadding = 0p
label_snuggle = yes
max_snuggle_distance = 1r
snuggle_sampling = 2
snuggle_tolerance = 0.25r
snuggle_link_overlap_test = yes
snuggle_link_overlap_tolerance = 2p
snuggle_refine = yes
</plot>
</plots>
I'm not sure what other options I can apply to try to resolve this. My question is: What should I try in this or another configuration file, which fixes the SVG output? Thanks for your advice.
Maybe you can try this option:
label_rotate = no
And I think the layout above caused by the snuggle option ,and also check your conf file and be sure all the "r0" and "r1" of plot(type=text) are bigger than 1r .
Here is the circos lessonss example