Click here to Skip to main content
15,898,371 members
Home / Discussions / Java
   

Java

 
QuestionUsing Javascript to list local directory contents Pin
Member 84548753-Dec-11 19:17
Member 84548753-Dec-11 19:17 
AnswerRe: Using Javascript to list local directory contents Pin
Richard MacCutchan3-Dec-11 21:30
mveRichard MacCutchan3-Dec-11 21:30 
AnswerRe: Using Javascript to list local directory contents Pin
TorstenH.4-Dec-11 23:55
TorstenH.4-Dec-11 23:55 
GeneralSteganography in Images and Audio Pin
khanhhungict3-Dec-11 18:35
khanhhungict3-Dec-11 18:35 
Answerhanoi tower Pin
bhira29-Nov-11 22:34
bhira29-Nov-11 22:34 
GeneralRe: hanoi tower Pin
TorstenH.29-Nov-11 22:52
TorstenH.29-Nov-11 22:52 
GeneralRe: hanoi tower Pin
RaviRanjanKr3-Dec-11 10:12
professionalRaviRanjanKr3-Dec-11 10:12 
Generalimage procesing in java Pin
palikalirona29-Nov-11 20:10
palikalirona29-Nov-11 20:10 
resize

private BufferedImage resizeImage(BufferedImage originalImage, int type,int width, int hieght){
BufferedImage resizedImage = new BufferedImage(width, hieght, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, width, hieght, null);

g.dispose();

return resizedImage;
}

convert into gray scale

public static BufferedImage convertToGrayscale(BufferedImage source) {
BufferedImageOp op = new ColorConvertOp(
ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
return op.filter(source, null);
}

public BufferedImage gray(BufferedImage source)
{


BufferedImage image = new BufferedImage(source.getWidth(), source.getHeight(),
BufferedImage.TYPE_BYTE_BINARY);
// BufferedImage.);

Graphics g = image.getGraphics();
g.drawImage(source, 0, 0, null);
g.dispose();



return image;
}


rotate

public static BufferedImage rotate(BufferedImage img, int angle) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = dimg = new BufferedImage(h, w, img.getType());
Graphics2D g = dimg.createGraphics();
g.rotate(Math.toRadians(angle), h/2, w/2);
g.drawImage(img, null, 0, 0);
return dimg;
}


horizontalflip

C#
public static BufferedImage horizontalflip(BufferedImage img) {
        int w = img.getWidth();
        int h = img.getHeight();
        BufferedImage dimg = new BufferedImage(w, h, img.getType());
        Graphics2D g = dimg.createGraphics();
        g.drawImage(img, 0, 0, w, h, w, 0, 0, h, null);
        g.dispose();
        return dimg;
    }



dithering

public static BufferedImage processImage(BufferedImage inputImage) {

// Create a binary image for the results of processing

int w = inputImage.getWidth();
int h = inputImage.getHeight();
BufferedImage outputImage = new BufferedImage(w, h,
BufferedImage.TYPE_BYTE_BINARY);

// Work on a copy of input image because it is modified by diffusion

WritableRaster input = inputImage.copyData(null);
WritableRaster output = outputImage.getRaster();

final int threshold = 180;
float value, error;

for (int y = 0; y < h; ++y)
for (int x = 0; x < w; ++x) {

value = input.getSample(x, y, 0);

// Threshold value and compute error

if (value < threshold) {
output.setSample(x, y, 0, 0);
error = value;
}
else {
output.setSample(x, y, 0, 1);
error = value - 255;
}

// Spread error amongst neighbouring pixels

if((x > 0) && (y > 0) && (x < (w-1)) && (y < (h-1)))
{
value = input.getSample(x+1, y, 0);
input.setSample(x+1, y, 0, clamp(value + 0.4375f * error));
value = input.getSample(x-1, y+1, 0);
input.setSample(x-1, y+1, 0, clamp(value + 0.1875f * error));
value = input.getSample(x, y+1, 0);
input.setSample(x, y+1, 0, clamp(value + 0.3125f * error));
value = input.getSample(x+1, y+1, 0);
input.setSample(x+1, y+1, 0, clamp(value + 0.0625f * error));
}

}
return outputImage;

}

// Forces a value to a 0-255 integer range

public static int clamp(float value) {
return Math.min(Math.max(Math.round(value), 0), 255);
}


public static final int getColorIndexSize(RenderedImage img) {
ColorModel cm = img.getColorModel();
if (cm instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel)cm;
return icm.getMapSize();
} else {
return 0;
}
}
GeneralRe: image procesing in java Pin
Richard MacCutchan29-Nov-11 21:44
mveRichard MacCutchan29-Nov-11 21:44 
GeneralRe: image procesing in java Pin
Nagy Vilmos5-Dec-11 1:58
professionalNagy Vilmos5-Dec-11 1:58 
GeneralRe: image procesing in java Pin
Richard MacCutchan5-Dec-11 2:21
mveRichard MacCutchan5-Dec-11 2:21 
GeneralRe: image procesing in java Pin
bharath S h14-Dec-11 15:25
bharath S h14-Dec-11 15:25 
GeneralRe: image procesing in java Pin
Richard MacCutchan14-Dec-11 22:07
mveRichard MacCutchan14-Dec-11 22:07 
QuestionRe: image procesing in java Pin
bharath S h14-Dec-11 15:27
bharath S h14-Dec-11 15:27 
GeneralRe: image procesing in java Pin
RaviRanjanKr3-Dec-11 10:17
professionalRaviRanjanKr3-Dec-11 10:17 
GeneralRe: image procesing in java Pin
bharath S h1-Mar-12 17:37
bharath S h1-Mar-12 17:37 
Questionarray sort performance java vs .net c# Pin
nipsonanomimata29-Nov-11 3:12
nipsonanomimata29-Nov-11 3:12 
AnswerRe: array sort performance java vs .net c# Pin
David Skelly29-Nov-11 3:46
David Skelly29-Nov-11 3:46 
AnswerRe: array sort performance java vs .net c# Pin
TorstenH.30-Nov-11 0:49
TorstenH.30-Nov-11 0:49 
GeneralRe: array sort performance java vs .net c# Pin
nipsonanomimata30-Nov-11 1:03
nipsonanomimata30-Nov-11 1:03 
QuestionJTable cell not going away! SOLVED Pin
venomation26-Nov-11 16:34
venomation26-Nov-11 16:34 
AnswerRe: JTable cell not going away! SOLVED Pin
TorstenH.27-Nov-11 22:33
TorstenH.27-Nov-11 22:33 
Questionhelp.... Pin
djamelm6126-Nov-11 1:50
djamelm6126-Nov-11 1:50 
AnswerRe: help.... Pin
Richard MacCutchan26-Nov-11 2:39
mveRichard MacCutchan26-Nov-11 2:39 
GeneralRe: help.... Pin
mirzabeigi8-Dec-11 7:42
mirzabeigi8-Dec-11 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.