import java.awt.*;
import javax.swing.*;public class c4_01_02 extends JFrame{
public static void main(String args[]){
c4_01_02 frame=new c4_01_02();
}
Image image1;
public c4_01_02(){
super("c4_01_02");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.white);
setSize(600,500);
setVisible(true);
}
public void paint(Graphics g){
int x,y;
image1=Toolkit.getDefaultToolkit().getImage("photo3.jpg");
x=10;y=40;
g.drawImage(image1,x,y,x+240,y+180,0,0,240,180,this);
x=10;y=240;
g.drawImage(image1,x,y,x+240,y+180,0,180,240,0,this);
x=300;y=40;
g.drawImage(image1,x,y,x+240,y+180,0,180,240,0,this);
x=300;y=240;
g.drawImage(image1,x,y,x+240,y+90,60,0,240,90,this);
}
}
请快些加分...冲级中..
import javax.swing.*;public class c4_01_02 extends JFrame{
public static void main(String args[]){
c4_01_02 frame=new c4_01_02();
}
Image image1;
public c4_01_02(){
super("c4_01_02");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.white);
setSize(600,500);
setVisible(true);
}
public void paint(Graphics g){
int x,y;
image1=Toolkit.getDefaultToolkit().getImage("photo3.jpg");
x=10;y=40;
g.drawImage(image1,x,y,x+240,y+180,0,0,240,180,this);
x=10;y=240;
g.drawImage(image1,x,y,x+240,y+180,0,180,240,0,this);
x=300;y=40;
g.drawImage(image1,x,y,x+240,y+180,0,180,240,0,this);
x=300;y=240;
g.drawImage(image1,x,y,x+240,y+90,60,0,240,90,this);
}
}
请快些加分...冲级中..
解决方案 »
- 急!急!!如何验证xml文件的有效性?
- 高分求助,项目发布后无法显示.
- 求三重for循环的总共循环次数,代码如下:
- 请问System.out.wtite(87)为何无法输出数据呢?
- 学习ajax.....遇到问题,在线等......
- 100分问swing的JButton的一个问题,高手进..
- 国际化的问题
- 怎么清除JTable中的全部内容??
- 欢迎大家讨论一下程序员的发展轨迹
- help!
- java连接ORACLE数据问题
- 小妹郁闷死了,各位大侠救命啊!关于SOCKET和多线程的问题。error J0082: Class 'Server' doesn't have a constructor that matches 'Ser
给我详细点代码啊~,弄个小例子出来
我也要做这个
可楼上.drawImage(image1,x,y,x+240,y+180,0,180,240,0,this);这个各参数值是什么意思啊
我看了一下API里面的可是还没研究出是什么意思比如我想转90,180,270,360等等有源码吗
* @(#)Transform.java 1.2 98/07/31
*/
import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;/*
* This applet renders a shape, selected by the user, with a paint,stroke, and rendering method,
* also selected by the user.
*/public class Transform extends JApplet implements ItemListener,
ActionListener {
JLabel primLabel, lineLabel, paintLabel, transLabel, strokeLabel;
TransPanel display;
static JComboBox primitive, line, paint, trans, stroke;
JButton redraw;
public static boolean no2D = false; public void init() {
GridBagLayout layOut = new GridBagLayout();
getContentPane().setLayout(layOut);
GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0;
c.fill = GridBagConstraints.BOTH;
primLabel = new JLabel();
primLabel.setText("Primitive");
Font newFont = getFont().deriveFont(1);
primLabel.setFont(newFont);
primLabel.setHorizontalAlignment(JLabel.CENTER);
layOut.setConstraints(primLabel, c);
getContentPane().add(primLabel); lineLabel = new JLabel();
lineLabel.setText("Lines");
lineLabel.setFont(newFont);
lineLabel.setHorizontalAlignment(JLabel.CENTER);
layOut.setConstraints(lineLabel, c);
getContentPane().add(lineLabel); paintLabel = new JLabel();
paintLabel.setText("Paints");
paintLabel.setFont(newFont);
paintLabel.setHorizontalAlignment(JLabel.CENTER);
layOut.setConstraints(paintLabel, c);
getContentPane().add(paintLabel); c.gridwidth = GridBagConstraints.RELATIVE;
transLabel = new JLabel();
transLabel.setText("Transforms");
transLabel.setFont(newFont);
transLabel.setHorizontalAlignment(JLabel.CENTER);
layOut.setConstraints(transLabel, c);
getContentPane().add(transLabel); c.gridwidth = GridBagConstraints.REMAINDER;
strokeLabel = new JLabel();
strokeLabel.setText("Rendering");
strokeLabel.setFont(newFont);
strokeLabel.setHorizontalAlignment(JLabel.CENTER);
layOut.setConstraints(strokeLabel, c);
getContentPane().add(strokeLabel); GridBagConstraints ls = new GridBagConstraints();
ls.weightx = 1.0;
ls.fill = GridBagConstraints.BOTH;
primitive = new JComboBox( new Object []{
"rectangle",
"ellipse",
"text"});
primitive.addItemListener(this);
newFont = newFont.deriveFont(0, 14.0f);
primitive.setFont(newFont);
layOut.setConstraints(primitive, ls);
getContentPane().add(primitive); line = new JComboBox( new Object []{
"thin",
"thick",
"dashed"});
line.addItemListener(this);
line.setFont(newFont);
layOut.setConstraints(line, ls);
getContentPane().add(line); paint = new JComboBox( new Object[]{
"solid",
"gradient",
"polka"});
paint.addItemListener(this);
paint.setFont(newFont);
layOut.setConstraints(paint, ls);
getContentPane().add(paint); ls.gridwidth = GridBagConstraints.RELATIVE; trans = new JComboBox( new Object[]{
"Identity",
"rotate",
"scale",
"shear"});
trans.addItemListener(this);
trans.setFont(newFont);
layOut.setConstraints(trans, ls);
getContentPane().add(trans); ls.gridwidth = GridBagConstraints.REMAINDER;
stroke = new JComboBox( new Object[]{
"Stroke",
"Fill",
"Stroke & Fill"});
stroke.addItemListener(this);
stroke.setFont(newFont);
layOut.setConstraints(stroke, ls);
getContentPane().add(stroke); GridBagConstraints button = new GridBagConstraints();
button.gridwidth = GridBagConstraints.REMAINDER;
redraw = new JButton("Redraw");
redraw.addActionListener(this);
redraw.setFont(newFont);
layOut.setConstraints(redraw, button);
getContentPane().add(redraw); GridBagConstraints tP = new GridBagConstraints();
tP.fill = GridBagConstraints.BOTH;
tP.weightx = 1.0;
tP.weighty = 1.0;
tP.gridwidth = GridBagConstraints.REMAINDER;
display = new TransPanel();
layOut.setConstraints(display, tP);
display.setBackground(Color.white);
getContentPane().add(display); validate(); } public void itemStateChanged(ItemEvent e){} public void actionPerformed(ActionEvent e) {
display.setTrans(trans.getSelectedIndex());
display.renderShape();
}
public static void main( String[] argv ) {
if ( argv.length > 0 && argv[0].equals( "-no2d" ) ) {
Transform.no2D = true;
}
JFrame frame = new JFrame( "Transform" );
frame.addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent e ){
System.exit( 0 );
}
}); JApplet applet = new Transform();
frame.getContentPane().add( BorderLayout.CENTER, applet );
applet.init();
frame.setSize( 550, 400 );
frame.show();
}}class TransPanel extends JPanel {
AffineTransform at = new AffineTransform();
int w, h;
Shape shapes[] = new Shape[3];
BufferedImage bi;
boolean firstTime = true; public TransPanel(){
setBackground(Color.white);
shapes[0] = new Rectangle(0, 0, 100, 100);
shapes[1] = new Ellipse2D.Double(0.0, 0.0, 100.0, 100.0);
TextLayout textTl = new TextLayout("Text", new Font("Helvetica", 1, 96), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(0, (float)textTl.getBounds().getHeight());
shapes[2] = textTl.getOutline(textAt);
} public void setTrans(int transIndex) {
// Sets the AffineTransform.
switch ( transIndex ) {
case 0 : at.setToIdentity();
at.translate(w/2, h/2); break;
case 1 : at.rotate(Math.toRadians(45)); break;
case 2 : at.scale(0.5, 0.5); break;
case 3 : at.shear(0.5, 0.0); break;
}
}
public void renderShape() {
repaint();
} public void paintComponent(Graphics g) {
super.paintComponent(g);
if ( !Transform.no2D ) {
Graphics2D g2 = (Graphics2D) g;
Dimension d = getSize();
w = d.width;
h = d.height;
// Prints out the intructions.
String instruct = "Pick a primitive, line style, paint, transform,";
TextLayout thisTl = new TextLayout(instruct, new Font("Helvetica", 0, 10), g2.getFontRenderContext());
float width = (float)thisTl.getBounds().getWidth();
float height = (float)thisTl.getBounds().getHeight();
thisTl.draw(g2, w/2-width/2, 15); instruct = "and rendering method and click the Redraw button.";
thisTl = new TextLayout(instruct, new Font("Helvetica", 0, 10), g2.getFontRenderContext());
width = (float)thisTl.getBounds().getWidth();
thisTl.draw(g2, w/2-width/2, height + 17); // Initialize the transform.
if (firstTime) {
at.setToIdentity();
at.translate(w/2, h/2);
firstTime = false;
} // Sets the Stroke.
Stroke oldStroke = g2.getStroke(); switch ( Transform.line.getSelectedIndex() ) {
case 0 : g2.setStroke(new BasicStroke(3.0f)); break;
case 1 : g2.setStroke(new BasicStroke(8.0f)); break;
case 2 : float dash[] = {10.0f};
g2.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
break;
} // Sets the Paint.
Paint oldPaint = g2.getPaint(); switch ( Transform.paint.getSelectedIndex() ) {
case 0 : g2.setPaint(Color.blue);break;
case 1 : g2.setPaint(new GradientPaint(0, 0, Color.lightGray, w-250, h, Color.blue, false));
break;
case 2 : BufferedImage buffi = new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
Graphics2D buffig = buffi.createGraphics();
buffig.setColor(Color.blue);
buffig.fillRect(0, 0, 15, 15);
buffig.setColor(Color.lightGray);
buffig.translate((15/2)-(5/2), (15/2)-(5/2));
buffig.fillOval(0, 0, 7, 7);
Rectangle r = new Rectangle(0,0,25,25);
g2.setPaint(new TexturePaint(buffi, r));
break;
} // Sets the Shape.
Shape shape = shapes[Transform.primitive.getSelectedIndex()];
Rectangle r = shape.getBounds(); // Sets the selected Shape to the center of the Canvas.
AffineTransform saveXform = g2.getTransform();
AffineTransform toCenterAt = new AffineTransform();
toCenterAt.concatenate(at);
toCenterAt.translate(-(r.width/2), -(r.height/2)); g2.transform(toCenterAt); // Sets the rendering method.
switch ( Transform.stroke.getSelectedIndex() ) {
case 0 : g2.draw(shape); break;
case 1 : g2.fill(shape); break;
case 2 : Graphics2D tempg2 = g2;
g2.fill(shape);
g2.setColor(Color.darkGray);
g2.draw(shape);
g2.setPaint(tempg2.getPaint()); break;
} g2.setStroke(oldStroke);
g2.setPaint(oldPaint);
g2.setTransform(saveXform);
}
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class c4_01_03 extends JFrame
{
public static void main(String args[])
{
c4_01_03 frame=new c4_01_03();
}
Image image1;
public c4_01_03(){
super ("c4_01_03");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.white);
setSize(500,400);
setVisible(true);
}
public void paint(Graphics g){
int x,y;
Graphics2D g2;
g2=(Graphics2D) g;
image1=Toolkit.getDefaultToolkit().getImage("photo3.jpg");
g2.rotate(Math.toRadians(10));//旋转10度
g2.drawImage(image1,200,20,240,180,this);
g2.rotate(Math.toRadians(10));//旋转10度
g2.drawImage(image1,200,20,240,180,this);
g2.rotate(Math.toRadians(10));//旋度10度
g2.drawImage(image1,200,20,240,180,this);
}
}
只怪我没说清
我说这图片不仅仅是显示的时候是倒转了90度
而是本身生成图片是真正的倒转了90度
并且你给的drawImage这参数值我也没搞懂
你再帮帮我 一定结贴
这需要修改bmp本身内部的点信息。
具体算法可以看看图像处理的书,书店里还是比较多的。
我看了 可是也不是对图片本身编辑倒转
如果你多给点提示啊我真是太感谢了 !!!!!!!!!!!!
Image imageOriginal = imgIcon.getImage();
int widthOriginal = imageOriginal.getWidth(null);
int heightOriginal = imageOriginal.getHeight(null);
System.out.println("width=" + widthOriginal + ",heightOriginal=" + heightOriginal);
BufferedImage buffImg = new BufferedImage(widthOriginal, heightOriginal,
BufferedImage.TYPE_INT_RGB);
Graphics g = buffImg.createGraphics();
int num = Integer.parseInt(rotateNum);
//旋转90度
if (flag.equals("2")) { if (num % 4 == 1) {
g.drawImage(imageOriginal, 0, 0, widthOriginal, heightOriginal, 0,
heightOriginal, widthOriginal, 0, null);
}
else if (num % 4 == 0) {
g.drawImage(imageOriginal, 0, 0, widthOriginal, heightOriginal, 0,
0, widthOriginal, heightOriginal, null);
}
} //旋转180度
else if (flag.equals("3")){
if (num % 2 == 1) {
g.drawImage(imageOriginal, 0, 0, widthOriginal, heightOriginal, 0,
heightOriginal, widthOriginal, 0, null);
}
else if (num % 2 == 0) {
g.drawImage(imageOriginal, 0, 0, widthOriginal, heightOriginal, 0,
0, widthOriginal, heightOriginal, null);
}
}
g.dispose(); FileOutputStream fos = new FileOutputStream(imageurl);
BufferedOutputStream bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(buffImg);
bos.flush();
bos.close();