• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

image resizing

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to image resizing with defect quality of an image using java

Hai all

in may application i have to upload an image thru dataentry form of History

The problem is via my java programme handled by image resizing specifying its width and height and without defect
of an image.

in my application i have set an image in 2 different size. one 400x350 and 250x250

when i upload an image, i have store in the server this image.
i created 2 folder 1 is folder400x350 2 is folder250x250

how this possible?

anyone to know this please help me.
its an urgent
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Smita, please give more details.

I am not able to understand what you want.
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chetan Parekh
in my application upload profiles action showing a dataEntryForm. it contains
upload an image to the server.
and after i have a view profile link , when i click on the viewprofile action
it will display the image with description in short. but the image size this time
400x350 pixels. here the same page i have one link in moredetails...> link.
when i click on the moredetails link it will display the same record with the same
picture but, the picture size is 25x250 pixels with detail information of the profiles

in controlling Java programme to fix a size and without defect a quality.
to display the webpage.

when the user upload an image to any size of their photo.
in my programme needed to arrange of this uploaded image to fix a size itself thru java
programme.

this image can 2 different size.
one is 400x350
second is 250x250

My application contains the link below

UploadProfiles - this form contains details with photo to upload to the server

ViewProfiles - this link show the uploaded profiles in short with phto size is 400x350
eg: phto + descripton in short the moredetails... link here
the same page click on the moredetails link, it will show the details
and picture size is 250x250 pixels
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it is HTML issue.

You can control the size image using HTML.

Check the below code.


[ October 13, 2005: Message edited by: Chetan Parekh ]
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing is, you are displaying image at one place in 400X350 size and another place in 250 X 250 size.

But they are not proportionate.

I suggest you to display 400X400 instead of 400X350.
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chetan Parekh

not a pure html programme
its based on Struts related java programme
how to solve these?
i think you didn't get idea about my requirements
i wanted to upload 1024x600 size of image in my application. I am a user.

the web application of real display section,
when i upload an image, the struts-java-jsp programme to control to fix its size the time of uploading
an image.

1024x600 picture

to 2 diff. size

one is 400x400 and other is 200x350
how this possible?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
User will upload file in SIZE1 and you want to convert and store that file in SIZE2 and SIZE3 using Java?

Am I right about you requirement?
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
User will upload file in SIZE1 and you want to convert and store that file in SIZE2 and SIZE3 using Java?

Am I right about you requirement ?

