由买买提看人间百态

topics

全部话题 - 话题: graphics2d
1 (共1页)
a*****p
发帖数: 1285
1
来自主题: Java版 - java graphics2d 画图请教
public class MouseComponent extends JComponent {



public MouseComponent() {

shapes = new ArrayList();
lines = new ArrayList();
bounds = new ArrayList();
current = null;
startpoint = null;
endpoint = null;

isSelected = false;
eraserSelected = false;
cursorPointer = false;
isLine = false;
clear = false;
filled = false;

shapeIndex =... 阅读全帖
a*****p
发帖数: 1285
2
来自主题: Java版 - java graphics2d 画图请教
java 里面建了arraylist来做画图程序,其他function都就绪了,现在color上
碰到点问题。因为用得arraylist,
每次graphics2d.setcolor得时候,一repaint,画图板上所有得图颜色都变了,怎么让
单个得图颜色变啊??变了之后还能
保存,每个图形自己本身有color属性么??
a*****p
发帖数: 1285
3
来自主题: Java版 - java graphics2d 画图请教
可能说得不明白,补充一下。
我用graphics2d画图,一个component上面好几个shape,然后我换color,用g2.
setcolor,问题是一换color所有得图
颜色都变了,而不是当前选中得图,这种情况一般怎么只变当前图得颜色呢??再画另
外一个图得时候,其他得图不受影
响??就是存在不同颜色??
y***e
发帖数: 39
4
/////////JDK1.2 case
static class MyButton extends JButton
implements Printable {
public MyButton() {
super("MyButton");
}
public int print(Graphics g, PageFormat pf, int pi)
throws PrinterException {
System.out.println("mybutton print");
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) g;
g2.translate(pf.getImageableX(), pf.getImageableY());
Font f = new Font("Monospaced",Font
F****n
发帖数: 3271
5
This is because each time getGraphics() is invoked, it call createGraphics
which creates a new Graphics2D object, so the Graphics you used to draw Line
is not the Graphics you have set Color. You should Use:
Graphics2D g2D = bImage.createGraphics();
g2D.setColor(Color.red);
g2D.draw(...);

g*****g
发帖数: 34805
6
Like this
BufferedImage bufimg =ImageIO.read(file);
BufferedImage bufimg2 = new BufferedImage(width, height,bufimg.getType());
Graphics2D g2d = (Graphics2D) bufimg2.getGraphics();
g2d.scale((double) width /bufimg.getWidth(), (double) height /bufimg.
getHeight());
g2d.drawImage(bufimg,0,0,null);
Image img = bufimg2;
w******p
发帖数: 166
7
来自主题: Java版 - Java 里划直线加粗的问题
public void paint (Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(6.0f);
g2.drawLine(...)
}
d*r
发帖数: 238
8
当我有一些jpg文件,Dimension 是800x600,我要用1024x768来显示的时候,有些图像的
边缘就出现锯齿。
我不知道用什么方法能去掉这些锯齿。
我用了Graphics2D和AffineTransform的scale() function.
如果用C#的PictureBox就没有任何锯齿出现。
F****n
发帖数: 3271
9
直接用Graphics2D的Transform会把所有细节放大, 当然会有剧齿,
你自己CREATE 一个SCALED的IMAGE不就行了.

B******N
发帖数: 445
10
you are wrong, it's better not create scale instance, which will be very slow.
the correct answer:
BufferedImage targetImage = new BufferedImage(targetWidth,
targetHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = targetImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(srcImage, 0, 0, targetWidth, targetHeight, null);
g2d.dispose();
you will get much fa
T*****e
发帖数: 361
11
我重新查了一下相关的类,好象可以这么做:
1. Create a BufferedImage object.
2. Call BufferedImage.createGraphics2D to get a Graphics2D object that can be
used for drawing shapes (points, lines, polygons, etc) on the BufferedImage
object.
3. Create an ImageWriter object for writing the BufferedImage object into an
image file.
如果这条路径能够行得通,那么我在转换到Java时就不用担心创建图像、画图、存文件的
问题了。
谢谢你提供的信息。
c*****t
发帖数: 1879
12
Java3D maybe dead. Sun layed-off/reassigned people in the Java3D
team. They now favors OpenGL again...
Java3D is object-oriented, unlike OpenGL. It makes doing things
such as animation, mouse etc significantly easier. However, OpenGL
stuff seemed to be more popular, easier to implement etc.
In short, don't waste time on Java3D.
As for Java2D, usually knowint Graphics/Graphics2D is good enough.
You probably don't even have to worry about transformations etc.
Unless you do image processing (wh
l**********r
发帖数: 24
13
我用
Graphics2D
draw(new Line2D.Double()
画的线,只要不是水平和垂直的
就都有小小的锯齿
怎么办? 给老板交上去有点丢人,虽然他也不懂
c*****t
发帖数: 1879
14
来自主题: Java版 - 用java画直线的问题
Learn to use BufferedImage and Graphics2D. To save the image to
a file, just use javax.imageio.ImageIO.write (bufferedImage, "png",
new File ("output.png")).
c*****t
发帖数: 1879
15
来自主题: Java版 - Image processing library
Basic Java Graphics manipulations have all the features you need.
Graphics2D has some even more advanced features. JAI has even
more features that you will ever need, but most IMO are pretty
slow since it was aimed to be fairly generic.
I think that in JRE 1.4.2, the basic imageio includes PNG (very simple),
GIF and JPG (not including JPEG2000). One can download a separate
jar from Sun for additional formats such as TIFF, PNG (out), PNM,
BMP etc. Later version of JRE should have them (and inc
m******y
发帖数: 102
16
来自主题: Java版 - Java 里划直线加粗的问题
用Graphics2D
h******a
发帖数: 46
17
www.lowagie.com/iText/ , you can save your Graphics2D to pdf
j******o
发帖数: 82
18
Yes...just do the following
BufferedImage im = new BufferedImage(...); // desired width, height, type
Graphics2D g2 = im.createGraphics();
drawStuff(g2);
ImageIO.write(im, ....); // to PNG, JPEG, etc.
g****j
发帖数: 24
19
来自主题: Java版 - 请教document
textlayout还是很慢,或者我的代码有问题?才10万长的序列。
public void initValues(Graphics2D g)
{
HashMap dna2color=new HashMap();
dna2color.put('A',Color.green);
dna2color.put('T',Color.red);
dna2color.put('C',Color.blue);
dna2color.put('G',Color.orange);

StringBuffer s=new StringBuffer();
for(int i=0;i<10000;i++) s.append("ATCGATCGATAT");

AttributedString as=new AttributedString(s.toString());
System.out.println(3);
for(int i=0;i
F****n
发帖数: 3271
20
来自主题: Java版 - 请教document
你这个问题主要是每次都要重复create TextLayout, 10万个字母要10万次。其实就4个
TextLayout重复用就可以了.
public void initValues(Graphics2D g)
{
HashMap dna2tl =new HashMap();
TextLayout atl = ...//create a text layout for A
dna2tl.put('A',atl);
...
}
更快的方法可以直接用4个Image.
HashMap dna2img
h**********c
发帖数: 4120
21
来自主题: Java版 - java graphics2d 画图请教
opengl 是这么干的:
push color1
change to color2
pop color1
大概就这个意思,g2.setcolor的时候先getcolor找地保存一下,
g2 画完了,再set color。
你说的意思还是比较含糊,最好把原代码帖上来,
我以前用java canvas画过比较复杂的东西,时间长了,后改opengl了。
a*****p
发帖数: 1285
22
来自主题: Java版 - java graphics2d 画图请教
有点长,这个现在是拖拽得时候,画好多图,而不是更新那一个图。
a*****p
发帖数: 1285
23
来自主题: Java版 - java graphics2d 画图请教
贴了代码,能帮看看么??/
g*****g
发帖数: 34805
24
来自主题: Java版 - java graphics2d 画图请教
All you need is a hashmap instance variable from shape to color.
b***i
发帖数: 3043
25
来自主题: Java版 - Concurrent Exception in Swing
我在main里面调用一个自己写的类OldSplashScreen的函数,起了一个线程,执行
splash()(其中145行splashWindow = new SplashWindow(this,fImage);)
178在一个private class SplashWindow extends JFrame的类中,是构造函数
private class SplashWindow extends JFrame {
BufferedImage base=null;
public Graphics2D gS=null;
private static final long serialVersionUID = 1L;
BufferedImage bf=null;
BufferedImage canvas=null;
178: SplashWindow(Frame aParent, Image aImage) {
构造函数怎么会出错?我估计是非Swing EDT里面调用Swing类Frame子类的构造函数了。
... 阅读全帖
b***i
发帖数: 3043
26
一个控制定自定义的SplashWindow的类,定了一个timer.schedule(task, 0, 100);其
中 task=new TimerTask(){.....run(){splashWindow.repaint();},
关闭窗口的时候timer.cancel();然后通过invokeLater调用splashWindow.dispose();
splashWindow=null等,希望gc来析构变量。
splashWindow是属于 private class SplashWindow extends JFrame{
其中构造函数初始化了 canvas= new BufferedImage(....);
}
还有public void paint(Graphics graphics){
if (fImage != null && running) {
Graphics2D g=canvas.createGraphics();
g.drawImage(base, 0, 0, this);
g.drawImage(... 阅读全帖
1 (共1页)