how to make border around an image - libgdx? - android

i have a large image ,then i cut it into 9 equal small images. that is my code
Image pricer[][] = new Image[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
pricer[i][j] = new Image(TextureRegion.split(bg, tile, tile)[i][j]);
pricer[i][j].setSize(200, 200);
pricer[i][j].setPosition((j*200),600-(i*200));
stage.addActor(pricer[i][j]);
}
}
now, i want to create border for those images that i devide into small peace.many thanks for your help

You can use a ShapeRenderer:
ShapeRenderer renderer = new ShapeRenderer();
renderer.begin(ShapeType.Line)
renderer.setColor(color);
renderer.rect(image.getImageX(), image.getImageY(), image.getImageWidth(), image.getImageHeight);
renderer.end();

Related

Watershed algorithm with touch on image to add marker OpenCV android

I am trying to save the watershed segments as image to sdcard in android.
Code tried in c++ and working fine
for (int m = 0; m < images.size(); m++) {
//wshed = wshed*0.5 + imgGray*0.5;
cv::Mat input_bgra;
cv::cvtColor(images[m], input_bgra, CV_BGR2BGRA);
// find all white pixel and set alpha value to zero:
for (int y = 0; y < input_bgra.rows; ++y)
for (int x = 0; x < input_bgra.cols; ++x)
{
cv::Vec4b & pixel = input_bgra.at<cv::Vec4b>(y, x);
// if pixel is black
if (pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0)
{
// set alpha to zero:
pixel[3] = 0;
}
}
std::ostringstream name;
name << "D:/Sathiya/res/intlayer" << m << ".png";
imwrite(name.str(), input_bgra);
}
Not sure how to achieve this in android.
I am trying to save watershed segments as png in java , is it straightforward to do.

Android combining multiple images from database to single bitmap

i need to combine multiple images to a single bitmap. i need to combine the images in the range from 2-6. The path of the image is taken from my app's database and image is stored in my external sd card.
i have combined 2 images . But i need to combine 3, 4, 5 and 6 images in to single canvas.
My code for combining 2 images is provided below:-
private Bitmap combineImageIntoOne(ArrayList<Bitmap> a) {
int top = 0;
int width = 0, height = 0;
for (int j = 0; j < a.size(); j++) {
width += a.get(j).getWidth();
}
height = a.get(0).getHeight();
Bitmap combineBitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(combineBitmap);
for (int i = 0; i < a.size(); i++) {
System.out.println("image width = " + top);
comboImage.drawBitmap(a.get(i), top, 0f, null);
top = top + a.get(i).getWidth();
}
System.out.println("combineBitmap combineBitmap..in.."+combineBitmap);
return combineBitmap;
}
I think you can combine 3, 4, 5 and 6 images in to single canvas by the same code.
If you want to use the tallest bitmap's height,you can change the code like this.
//get the max height
height = a.get(0).getHeight();
for (int j = 0; j < a.size(); j++) {
width += a.get(j).getWidth();
if(height<a.get(j).getHeight()){
height=a.get(j).getHeight();
}
}

sprite size libgdx android

I created 5 sprites using libgdx library, then want to assign the different size to all of them between 0 to 10 and then move from left to right. 5 sprite is succussfully created but the problem is in the size. i tried the S.nextInt(10). but its not working.
Also i want to create all the sprites between 100-200 height. how to do it?
int number = 5;
sprite = new Sprite[number];
for (int i = 0; i < number; i++) {
sprite[i] = new Sprite(texture);
int size = S.nextInt(10);
sprite[i].setSize(size, size);
speed = S.nextInt(2);
sprite[i].setPosition(speed, 100);
}
batch.begin();
for (int i = 0; i < number; i++) {
sprite[i].draw(batch);
}
batch.end();

How to detect color line in image using android java

If I have an image containing black lines, like the image below. How can I detect the black lines.( to know the x,y of dots on this lines) ?
I want to know how to get started with this topic. What library should I learn to go through
You can use Catalano Framework.
http://code.google.com/p/catalano-framework/
FastBitmap image = new FastBitmap(bitmap);
image.toGrayscale();
int width = image.getWidth();
int height = image.getHeight();
ArrayList<IntPoint> lst = new ArrayList<>();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (image.getGray(i, j) == 0)
lst.add(new IntPoint(i,j));
}
}

Android Kube API Samples gets out of structure

I'm using the Kube application from Android API Samples for an application I'm working on.
The sample creates a model of the Rubik's Cube in OpenGL made out of 27 small cubes. Afterwards the cube is being scrambled in the animate() method by rotating random layers of the cube, after each rotation the layers are being set accordingly in a process I don't fully understand
// adjust mPermutation based on the completed layer rotation
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
// newPermutation[i] = mCurrentLayerPermutation[mPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
The sample works fine but for some reason when I change the direction of the rotation to true, the cubes start overlapping each other, as if the layers weren't updated correctly.
Help would be appreciated :)
I solved the problem myself, so in case anyone is interested:
changing the direction to true makes the cube rotate in the other direction, which is like rotating three times in the regular direction so in order to save to cubes new location correctly I need to save the new location three times, as seen in the code below:
if (mAngleIncrement < 0) { // checks the turning direction
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
}
else {
int[] newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
newPermutation = new int[27];
for (int i = 0; i < 27; i++) {
newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
}
mPermutation = newPermutation;
updateLayers();
}

Categories

Resources