convert c# code to java

Hi,

I have the below small c# code that i need to convert to Java.

Hope someone who knows the 2 programming languages help me to convert it to java.

thanks.

protectedvoid Page_Load(object sender, EventArgs e)

{

}

void button_Click(object sender, EventArgs e)

{

Bitmap objBitmap =new Bitmap(108, 80);

Graphics objGraphics = Graphics.FromImage(objBitmap);

System.Drawing.Image fullSizeImg;

fullSizeImg = System.Drawing.Image.FromFile("e:\\temp\\Laura_001.jpg");

System.Drawing.Image thumbNailImg;

thumbNailImg = Crop(fullSizeImg, 100, 74);

thumbNailImg.Save("E:\\temp\\cropped.jpg", ImageFormat.Jpeg);

System.Drawing.Image objImage2 = System.Drawing.Image.FromFile("e:\\temp\\projectFrame.gif");

objGraphics.DrawImage(thumbNailImg, 0, 0, 100, 74);

objGraphics.DrawImage(objImage2, 0, 0, 108, 80);

objBitmap.Save("E:\\temp\\final.jpg", ImageFormat.Jpeg);

objGraphics.Dispose();

fullSizeImg.Dispose();

thumbNailImg.Dispose();

objImage2.Dispose();

}

private System.Drawing.Image Crop(System.Drawing.Image original,int Width,int Height)

{

int sourceWidth = original.Width;

int sourceHeight = original.Height;

int sourceX = 0;

int sourceY = 0;

int destX = 0;

int destY = 0;

float nPercent = 0;

float nPercentW = 0;

float nPercentH = 0;

nPercentW = (((float)(Width)) / ((float)(sourceWidth)));

nPercentH = (((float)(Height)) / ((float)(sourceHeight)));

if (nPercentH < nPercentW)

{

nPercent = nPercentW;

destY = ((int)(((Height - (sourceHeight * nPercent)) / 2)));

}

else

{

nPercent = nPercentH;

destX = ((int)(((Width - (sourceWidth * nPercent)) / 2)));

}

int destWidth = ((int)((sourceWidth * nPercent)));

int destHeight = ((int)((sourceHeight * nPercent)));

Bitmap bmPhoto =new Bitmap(Width, Height, PixelFormat.Format24bppRgb);

bmPhoto.SetResolution(original.HorizontalResolution, original.VerticalResolution);

Graphics grPhoto = Graphics.FromImage(bmPhoto);

grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;

grPhoto.DrawImage(original,new Rectangle(destX, destY, destWidth, destHeight),new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);

grPhoto.Dispose();

return bmPhoto;

}

[3892 byte] By [Servant@AKa] at [2007-11-27 2:23:37]
# 1
The Graphics tutorial may help you: http://java.sun.com/docs/books/tutorial/2d/index.html
DrLaszloJamfa at 2007-7-12 2:29:26 > top of Java-index,Java Essentials,Java Programming...
# 2

i wrote below 2 java methods:the cropping works but the image quality is poor.

how can i get highest image rendering quality ?

thanks.

public static GraphicsConfiguration getDefaultConfiguration() {

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice gd = ge.getDefaultScreenDevice();

return gd.getDefaultConfiguration();

}

private BufferedImage Crop(BufferedImage original, int Width, int Height)

{

int sourceWidth = original.getWidth();

int sourceHeight = original.getHeight();

int sourceX = 0;

int sourceY = 0;

int destX = 0;

int destY = 0;

float nPercent = 0;

float nPercentW = 0;

float nPercentH = 0;

nPercentW = (((float)(Width)) / ((float)(sourceWidth)));

nPercentH = (((float)(Height)) / ((float)(sourceHeight)));

if (nPercentH < nPercentW)

{

nPercent = nPercentW;

destY = ((int)(((Height - (sourceHeight * nPercent)) / 2)));

}

else

{

nPercent = nPercentH;

destX = ((int)(((Width - (sourceWidth * nPercent)) / 2)));

}

int destWidth = ((int)((sourceWidth * nPercent)));

int destHeight = ((int)((sourceHeight * nPercent)));

int transparency = original.getColorModel().getTransparency();

GraphicsConfiguration gc=getDefaultConfiguration();

BufferedImage bmPhoto = gc.createCompatibleImage(Width, Height,transparency);//new BufferedImage(Width, Height, BufferedImage.TYPE_INT_RGB);

// bmPhoto.SetResolution(original.get, original.VerticalResolution);

Graphics2D grPhoto = bmPhoto.createGraphics();

grPhoto.setRenderingHint(RenderingHints.KEY_INTERPOLATION,

RenderingHints.VALUE_INTERPOLATION_BICUBIC);

//grPhoto.dra

grPhoto.drawImage(original,destX, destY, destWidth, destHeight,sourceX, sourceY, sourceWidth, sourceHeight,null);// new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight));

grPhoto.dispose();

return bmPhoto;

}

Servant@AKa at 2007-7-12 2:29:26 > top of Java-index,Java Essentials,Java Programming...