TouchImageView tap location - java

I'm using TouchImageView from https://github.com/MikeOrtiz/TouchImageView and I'm trying to use highlights.
For example, when the user taps in a certain point of the image (doesn't matter if the image is zoomed in or not), I would trigger an event - show the description of the highlight in a webview.
It works but only when all the image fits in the view, when I zoom in it all bugs.
If (scaledRight < 0) it seems to work reasonably well, but when it falls on the else it doesn't work.
Any help will be really appreciated, and if it works I can send it to the creator :)
Thanks in advance.
public boolean onTouch(View v, MotionEvent event) {
mScaleDetector.onTouchEvent(event);
matrix.getValues(m);
float x = m[Matrix.MTRANS_X];
float y = m[Matrix.MTRANS_Y];
PointF curr = new PointF(event.getX(), event.getY());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
last.set(event.getX(), event.getY());
if(!isFullScreen){
//System.out.println("Right is " + right);
//System.out.println("Bottom is " + bottom);
//System.out.println("Start x is " + start.x);
//System.out.println("Start y is " + start.y);
//float scaledRight = 2 * (right);
float scaledRight = 2 * (right/saveScale);
float scaledBottom = 2 * (bottom/saveScale);
//float scaledBottom = 2 * (bottom);
float tapPositionX = 0;
float tapPositionY = 0;
double xMaxBound = 0;
double xMinBound = 0;
double yMaxBound = 0;
double yMinBound = 0;
int radius = 0;
System.out.println("Right is " + right);
System.out.println("Bottom is " + bottom);
/*
if(theDeltaX < 0) {
theDeltaX = -theDeltaX;
}
theDeltaX = theDeltaX / saveScale;
if(theDeltaY < 0) {
theDeltaY = -theDeltaY;
}
theDeltaY = theDeltaY / saveScale;
*/
for(int i = 0; i < XMLParser.hlPicIDArray.size(); i++)
{
if(imageID.equalsIgnoreCase(XMLParser.hlPicIDArray.get(i))) {
radius = Integer.parseInt(XMLParser.hlRadiusArray.get(i));
xMaxBound = Integer.parseInt(XMLParser.hlOrXArray.get(i));
xMinBound = xMaxBound;
yMaxBound = Integer.parseInt(XMLParser.hlOrYArray.get(i));
yMinBound = yMaxBound;
xMaxBound = xMaxBound + (radius * Math.cos(0));
xMinBound = xMinBound + (radius * Math.cos(3.14));
yMaxBound = yMaxBound + (radius * Math.sin(1.57));
yMinBound = yMinBound + (radius * Math.sin(4.71));
if(scaledRight <= 0) {
//tapPositionX = (bmWidth * 2) - (scaledRight) + (80/saveScale);
tapPositionX = bmWidth - (scaledRight) + (80/saveScale);
tapPositionX = (curr.x/width) * (tapPositionX);
tapPositionX += (right);// - 80;
xMinBound = xMinBound - (0.12 * xMinBound); //Compensation for imprecision
//xMaxBound = xMaxBound - (0.08 * (maxScale - saveScale) * xMinBound);
//Highlight point is added to right to compensate the white margins
}
else {
//?
//tapPositionX = (start.x/width) * right * 2; //(+ offset)
tapPositionX = (start.x/width) * right; //(+ offset)
//tapPositionX = tapPositionX + ((theDeltaX/width) * bmWidth * 2);
tapPositionX = tapPositionX + (last.x/width) * (bmWidth - right); // * 2
//tapPositionX -= theDeltaX;
}
if(scaledBottom <= 0) {
//tapPositionY = (bmHeight * 2) - (scaledBottom) + (80/saveScale);
tapPositionY = bmHeight - (scaledBottom) + (80/saveScale);
tapPositionY = (last.y/height) * tapPositionY;
tapPositionY += (bottom/saveScale);// - 80;
yMinBound = yMinBound - (0.12 * yMinBound); //Compensation for imprecision
//yMaxBound = yMaxBound - (0.08 * (maxScale - saveScale) * yMinBound);
}
else {
//tapPositionY = (start.y/height) * bottom * 2;
tapPositionY = (start.y/height) * bottom;
tapPositionY = tapPositionY + (last.y/height) * (bmHeight - bottom);
//tapPositionY -= theDeltaY;
}
System.out.println("X tapped is " + tapPositionX);
System.out.println("Y tapped is " + tapPositionY);
System.out.println("Delta X is " + theDeltaX);
System.out.println("Delta Y is " + theDeltaY);
if((tapPositionX <= xMaxBound) && (tapPositionX >= xMinBound) && (tapPositionY <= yMaxBound) && (tapPositionY >= yMinBound)) {
System.out.println("HL Area tapped!");

Related

Zooming relative to mouse doesnt work in JavaFX

I had a working code, which used ParallelCamera when zooming, and it worked perfectly.
Here's it:
double s = camera.getScaleX();
double d = e.getDeltaY();
double f = 1.2;
double x = e.getSceneX();
double y = e.getSceneY();
if (d < 0) {
f = 2;
} else if (d > 0) {
f = 0.5;
}
double ps = s;
/*if (s * f > 1) {
camera.setScaleX(1);
camera.setScaleY(1);
camera.setScaleZ(1);
camera.setTranslateX(0);
camera.setTranslateY(0);
return;
}
camera.setScaleX(s * f);
camera.setScaleY(s * f);
camera.setScaleZ(s * f);
s = camera.getScaleX();
double dx = ps * (1 - f) * x;
double dy = ps * (1 - f) * y;
System.out.println(dx);
double width = primaryScene.getWidth();
double height = primaryScene.getHeight();
if (camera.getTranslateX() + s * width + dx > width) {
camera.setTranslateX(width - s * width);
} else if ((camera.getTranslateX() + dx < 0)) {
camera.setTranslateX(0);
} else {
camera.setTranslateX(camera.getTranslateX() + dx);
}
if (camera.getTranslateY() + s * height + dy > height) {
camera.setTranslateY(height - s * height);
} else if ((camera.getTranslateY() + dy < 0)) {
camera.setTranslateY(0);
} else {
camera.setTranslateY(camera.getTranslateY() + dy);
}
But I wanted to not have the quality loss, so I rewrote it.
Now it scales the Pane, and not the camera.
I followed exactly the same code, only this time the scaling is reversed.
And when I calculate the position, I first set an offset tomimic my original code.
(The camera's pivot point is at 0,0, but the Pane's is in the center)
The quality loss is gone, but it doesnt really work:
double s = mapLayer.getScaleX();
double d = e.getDeltaY();
double f = 1.2;
double width = primaryScene.getWidth();
double height = primaryScene.getHeight();
double x = (e.getSceneX());
double y = (e.getSceneY());
if (d > 0) {
f = 2;
} else{
f = 0.5;
}
double ps = s;
mapLayer.setScaleX(s * f);
mapLayer.setScaleY(s * f);
mapLayer.setScaleZ(s * f);
s = mapLayer.getScaleX();
double dx = ps * (1 - f) * x;
double dy = ps * (1 - f) * y;
mapLayer.setTranslateX(mapLayer.getTranslateX()+ps*(width/2)*(f-1));
mapLayer.setTranslateY(mapLayer.getTranslateY()+ps*(height/2)*(f-1));
mapLayer.setTranslateX(mapLayer.getTranslateX()+dx);
mapLayer.setTranslateY(mapLayer.getTranslateY()+dy);
I found this, and it worked like a charm:
JavaFX 8 - Zooming Relative to Mouse Pointer. The solution now is this (without clamping):
double delta = 1.2;
double scale = mapLayer.getScaleX(); // currently we only use Y, same value is used for X
double oldScale = scale;
if (e.getDeltaY() < 0) {
scale /= delta;
} else {
scale *= delta;
}
double f = (scale / oldScale) - 1;
double dx = (e.getSceneX()
- (mapLayer.getBoundsInParent().getWidth() / 2
+ mapLayer.getBoundsInParent().getMinX()));
double dy = (e.getSceneY()
- (mapLayer.getBoundsInParent().getHeight() / 2
+ mapLayer.getBoundsInParent().getMinY()));
mapLayer.setScaleX(scale);
mapLayer.setScaleY(scale);
mapLayer.setScaleZ(scale);
mapLayer.setTranslateX(mapLayer.getTranslateX() - f * dx);
mapLayer.setTranslateY(mapLayer.getTranslateY() - f * dy);

How could I zoom in JavaFx without quality loss?

Currently I zoom in and out using a ParallelCamera, but everything stays on the scene resolution when I zoom in.
But if I scale the group itself, not the camera then it is extremely slow, sometimes freezes the entire application.
What is the correct way of zooming?
My group contains about 4,000 Polygons, nothing else.
Here's the current code:
double s = camera.getScaleX();
double d = e.getDeltaY();
double f = 1.2;
double x = e.getSceneX();
double y = e.getSceneY();
if (d < 0) {
f = 1.1;
} else if (d > 0) {
f = 0.9;
}
double ps = s;
if (s * f > 1) {
camera.setScaleX(1);
camera.setScaleY(1);
camera.setScaleZ(1);
camera.setTranslateX(0);
camera.setTranslateY(0);
return;
}
camera.setScaleX(s * f);
camera.setScaleY(s * f);
camera.setScaleZ(s * f);
s = camera.getScaleX();
double dx = ps * (1 - f) * x;
double dy = ps * (1 - f) * y;
double width = primaryScene.getWidth();
double height = primaryScene.getHeight();
if (camera.getTranslateX() + s * width + dx > width) {
camera.setTranslateX(width - s * width);
} else if ((camera.getTranslateX() + dx < 0)) {
camera.setTranslateX(0);
} else {
camera.setTranslateX(camera.getTranslateX() + dx);
}
if (camera.getTranslateY() + s * height + dy > height) {
camera.setTranslateY(height - s * height);
} else if ((camera.getTranslateY() + dy < 0)) {
camera.setTranslateY(0);
} else {
camera.setTranslateY(camera.getTranslateY() + dy);
}

LibGdx Mouse Position relative to Orthographic Camera instead of Screen

Basically I wrote a "Dota like Style" based on the OrthographicCamera from libgdx.
You can test it out for youself here is the class.
I am using this to draw a TiledMap, and I have and array of tiles corresponding with the graphical tiles, however if I move the mouse, and with that the camera.
The coordinates off the mouse and the tiles are completely different.
Gdx.input x and y get their coordinates relative to the screen and not where the mouse is in the world relative to the camera.
I can't figure out a way to get the mouse position relative to the camera, so that if I move the camera I won't just get the regular mouse coordinates, but the actual world coordinates that the camera is showing, and where my mouse is located within the confines of the view of the camera relative to the world.
public class DotaCamera extends OrthographicCamera {
private float xmin;
private float xmax;
private float ymin;
private float ymax;
private float x;
private float y;
private int Width = Gdx.graphics.getWidth();;
private int Height = Gdx.graphics.getHeight();
private int camSpeedMax = 16;
private float camAcceleration = 0.3f;
private int camSpeedSmoother = 3;
private float camVelocityX = 0;
private float camVelocityY = 0;
private float fZoomMax = 1f;
private float fZoomMin = 0.5f;
private float fZoomSpeed = 0.03f;
public DotaCamera() {
this(0, 0, 0, 0);
}
public DotaCamera(float xmin, float xmax, float ymin, float ymax) {
super();
setBounds(xmin, xmax, ymin, ymax);
}
public void setBounds(float xmin, float xmax, float ymin, float ymax) {
this.xmin = xmin;
this.xmax = xmax;
this.ymin = ymin;
this.ymax = ymax;
}
public void setPosition(float x, float y) {
setPosition(x, y, 0);
}
public void setPosition(float x, float y, float z) {
position.set(x, y, z);
this.x = x;
this.y = y;
fixBounds();
}
private void fixBounds() {
if (position.x < xmin + viewportWidth / 2) {
position.x = xmin + viewportWidth / 2;
}
if (position.x > xmax - viewportWidth / 2) {
position.x = xmax - viewportWidth / 2;
}
if (position.y < ymin + viewportHeight / 2) {
position.y = ymin + viewportHeight / 2;
}
if (position.y > ymax - viewportHeight / 2) {
position.y = ymax - viewportHeight / 2;
}
}
/**
* Controls the zoom of the of the camera.
*/
public void updateZoom() {
int mouseWheelMovement = Mouse.getDWheel();
if (mouseWheelMovement > 0) {
if (this.zoom > fZoomMin) {
this.zoom -= fZoomSpeed;
} else {
this.zoom = fZoomMin;
}
}else if(mouseWheelMovement < 0){
if (this.zoom < fZoomMax) {
this.zoom += fZoomSpeed;
} else {
this.zoom = fZoomMax;
}
}
}
/**
* Update And move the Camera DOTA Stylized movement.
*/
public void updateAndMove() {
float dt = Gdx.graphics.getDeltaTime();
int MouseX = Mouse.getX(); // Get MouseX
int MouseY = Height - Mouse.getY(); // Get MouseY
int camSpeedX = 0;
int camSpeedY = 0;
String horizontalDirection = getMoveLeftRight(MouseX); // Get
// horizontalDirection
String verticalDirection = getMoveUpDown(MouseY); // Get
// verticalDirection
/* * * * * * * *
* Decide what to do with the horizontalDirection.
*/
switch (horizontalDirection) {
case "left":
camSpeedX = ((Width / 2) - (MouseX + (Width / 4)))
/ camSpeedSmoother; // Create Speed -X
camSpeedX = ((camSpeedX > camSpeedMax) ? camSpeedMax : camSpeedX); // Limit
// the
// speed.
if (camVelocityX < camSpeedX)
camVelocityX += camAcceleration;
break;
case "right":
camSpeedX = (((MouseX + (Width / 4)) - ((Width / 4) * 3)) - (Width / 4))
/ camSpeedSmoother; // Create speed +X.
camSpeedX = ((camSpeedX > camSpeedMax) ? camSpeedMax : camSpeedX); // Limit
// the
// speed.
if (camVelocityX < camSpeedX)
camVelocityX += camAcceleration; // Accelerate
camSpeedX *= -1; // To negate the speed.
break;
case "":
camVelocityX = 0;
break;
}
/* * * * * * * *
* Decide what to do with the verticalDirection.
*/
switch (verticalDirection) {
case "up":
camSpeedY = (Height / 4) - MouseY; // Create speed -Y
camSpeedY = ((camSpeedY > camSpeedMax) ? camSpeedMax : camSpeedY); // Limit
// the
// speed.
if (camVelocityY < camSpeedY)
camVelocityY += camAcceleration;
camSpeedY *= -1;
break;
case "down":
camSpeedY = (((MouseY + (Height / 4)) - ((Height / 4) * 3)) - (Height / 4))
/ camSpeedSmoother; // Create speed +Y.
camSpeedY = ((camSpeedY > camSpeedMax) ? camSpeedMax : camSpeedY); // Limit
// the
// speed.
if (camVelocityY < camSpeedY)
camVelocityY += camAcceleration;
break;
case "":
camVelocityY = 0;
break;
}
// System.out.println("vX:" +camVelocityX+ "vY: " +camVelocityY+ "sX: "
// +camSpeedX+ "sY: " +camSpeedY);
this.position.x -= (camVelocityX * camSpeedX) * dt;
this.position.y -= (camVelocityY * camSpeedY) * dt;
this.update();
}
/**
* Get the X-Axial Direction.
*
* #param MouseX
* #return Direction
*/
private String getMoveLeftRight(int MouseX) {
if (MouseX + (Width / 4) < Width / 2) {// Needs to move left?
return "left";
} else if (MouseX > (Width / 4) * 3) {// Needs to move right?
return "right";
}
return "";
}
/**
* Get the Y-Axial Direction.
*
* #param MouseY
* #return Direction
*/
private String getMoveUpDown(int MouseY) {
if (MouseY < Height / 4) {// Needs to move up?
return "up";
} else if (MouseY > (Height / 4) * 3) {// Needs to move down?
return "down";
}
return "";
}
Came across this problem and discovered the answer here:
https://gamedev.stackexchange.com/questions/27786/camera-coordinate-to-screen-coordinate
Supposedly, using Camera.unproject(Vector3 screenCoords) is the correct way of doing this.
My solution looks like this:
Vector3 getMousePosInGameWorld() {
return camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
}
I hope you found the solution to what you need here
https://gamedev.stackexchange.com/questions/60703/libgdx-how-to-get-mouse-position-relative-to-a-tiled-map
maybe here
Get cursor position in LIBGDX
or here
http://www.netthreads.co.uk/2012/01/31/libgdx-example-of-using-scene2d-actions-and-event-handling/

Image over another already drawn image in CAPTCHA

I want to generate a captcha by myself without using any other API, but here are some issues. In my code I have treated each character as an image and then form some operation on them but now I want to rotate whole image with respect to its midpoint.
Here is my sample code:
for (int i = 0; i < charsToPrint; i++)
{
double randomValue =Math.random();
int randomIndex = (int) Math.round(randomValue * (chars.length - 1));
char characterToShow = chars[randomIndex];
finalString.append(characterToShow);
int charWidth = fontMetrics.charWidth(characterToShow);
int charDim = Math.max(maxAdvance, fontHeight);
//int halfCharDim = (int) (charDim / 2);
charImage = new BufferedImage(charDim, charDim,BufferedImage.TYPE_INT_ARGB);
charGraphics = charImage.createGraphics();
charGraphics.setColor(textColor);
charGraphics.setFont(textFont);
int rn = ran.nextInt((20 - 10) + 1) + 10;
x1=charDim/rn;
int rn1 = ran.nextInt((20 - 10) + 1) + 10;
y1=charDim/rn1;
int charX = (int) ((0.5 * charDim - 0.5 * charWidth)+x1);
int charY=(int) ((charDim - fontMetrics.getAscent()) / 2 + fontMetrics.getAscent()+y1);
charGraphics.drawString("" + characterToShow, charX, charY);
float x = horizMargin + spacePerChar * (i) - charDim / 2.0f;
int y = (int) ((height - charDim) / 2);
g.setColor(Color.GREEN);
g.drawImage(charImage, (int) (x+x1), (int)(y+y1), charDim,charDim, null,null);
charGraphics.dispose();
}

Java, Colours of a buffered image are completely different to the original image

I am trying to add some texture to my game. I am running into some problems getting the image to display properly.
This is what the texture should look like, just a boring black square:
And this is what I get. A little bit of black with blue lines.
This is the code I used to import the image. The BufferedImage is set to Type_INT_RGB:
package com.mime.minefront.graphics;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Texture {
public static Render floor = loadBitmap("/textures/floorb.png");
public static Render loadBitmap(String fileName) {
try {
BufferedImage image = ImageIO.read(Texture.class.getResource(fileName));
int width = image.getWidth();
int height = image.getHeight();
Render result = new Render(width, height);
image.getRGB(0, 0, width, height, result.pixels, 0, width);
return result;
} catch (Exception e) {
System.out.println("CRASH!");
throw new RuntimeException(e);
}
}
}
Any help or advice would be great. I have tried to search for the answer but with no luck.
This is my Render class.
package com.mime.minefront.graphics;
public class Render {
public final int width;
public final int height;
public final int[] pixels;
public Render(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}
public void draw(Render render, int xOffset, int yOffset) {
for (int y = 0; y < render.height; y++) {
int yPix = y + yOffset;
if (yPix < 0 || yPix >= height) {
continue;
}
for (int x = 0; x < render.width; x++) {
int xPix = x + xOffset;
if (xPix < 0 || xPix >= width) {
continue;
}
int aplha = render.pixels[x + y * render.width];
if (aplha > 0) {
pixels[xPix + yPix * width] = aplha;
}
}
}
}
}
and this is my Render3D class
package com.mime.minefront.graphics;
import com.mime.minefront.Game;
import com.mimi.minefront.input.Controller;
import com.mimi.minefront.input.InputHandler;
import java.awt.Robot;
import java.util.Random;
public class Render3D extends Render {
public double[] zBuffer;
private double renderDistance = 5000;
private double forward, right, up, cosine, sine;
public Render3D(int width, int height) {
super(width, height);
zBuffer = new double[width * height];
}
public void floor(Game game) {
double floorPosition = 8;
double cellingPosition = 8;
forward = game.controls.z;
right = game.controls.x;
up = game.controls.y;
double walking = Math.sin(game.time / 6.0) * 0.5;
if (Controller.crouchWalk) {
walking = Math.sin(game.time / 6.0) * 0.25;
}
if (Controller.runWalk) {
walking = Math.sin(game.time / 6.0) * 0.8;
}
double rotation = 0;//Math.sin(game.time / 20) * 0.5; //game.controls.rotation;
cosine = Math.cos(rotation);
sine = Math.sin(rotation);
for (int y = 0; y < height; y++) {
double celling = (y - height / 2.0) / height;
double z = (floorPosition + up) / celling;
if (Controller.walk) {
z = (floorPosition + up + walking) / celling;
}
if (celling < 0) {
z = (cellingPosition - up) / -celling;
if (Controller.walk) {
z = (cellingPosition - up - walking) / -celling;
}
}
for (int x = 0; x < width; x++) {
double depth = (x - width / 2.0) / height;
depth *= z;
double xx = depth * cosine + z * sine;
double yy = z * cosine - depth * sine;
int xPix = (int) (xx + right);
int yPix = (int) (yy + forward);
zBuffer[x + y * width] = z;
pixels[x + y * width] = //((xPix & 15) * 16 | ((yPix % 15) * 16) << 8);
Texture.floor.pixels[xPix & 7] + (yPix & 7) * 8;
if (z > 500) {
pixels[x + y * width] = 0;
}
}
}
}
public void renderWall(double xLeft, double xRight, double zDistance, double yHeight) {
double xcLeft = ((xLeft) - right) * 2;
double zcLeft = ((zDistance) - forward) * 2;
double rotLeftSideX = xcLeft * cosine - zcLeft * sine;
double yCornerTL = ((-yHeight) - up) * 2;
double yCornerBL = ((+0.5 - yHeight) - up) * 2;
double rotLeftSideZ = zcLeft * cosine + xcLeft * sine;
double xcRight = ((xRight) - right) * 2;
double zcRight = ((zDistance) - forward) * 2;
double rotRightSideX = xcRight * cosine - zcLeft * sine;
double yCornerTR = ((-yHeight) - up) * 2;
double yCornerBR = ((+0.5 - yHeight) - up) * 2;
double rotRightSideZ = zcRight * cosine + xcRight * sine;
double xPixelLeft = (rotLeftSideX / rotLeftSideZ * height + width / 2);
double xPixelRight = (rotRightSideX / rotRightSideZ * height + width / 2);
if (xPixelLeft >= xPixelRight) {
return;
}
int xPixelLeftInt = (int) (xPixelLeft);
int xPixelRightInt = (int) (xPixelRight);
if (xPixelLeftInt < 0) {
xPixelLeftInt = 0;
}
if (xPixelRightInt > width) {
xPixelRightInt = width;
}
double yPixelLeftTop = (yCornerTL / rotLeftSideZ * height + height / 2);
double yPixelLeftBottom = (yCornerBL / rotLeftSideZ * height + height / 2);
double yPixelRightTop = (yCornerTR / rotRightSideZ * height + height / 2);
double yPixelRightBottom = (yCornerBR / rotRightSideZ * height + height / 2);
double tex1 = 1 / rotLeftSideZ;
double tex2 = 1 / rotRightSideZ;
double tex3 = 0 / rotLeftSideZ;
double tex4 = 8 / rotRightSideZ - tex3;
for (int x = xPixelLeftInt; x < xPixelRightInt; x++) {
double pixelRotation = (x - xPixelLeft) / (xPixelRight - xPixelLeft);
double xTexture= (int) ((tex3+tex4*pixelRotation)/tex1+(tex2-tex1)*pixelRotation);
double yPixelTop = yPixelLeftTop + (yPixelRightTop - yPixelLeftTop) * pixelRotation;
double yPixelBottom = yPixelLeftBottom + (yPixelRightBottom - yPixelLeftBottom) * pixelRotation;
int yPixelTopInt = (int) (yPixelTop);
int yPixelBottomInt = (int) (yPixelBottom);
if (yPixelTopInt < 0) {
yPixelTopInt = 0;
}
if (yPixelBottomInt > height) {
yPixelBottomInt = height;
}
for (int y = yPixelTopInt; y < yPixelBottomInt; y++) {
pixels[x + y * width] = (int) xTexture*100;
zBuffer[x + y * width] = 0;
}
}
}
public void renderDistanceLimiter() {
for (int i = 0; i < width * height; i++) {
int colour = pixels[i];
int brightness = (int) (renderDistance / (zBuffer[i]));
if (brightness < 0) {
brightness = 0;
}
if (brightness > 255) {
brightness = 255;
}
int r = (colour >> 16) & 0xff;
int g = (colour >> 8) & 0xff;
int b = (colour) & 0xff;
r = r * brightness / 255;
g = g * brightness / 255;
b = b * brightness / 255;
pixels[i] = r << 16 | g << 8 | b;
}
}
}
From getRGB() :
Returns an array of integer pixels in the default RGB color model
(TYPE_INT_ARGB) and default sRGB color space, from a portion of the
image data. Color conversion takes place if the default model does not
match the image ColorModel
See if using TYPE_INT_ARGB instead of TYPE_INT_RGB works.

Categories