Problem about set the size of an image
Dear all,
I encountered the following problem when programming with
action script.
I've got an image component. And I'd like to load the picture
dynamically.
So I called the function loadMovie like this:
this.loadMovie( url );
It seems work for me.
But when I wanted to change the size of the image, the
picture disappeared.
I added the following line under the loadMovie function:
this._width=500;
this._height=500;
Would anyone be kind enough to give any hintsto solve my
problem?
Any help would be appreciated and thanks in advance.
resize the image file before it's loaded.
Or you can call getScaledInstance on the Image object... which you can get from the ImageIcon, then construct a new ImageIcon with the scaled image.
Similar Messages
-
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 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. -
Yet another question about setting the size of a JTextField
Hello,
yep, I already looked at the other posts & the API.
I have tried the following (& other code) to try to set the width of the display. Nothing works so far.
percent_CO2 = new JTextField();
percent_CO2.setColumns(8);
percent_CO2.setToolTipText("The % Carbon Dioxide relates to ...");
percent_CO2.setPreferredSize(new Dimension(10,20));
percent_CO2.setMaximumSize (new Dimension(10,20)); This is one of several JTextField's on a Jpanel defined as :
jcommonCharPanel.setLayout( new GridLayout(8, 2, 2, 4) );
//8 rows, 2 columns, vertical & horizontal gaps of 2 & 4Any ideas why it is so difficult to set the size of the JTextField?
Should I try to limit the size of the JPanel instead?
thanks,
-- HSC --http://forum.java.sun.com/thread.jsp?forum=54&thread=379656
-
Question about setting the background from an image over the internet.
Hello ,
If I want the background of my panel to be set from an image over the internet directly do I just add that URL right away like this :
protected final static String imagePath = "http://www.engr.wisc.edu/2010/background.jpg";
icon = new ImageIcon(AuthScreen.imagePath);
JPanel panel = new JPanel(){
protected void paintComponent(Graphics g)
Dimension d = getSize();
g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
super.paintComponent(g);
};instead of this :
protected final static String imagePath = "d:\\javaapps\\bg.jpg";cuz I did that but it isnt working .
Thanks.I don't see how, try it out:
import java.awt.*;
import java.awt.image.*;
import java.net.URL;
import javax.swing.*;
import javax.imageio.*;
public class ForumJunk{
ForumJunk(){
JFrame f = new JFrame("Forum Junk");
JPanel p = new MyJPanel();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setVisible(true);
public static void main(String[] args) {
new ForumJunk();
class MyJPanel extends JPanel{
BufferedImage bi = null;
MyJPanel(){
try{
bi = ImageIO.read(new URL("http://www.kodiakfishingbc.com/Editor/assets/chris03resize.jpg"));
this.setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight()));
}catch(java.io.IOException e){
System.out.println(e.toString());
public void paintComponent(Graphics g){
// super.paintComponent(g);
((Graphics2D)g).setBackground(Color.green);
g.clearRect(0, 0, bi.getWidth(), bi.getHeight());
g.drawImage(bi,0, 0, this);
super.paintComponent(g);
} -
Setting the size of a JComponent which is not currently shown
Hi,
I got a problem to set the size of a maybe JButton, before the button is displayed on screen.
Assume i got a button without any text.
Then the button length and height is 0 before the button
is displayed.
But i don't want to set the width and height of the
button dynamically in the paint method for performance
reason.
I got only the trick to set a JButton with like this
JButton b = new JButton(" ");But this is not nice.
I found no method in a JComponent to set the
size of a component static in the constructor.
The usage of setPrefferedSize() etc. don't work
until the component is not displayed.
So is there a way to compute the size of a Component
before displaying?
regards
OlekIt seems that there is no way to calculate the size via legacy methods.as already mentioned, it has a preferredSize and all you need do is something like this
import javax.swing.*;
import java.awt.*;
class Testing
public void buildGUI()
JFrame f = new JFrame();
f.getContentPane().add(getPanel("Hello"),BorderLayout.NORTH);
f.getContentPane().add(getPanel("Hello World"),BorderLayout.CENTER);
f.getContentPane().add(getPanel("Goodbye"),BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
public JPanel getPanel(String buttonText)
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton btn = new JButton(buttonText);
Dimension d = btn.getPreferredSize();
JLabel label = new JLabel("w = "+d.width+", h = "+d.height);
p.add(label);
p.add(btn);
return p;
public static void main(String[] args)
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}[EDIT]
just reread your first post, you want to set (not get) the size (thwak!, uppercut)
first reply amended
import javax.swing.*;
import java.awt.*;
class Testing
public void buildGUI()
JFrame f = new JFrame();
f.getContentPane().add(getPanel(62,26),BorderLayout.NORTH);
f.getContentPane().add(getPanel(99,26),BorderLayout.CENTER);
f.getContentPane().add(getPanel(83,26),BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
public JPanel getPanel(int w, int h)
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));
JButton btn = new JButton();
btn.setPreferredSize(new Dimension(w,h));
Dimension d = btn.getPreferredSize();
JLabel label = new JLabel("w = "+d.width+", h = "+d.height);
p.add(label);
p.add(btn);
return p;
public static void main(String[] args)
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new Testing().buildGUI();
}Edited by: Michael_Dunn on Nov 6, 2007 4:40 AM -
How to set the size of combo box using jsf
I face problem when i set the size of a combo in jsf
Is it not possible to use it with a GridBagLayout?Your question was "How do I get a tabbed pane to take all the space of the frame"?
You where given the answer. Did you try it? Did it work? Then why are you questioning the suggestion?
Its one line of code if you use a BorderLayout which by the way was specifically designed for this purpose.
Yes you can do it with a GridBagLayout with about 5 lines of code.
So the question is why would you want to write 5 lines of code when you can use one?
If your question was "How do I waste my time forcing the GridBagLayout to size a component to take up all the space of the frame", then you would have received a different answer. (Although most people would have told you to use a BorderLayout anyway, since its easier). -
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 -
Why is the size of new image constructed using Bufferd Image class less?
I am trying to compress image losslessly, for start I what I am doing is:
step1. Access pixels of .jpg image and store in array
Step2. Reconstruct the image from same array
What I have found is, that the size of new image constructed is less than the original.
I am pasting the code below
public static void main(String[] args) {
BufferedImage sourceImage = null;
try {
sourceImage = ImageIO.read(new File("Sample.jpg"));
} catch (IOException e) {
int type = sourceImage.getType();
int w = sourceImage.getWidth();
int h = sourceImage.getHeight();
byte[] pixels = null;
if (type == BufferedImage.TYPE_3BYTE_BGR) {
System.out.println("type.3byte.bgr");
pixels = (byte[]) sourceImage.getData().getDataElements(0, 0, w, h, null);
try {
BufferedImage edgesImage = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
edgesImage.getWritableTile(0, 0).setDataElements(0, 0, w, h, pixels);
ImageIO.write(edgesImage, "jpg", new File("result.jpg"));
} catch (IOException e) {
Please could any one explain me why is it so?I am working on a IEEE paper where in I am supposed to achieve a better compression ratios as compared to current JPEG standards. So if only loading and displaying the image results in size reduction and quality too, how do I go ahead with my algorithmI suggest you:
(a) start with images in an uncompressed format such as TIFF, rather than a format which is already lossy (JPEG)
(b) acquire some basic knowledge about JPEG before you attempt to improve on it, and
(c) learn to quote accurately. Otherwise your paper will be refereed out of existence. I didn't say anything about 'loading and displaying the image resulting in size reduction and quality too'. I said 'loading and storing'; and 'change the contents', not 'size reduction and quality too'.
A JPEG load and store operation does not result in a bitwise identical file. Frankly you should already know that. -
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 set the size of printing subject
I have a deskjet 3520 all in one and my computer is a laptop dv6 with windows7 prof. 64bit.
I want to print out PCB traces so that I can make my own but I don't know to how set the size
with this printer. They take up the whole page when I want them to be 2.35x3.35.
Don't know if this can be done with this printer.
Any help would be apreciated.
This question was solved.
View Solution.Can you post a link to a sample, or upload here a sample? That would make it easier to debug what is going on.
Bob Headrick, HP Expert
I am not an employee of HP, I am a volunteer posting here on my own time.
If your problem is solved please click the "Accept as Solution" button ------------V
If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V -
How to set the size of SUM()/SUM() of NUMBER Tyep?
I met the oracle truncation error when I post the
SUM(a field)/SUM(b field), a and b field are NUMBER Type
From the OCI Doc, Numbers with up to 38 digits precision.
and I set the size of data buffer 41 for NUMBER TYPE.
(for example)
rc = OCIDefineByPos( hstmt, &m_pDefine, ((CEBOracle *)pDatabase)->m_hpErr, index,
(dvoid *) m_lpszBindData, m_nBufSize+1, SQLT_STR,
(dvoid *) m_cbIndicator, (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT);
I always set the output datatype as SQLT_STR
and m_nBufSize is 41 for NUMBER Type
my client met the error when the result is 0.00012345678912345678912345678912345678912
I think that it's not a solution that just enlarge the number form 41 -> 45
How can I avoid this problem when user send the SQL Statement that the result has unlimited decimal number?
Thank you in advancdORA-01406 fetched column value was truncated
I found the reason of that problem.
I migrated from OCI Ver7 to Ver8
If I set the buffer size to 10 (actually 40 in my program) and the result was
0.0000000000000000001
When I debuged the output buffer
The result was 1.0E-19
but now 0.00000000 and truncation error
how to change floating point and scientific expression automatically depend on the result like OCI Ver7 and SQL PLUS?
I changed define function
odefin(m_hstmt, ii+1, (UCHAR *) m_lpszData[ii], m_lpLength[ii]+1, SQLT_STR, -1, m_lpcbValue[ii], 0, -1, -1, 0, 0);
to
m_rc = OCIDefineByPos( m_hstmt, &pDef, ((CEBOracle*) m_pDatabase)->m_hpErr, ii+1,
(dvoid *) m_lpszData[ii], m_lpLength[ii]+1, SQLT_STR,
(dvoid *) m_lpcbValue[ii], (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT ); -
How to set the size of popups from KM Navigation Iview
Hello guys
Does any of you know how I can set the size of the window that pops up when you click on a resource/file in a KM navigation iview?
I have tried to enter "width=100,height=100" (without the quotes) in the Window Features property of the KM Navigation Iview, but it does not influence the size of the popups.
Any suggestions to what could be wrong? Or is it not possible at all to control the size of that popup?
Kind regards,
MartinHi,
I cheched yesterday if I could find the command, sorry I couldn't.
I also realized that the layout generates html link tags (ie. <a />) for the resource links, no javascript open link functions (ie. window.open), wich doesn't alowed (as far as I know) to give size to the pop-up window.
So to make the link of the resource (gived by the <b>displayname(contectlink)</b> property set) I think you would have to <i>create (develop)</i> the layout, so the link will be rendered with window_size.
You have other option, you can take off the "<i>contentLink</i>" setting. and add the <b>download</b> command, so the user who want to open / save the document can click on this command and do it in their PC.
I.E, Create a copy of the <b>download</b>, and add this to the Collection render displayed porpeties:
rnd:command(command=Z_download/style=link)
You ca also use and icon to represent the download (you can set that icon in the command)
I.E, rnd:command(command=Z_download_icon/style=icon)
This last options represents a problem with the km-only-read content like xml files generaded by xml forms, it can only be readed in the km-portal.
I hope this might help you.
Best regards,
Jorge M. -
How to set the size of a Font in Pixel?
Hi,
i know how to get the screen resolution of the current monitor and I know how to use Fonts (and I know how to read the API, but that didnt help).
Is there a way to set the size (or at least the height) of a Font in pixel rather then in points?
All I actually need is how many pixels the height of my String will be when I print it on the screen.
I use Swing and drawString(...) to draw my String (this information shouldnt matter, but just in case).
thanxHi,
search doc about FontMetrics, you'll find infos about how to get the font height... If I remember well, you need to get the Graphics of the component, then call getFontMetrics() or getFontMetrics(font) to obtain the metrics, then call getHeight() to know the font height... -
How to set the size of a class that extends JDialog
Hi,
I was trying to set the size of my dialog window to be 600 by 600, but couldn't change it. Here is my code:
public class alii extends JDialog {
/** Creates new form alii */
public alii(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
private void initComponents() {
Container contentPane = getContentPane();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
pack();
public static void main(String args[]) {
JFrame frame = new JFrame();
alii a = new alii(new javax.swing.JFrame(), true);
frame.setSize(600,500);
frame.setLocation(200,200);
frame.setVisible(true);}}
Please help me with this and explain to me what is the problem and what needs to be changed.
CheersHi,
The code you sent me doesn't work, and the code I posted wasn't a complete, but there is the complete one. You can see now what the code does.
* alii.java
* Created on 15 November 2003, 13:31
* @author Ali
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import java.applet.*;
import java.net.*;
public class sun extends JDialog {
int x[] = new int[4];
int y[] = new int[4];
int w[] = new int[4];
int h[] = new int[4];
int Y_ax = 310;
double DrawGraf[][] = new double[4][4];
String line[] = new String[9];
double Perc[] = new double[4];
double Sum=0;
GUICanvas can;
double graphvalue[] = new double [5];
/** Creates new form alii */
public sun(Frame parent, boolean modal) {
super(parent, modal);
initComponents();
//setVisible(true);
//setSize(600,500);
//setLocation(200,200);
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {
//Container contentPane = getContentPane();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
//contentPane.setSize(700,700);
//pack();
public void drawthegraph(String s)
/* try {
URL url = new URL(
"http://localhost:111/test/servlet/Compare?value="+s);
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
for (int c = 0; c<9; c++)
line[c] = in.readLine();
in.close();
}catch (Exception e){
e.printStackTrace();
graphvalue[0] = 200;
graphvalue[1] = 200;
graphvalue[2] = 100;
graphvalue[3] = 300;
graphvalue[4] = 20;
//graphvalue[4] = can.d2i(graphvalue[4]);
//System.out.println(line[8]);
Sum = graphvalue[0]+graphvalue[1]+graphvalue[2]+graphvalue[3];
Perc[0] = graphvalue[0]/Sum*200;
Perc[1] = graphvalue[1]/Sum*200;
Perc[2] = graphvalue[2]/Sum*200;
Perc[3] = graphvalue[3]/Sum*200;
System.out.println(Perc[0]);
DrawGraf[0][0] = 130;
DrawGraf[0][1] = Y_ax - Perc[0];
DrawGraf[0][2] = 60;
DrawGraf[0][3] = Perc[0];
DrawGraf[1][0] = DrawGraf[0][0]+60;
DrawGraf[1][1] = Y_ax - Perc[1];
DrawGraf[1][2] = 60;
DrawGraf[1][3] = Perc[1];
DrawGraf[2][0] = DrawGraf[1][0]+60;
DrawGraf[2][1] = Y_ax - Perc[2];
DrawGraf[2][2] = 60;
DrawGraf[2][3] = Perc[2];
DrawGraf[3][0] = DrawGraf[2][0]+60;
DrawGraf[3][1] = 310 - Perc[3];
DrawGraf[3][2] = 60;
DrawGraf[3][3] = Perc[3];
for(int d=0;d<4;d++)
x[d]=d2i(DrawGraf[d][0]);
y[d]=d2i(DrawGraf[d][1]);
w[d]=d2i(DrawGraf[d][2]);
h[d]=d2i(DrawGraf[d][3]);
repaint();
static int d2i(double d) {return (int) Math.round(d);}
public void paint (Graphics g)
g.setColor(Color.red);
for(int d=0;d<4;d++)
g.fill3DRect(x[d],y[d],w[d],h[d],true);
g.setColor(Color.blue);
g.drawLine(130,130,130,310);
g.drawLine(130,310,370,310);
g.setColor(Color.black);
g.drawString("WELCOME TO Ali",150,100);
g.drawString("Region: Lambeth",430,150);
g.drawString("Manger: ",430,170);
g.drawString("Location: ",430,190);
g.drawString("Number of Staff: "+graphvalue[4],430,210);
g.drawString("Week1",135,345);
g.drawString("Week2",195,345);
g.drawString("Week3",255,345);
g.drawString("Week4",315,345);
g.drawString(" "+"20 -",100,295);
g.drawString(" "+"40 -",100,255);
g.drawString(" "+"60 -",100,215);
g.drawString(" "+"80 -",100,175);
g.drawString("100 -",100,135);
g.setColor(Color.yellow);
g.drawLine(130,290,370,290);
g.drawLine(130,250,370,250);
g.drawLine(130,210,370,210);
g.drawLine(130,170,370,170);
g.drawLine(130,130,370,130);
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {
setVisible(false);
dispose();
* @param args the command line arguments
public static void main(String args[]) {
JFrame frame = new JFrame();
sun sn = new sun(frame, true);
frame.setSize(600,500);
frame.getContentPane().add(sn);
frame.setLocation(200,200);
frame.setVisible(true);
You were right that I am know to this, but getting there slowly and thanks for your help.
Cheers
Maybe you are looking for
-
How can I re-synchronize my photo collection on iPhoto FROM iPad TO iMac?
Due to a config problem I´ve lost all my pictures on my iMac. But I have them all - luckily - on my iPad. But how can I get the collection back onto my iMac? Synchronizing via iTunes doesn´t work.....
-
My computer will charge my iPhone, but won't recognize or sync it?
My iPhone 4S was working perfectly fine, but now my laptop suddenly won't recognize it! This all started after I bought a new charger for my laptop. My other one quit working, so I bought a replacement, and now I'm having this problem. I'm not sure i
-
How to Stop Cookies & Other Devices Hammering Me with Repeated Ads?
While researching this I see many people have many different issues with the various ads we are subjected to while surfing the web, but I could find nothing covering the current annoyance I am experiencing now. My apologies if this is old hat to ever
-
Recording tv into computer somehow....?
hello. This may be a rediculous, amateur question, but is it possible to record tv into a computer? Not necessarily live, but even a feed from a VCR while playing a pre-recorded tape. Basically, what I'm trying to do, is be able to watch a previously
-
AE appends my filename when setting up a render queue output filename via scripting
I wrote a script that imports quicktimes and creates comps from them and adds them to the render queue. I'm running into an issue where files with certain names get appended when adding them to the queue. I believe it has something to do with the "."