-/************************************-

YES, I really wants like this way.

SIZE1 can store in size2 and size3 pixels without any defect of quality of the picture
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
User will upload file in SIZE1 and you want to convert and store that file in SIZE2 and SIZE3 using Java

yes, yes
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check getScaledInstance(int, int, int) here and write(java.awt.image.RenderedImage, java.lang.String, java.io.File) here.
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i go thru this way,
my image quality is very low

what to do
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give me the source code?
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this.
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got 100 error messages
Thumbnail.java:2: illegal character: \92
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\tx0\tx959\tx1918\tx2877
\tx3836\tx4795\tx5754\tx6713\tx7672\tx8631\f0\fs20 import com.sun.image.codec.jp
eg.*;\par
^
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please send me the code.
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D:\>java Thumbnail D:\patientSt.jpeg D:\p1.jpeg 120 80 75
Done.

i corrrected the programe
its work now
but one problem is

the picture black color
it can view only the black picture


what happpend
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D:\>java Thumbnail D:\patientSt.jpeg D:\p2.jpeg 120 80 75
Done.

here p1.jpeg is the 390x400


after completing the execution
the image is a black color. not P1.jpeg resizing to 80x80

what happend
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D:\>java Thumbnail D:\p1.jpeg D:\p2.jpeg 120 80 75
Done.

here p1.jpeg is the 390x400


after completing the execution
the image is a black color. not P1.jpeg resizing to 80x80

what happend


Eg.
The user upload the file size is 1024x600

i wanted to resizing this images into two different size


390x400
290x100
how this possible thru this programe


this programme shown an image is black color only
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but you have downloaded which utility from the list?

I will try end.
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the code

import com.sun.image.codec.jpeg.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;

class Thumbnail
{

public static void main(String[] args) throws Exception
{

if (args.length != 5)
{
System.err.println("Usage: java Thumbnail INFILE " +"OUTFILE WIDTH HEIGHT QUALITY");

System.exit(1);
}

// load image from INFILE

Image image = Toolkit.getDefaultToolkit().getImage(args[0]);

MediaTracker mediaTracker = new MediaTracker(new Container());

mediaTracker.addImage(image,0);

mediaTracker.waitForID(0);

// determine thumbnail size from WIDTH and HEIGHT

int thumbWidth = Integer.parseInt(args[2]);

int thumbHeight = Integer.parseInt(args[3]);

double thumbRatio = (double)thumbWidth / (double)thumbHeight;

int imageWidth = image.getWidth(null);

int imageHeight = image.getHeight(null);

double imageRatio = (double)imageWidth / (double)imageHeight;

if (thumbRatio < imageRatio)
{

thumbHeight = (int)(thumbWidth / imageRatio);

}
else
{

thumbWidth = (int)(thumbHeight * imageRatio);
}

// draw original image to thumbnail image object and

// scale it to the new size on-the-fly

BufferedImage thumbImage = new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);

Graphics2D graphics2D = thumbImage.createGraphics();

graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);

graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);

// save thumbnail image to OUTFILE

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(args[1]));

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);

int quality = Integer.parseInt(args[4]);

quality = Math.max(0, Math.min(quality, 100));

param.setQuality((float)quality / 100.0f, false);

encoder.setJPEGEncodeParam(param);

encoder.encode(thumbImage);

out.close();

System.out.println("Done.");

System.exit(0);

}

}
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
continue
the result



D:\>java Thumbnail D:\p1.jpeg D:\p2.jpeg 120 80 75
Done.

here p1.jpeg is the 390x400


after completing the execution
the image is a black color. not P1.jpeg resizing to 80x80

what happend


Eg.
The user upload the file size is 1024x600

i wanted to resizing this images into two different size


390x400
290x100
how this possible thru this programe


this programme shown an image is black color only
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Smitha

Here is working fine at my end.

Please run same program on different machine on your end and see what happened.


[ October 13, 2005: Message edited by: Chetan Parekh ]
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Smitha,

Any updates on the matter?
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for quick updated answering

Thank you very much
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I needed new things

in my web application i wanted to display dynamically viewing an images
from two different table

eg:
table1
id photo content link
1 aaaa dfsdfsdf moreDetails
2 bbbb cvbcbcb moreDetails

table2
id photo content link
1 cccc rtrtrrf moreDetails
2 vvvv erteteb moreDetails

from this above two table when i load my web application eg:www.test.com
then display one time table1 from the photo wtih description

and another time visit the webpage or refresh the page
then display table2 from the photo with description

How to solve this
i needed this struts way method
please give me the code also
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Smitha!!

What I have understood is, you have two tables TABEL1 and TABLE2 with the same structure and same data. When user accesses website for the first time, it will execute query on the TABLE1 and display the image. Now if user refreshes page or coming back from the other page to homepage, it will execute query on TABEL@ and display the image.

Am I right?

Please also tell me why you want to do this? What is the business logic behind this?
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the table1 and table2 containing the image and contents are different.
so i wanted to alternatively or dynamically view the image from 2 different tables

just i needed to dynamically view an image with its description(contents) from two different tables
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
B.Logic

Randomwise accessing the values from the two different table
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generate random number using java.util.Random class.

Now if the number is even then select image from TABLE1, else from TABLE2.


[ October 14, 2005: Message edited by: Chetan Parekh ]
 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
INSERT INTO table1 (name)VALUES('St.Mary's Church');

in my postgreSQL i cannot insert this data directly -'St.Mary's Church'

how to solv this query
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already replied to your private mess regarding this.

Please check it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic