How to detect the size of an image
Hi,
I have a servlet which grabs an image (jpg or gif) from a BLOB stored in my database and sents the image back to the client through the ServletOutputStream. This all works good and the image is presented nicely. However, I now want to have my servlet detect the size of the image, and if it is too big resize the image and return it.
As I am new to images in JAVA I am unsure how to do this and what tools to use for it. I found some information on JAI, but this seems way to elaborate for what I need. Please let me know if anyone knows how to do this.
Thank you and regards,
Joost Schouten
This code figures out the size of any object in bytes. I am not sure about resizing the image though..
public int getSerializedSize(Object object)
try
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
byte[] bytes = baos.toByteArray();
oos.close();
baos.close();
return bytes.length;
catch(Exception e) //not good
e.printStackTrace();
return -1;
}Rishi
Similar Messages
-
How to decrease the size of an image (CS5)?
I need help with how to reduce the size of an image to fit various smaller sizes. E.g. 135 x 380mm, 254 x254mm etc mounted/matted. Therefore, the image must be made smaller than these sizes without losing quality and any part of the image. I am unable to crop to achieve these sizes since I need the full image. These photos were taken by using a Canon D450 camera and in both RAW & JPEG.
Your help is much appreciated.You may want to use Image > Image size... and dial in the sizes you want.
Set your units to mm in the dialog. Turn off resample and you can adjust the final print size.
What I am showing you is called "scaling", changing the print size without throwing out pixels as resample would do. Your image is intact. This is from CS6, but it should be about the same in CS5.
Gene -
How to set the size of an image
hi,
I have a database which contain an image. now i want to retrieve this image & want to show this image in my jsp page as user's defined size. I have following code. My following code shows the original size of an image. Now i want to see different size of this image. How is this possible? I know control the size of this image after saving this image
in a file. but i want to control the size of this image without saving this image in a file? IS it possible ? Is there anybody can help me?
Please help me.
ResultSet rs = null;
PreparedStatement ps=null;
InputStream sImage=null;
byte[] imagebyte=null;
String var;
String name=request.getParameter("RegName") ;
String image =request.getParameter("ImageFile");
out.println(name);
out.println(image);
out.println();
ps=con.prepareStatement("insert into t_image (ID, Image) values(?,?);");
File file =new File(image);
FileInputStream in = new FileInputStream(file);
ps.setInt(1,1234);
ps.setBinaryStream(2,in,(int)file.length());
ps.execute();
rs =stm.executeQuery("select Image from t_image where ID=1234");
if(rs.next()) {
imagebyte =rs.getBytes(1);
response.reset();
response.setContentType("image/jpeg");
%>
<%
response.getOutputStream().write(imagebyte);
%>
<%
response.flushBuffer();
%>With regards
Binahi,
I have a database which contain an image. now i
want to retrieve this image & want to show this
image in my jsp page as user's defined size. I have
following code. My following code shows the original
size of an image. Now i want to see different size
of this image. How is this possible? I know control
the size of this image after saving this image
n a file. but i want to control the size of this
image without saving this image in a file? IS it
possible ? Is there anybody can help me?This has nothing to do with JDBC; you can only store and retrieve the image you have and there's no image manipulation functions in JDBC (nor should there be).
I can see 2 options:
1) serve the image file as is, but in the jsp that writes the html that contains the "<img>" tag that gets it, use the "height" and/or the "width" to scale the suppied image to presentation size you want.
2) find some image manipulation code that will convert the image into the size you want
Option 1 will work well if the problem you have is merely refining the image size for presentation. Option 2 is your only coice if it's the image files size itself you really want to change, not just it's appearance on a page. -
How to control the size of SVG images in epub files?
There is unfortunately no support for SVG files in InDesign.
Most of my images in jpg convertes nicely, but the small ones do not.
Therefore I want to use SVG files which I have created in Illustrator.
But how do I set the size in the epub file? Right now, whatever I do, they come out too big and I don't know how to control the size.
Is there a program, like Sigil or other, that can place the image for me - I'm no html wizard you see....In any Java program, it is good practice to make sure your live objects leave some room in the heap for "scratch space." Without this, you will spend too much time in GC, and, in the worst cases, run out of memory. In the general case, you can see how much live data your application requires by looking at the heap used after a full GC's. For Coherence, you should ensure that live data, as you say, is under 70% of the maximum heap size.
Coherence provides you tools to help enforce this policy. [http://coherence.oracle.com/display/COH35UG/local-scheme] describes how to size limit your cache. By implementing an eviction policy, you can control what happens when a size limit is exceeded. -
How to decrease the size of an Image in iAD
Hello, there!
I am trying to producer a new slide where I can write text in iAD.
I have problems with it though and can you please tell me how to add new slides, where I can either write text or add new objects or assets?
Also when I try to use the CAROUSEL, I can only put it there, but once I put the asset image on it, it doesnt work - I can't place the image in the center of each boxe and it doesn't go full screen once I click on on it through my iPod Touch (5th Generation).
Please answer me those questions and I would be very happy indeedYou may want to use Image > Image size... and dial in the sizes you want.
Set your units to mm in the dialog. Turn off resample and you can adjust the final print size.
What I am showing you is called "scaling", changing the print size without throwing out pixels as resample would do. Your image is intact. This is from CS6, but it should be about the same in CS5.
Gene -
How to define the size of saving image in sm or inch?
Hi,
is it possible to get the image of size defined in sm or inch?
There is no stable proportion between width in pixel and sm.
My purpose is to create a buffered image of defined size ( for example 5x5 sm) and save it. The saving is made with encoder in jpeg.
Thanks and Regards,...didn't find sm in the International System of Units (second � meter ..?)
// Table 1. SI Base Units
Quantity Unit
Name Symbol
length meter m
mass kilogram kg
time second s
electric current ampere A
thermodynamic temperature kelvin K
amount of substance mole mol
luminous intensity candela cd
// Table 2. Examples of SI Derived Units
Quantity Unit
Special Name Symbol Equivalent
plane angle radian rad 1
solid angle steradian sr 1
angular velocity rad/s
angular acceleration rad/2
frequency hertz Hz s-1
speed, velocity m/s
acceleration m/s2
force newton N kg m/s2
pressure, stress pascal Pa N/m2
energy, work, heat joule J kg m2 /s2, N m
power watt W kg m2/s3, J/s
power flux density W/m2
linear momentum, impulse kg m/s, N s
angular momentum kg m2/s, N m s
electric charge coulomb C A s
electric potential, emf volt V W/A, J/C
magnetic flux weber Wb V s
resistance ohm V/A
conductance siemens S A/V, -1
inductance henry H Wb/A
capacitance farad F C/V
electric field strength V/m, N/C
electric displacement C/m2
magnetic field strength A/m
magnetic flux density tesla T Wb/m2, N/(A m)
Celsius temperature degree Celsius C K
luminous flux lumen lm cd sr
illuminance lux lx lm/m2
radioactivity becquerel Bq s-1
// Table 3. SI Prefixes
Factor Prefix Symbol Factor Prefix Symbol
1024 yotta Y 10-1 deci d
1021 zetta Z 10-2 centi c
1018 exa E 10-3 milli m
1015 peta P 10-6 micro μ
1012 tera T 10-9 nano n
109 giga G 10-12 pico p
106 mega M 10-15 femto f
103 kilo k 10-18 atto a
102 hecto h 10-21 zepto z
101 deka d 10-24 yocto yze -
How to get the size of an image?
yhanks
try something like:
// in case 'this' is a JComponent or something similar:
MediaTracker mt = new MediaTracker(this);
mt.addImage(myImg1, 1);
mt.addImage(myImg2, 2);
while (!(mt.checkAll(true))) {
try {
Thread.sleep(10);
} catch (InterruptedException iex) { }
// all loadedThis would load all images registered with the MediaTracker but also blocks execution of your program. You might want to start a different thread for this.
cheers,
kelysar -
How to detect the size in pixels or percentage of a scrolling area?
Hello there!
I'm working capturing scrolling images and found a problem when I try it in another laptop, the thing was the resolution because in mine the scrolled area is added to the principal image and as I go down I merge the scrolling. But in other machines the image appears wrong, with the browser status bar in every scroll.
Can somebody help or give me some other address where I could find something useful?
Thank you in advance.So you have some sort browser with a scrolable view. As scrolling is preformed you add the newly revealed area to an an image. As more area is revealed, the image is made larger to paint the new area in addition to the old area. Ideally when the whole view has been looked at and scrolled through, then the image reflects the entirety of the view. The problem is, on one particular laptop when the user scrolls, the status bar keeps appearing as part of the newly added area, so you end up with an image of the view along with a bunch of status bars painted in various places of the image.
Am I correct so far?
If so, then I guess the question is are we even dealing with Swing components? Why can't you just call
myScrollPane.getViewport().getView();and paint that? -
How to control the size of Database's image
hi,
I have already saved image in database, & i also can retrieve image from database. But My problem is that when i save big image then it shows with it's original size. But i want to see its size what i want? But how this possible?i want to see it's small size. i cannot do it. I know how to control the image with ImageIO . But i don'nt know how to control the size of an image from database. I cannot do it. Please Help me.
Thanks
binaHi,
You can control the database size at technical setting level based on ur requirement. Field name is Size category.
Thanks. -
Does any body knows how to detect the resolution of an inserted image in word?
Does any body knows how to detect the resolution of an inserted image in word?
I'm not sure I understand your reply but when you insert images into Word that are larger than will fit on the page, they are automatically compressed. If you right click and select Size and Position you can restore it to 100% but you will not see all the image.
See www.grainge.org for RoboHelp and Authoring tips
@petergrainge -
How can I set the size of an image in java?
How can I set the size of an image in java? I have to choose the width and height of image...thanks to everybody...sorry for my english :-)
Hi 43477
Can you provide more details, do you want to setsize to display an image on a screen of when saving image etc?
PS.
There is a good invention called googlegoogle is good, but sometimes it's better to use more specific search, there is a search field avove on this page :) -
How do I figure out the size of an image in my iPhoto. Soe applications require a certain size and I have no way of knowing what they are.
Please confirm that Kilobytes are smaller than megabytes and gigabytes are the largest.You're correct, Kilobytes are smaller than megabytes and gigabytes are the largest.
When you attach the images to an email, look on the bottom line for the total size of the email. You can also change the image from Actual size to medium or small. -
How to decrease the size of image using a java peogram
Hi All,
I want to decrease the size of an image from MB to KB. I have some images of size around 1MB to 3MB. While displaying all those images in the browser it is taking so much time to download all those and display. So I want to write a Java program to make a duplicate copies of those images, which are small in height and width and display those images in small size. Basically I need to display all the list of images as thumbnail view or list view with faster speed.
Thanks in advance..
Upendra P.I read the documentation. There is no corresponding Image class. The other
classes are like BufferedImage and all.Yes BufferedImage sounds like what you want.
You could (1) Read the image (2) Obtain its dimensions and create a blank
scaled image (3) Draw a scaled version of the original image using the
Graphics2D obtained from the smaller one. (4) Save the smaller image.
The javax.util.ImageIO class will help with reading and writing the data and
Sun's Tutorial has a section on "2D Graphics". -
For the life of me, I can't find out what size a photo is in terms of inches or how to change the size of the photo[s] so I can print them. I think I read somewhere to click edit, then click adjust. I don't see anything about re-sizing when I click the adjust tab: only saturation and tint levels. Thank you.
With respect to digital images, there really is no size in inches. The size is given as number of pixels horizontally and vertically. In iPhoto '09 you click the little "i" inthe lower right side of the window and it will display information related to the selected photo, including the pixel dimensions. I do not have iPhoto '11 installed so I don't know if it is the same there.
In some applications, such as preview, it has something additional called Dots per Inch (DPI) which you would think would allow you to convert the pixel dimensions to inches. It is not a real thing, though. The DPI is determined by how large or small you have chosen to print your photo and the capabilities of your printer.
There is also something called Aspect Ratio, which is usually expressed in inches x inches such as 6x9 but that doesn't mean the size on the screen or when printed is 6x9. It is the ratio of the pixel dimensions. When cropping your photos, you will have several standard aspect ratios to choose from plus any custom ones you create.
In iPhoto '09, after you choose Print, in the Print Setting window are the settings for the size you want the photo printed. You want to shoose a setting with the same aspect ratio of your photo. Otherwise, iPhoto will resize and/or crop your photo to fit the size you have chosen. -
How to change the size of control´s prompt?
No matter the size of data to be displayed in the view suface prompt, the controls have the same size.
Does anyone here know how to change the size of control in surface prompt?HI,
In order to change the size of a radio button... one way you may consider is to Customise the Radio Button.
Place a Radio Button (RB) on the FP of a VI, Right-Click the RB > Advanced > Customise...
Click the Mode Button (most Left button) for Edit Mode
Right-click the radio button (the round image) now, you will see a list of actions i.e. Copy to clipboard, import picture ...You will see Four images under the 'Picture Item', those are the images that you will need to replace.
Prepare Four Images of the similar but larger expected size
*** Copy the 1st new image to clipboard. Back to the Picture Item and select 1st image. Then, select Import Picture (to replace the existing image)
Repeat *** for all four images.
Once done, change the mode back to original. Save the *.ctl
You are now ready to use the customised radio button!
Quick sample attached (sorry for the poor images created )
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010
依恩与LabVIEW
LVVILIB.blogspot.com
Attachments:
IFK_RButton_Large.ctl 11 KB
Maybe you are looking for
-
Newly added column not displayed in Interactive report
Hello, I have a tableA with 3 columns.In the application i am displaying as Form with Report region as Interactive report(Oracle 10g Application Express 3.2). I added one column to tableA.Now when i am refreshing the report by adding that column in t
-
Com.mysql.jdbc.JDBC4Connection suspected memory leak in java
We have a java application where we are using Bonecp pooling library. Below is how we setup the pooling. [code] try { // setup the connection pool BoneCPConfig config = new BoneCPConfig(); config.setJdbcUrl("jdbc:mysql://**.**.**.**:3306/test
-
User status for investment order to block settlement to final asset
Hi, I try to set up a user status to avoid user to settle internal/ investment order to final asset. I cannot find a user status that will let me make the distinction between the automatic settlement to AuC and the partial or full settlement to final
-
Is there any way to move completed items from one list to another, or to merge Reminder lists? For instance, if I set up a list called This Weekend and a bunch of those items are now completed, I find that I can't move those items onto another list (
-
I've seen this bug since version 1.0, and it still hasn't been fixed as of 1.4.2 (and engineering does know about it). On my main MDC, whenever I mount a firewire drive, and then dismount it and power it off, xsan admin becomes unresponsive (getting