JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 toolkit.createImage 看不到存檔
bearhcc





發文: 10
積分: 0
於 2018-11-23 05:23 user profilesend a private message to usersend email to bearhccreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問各位先進大家好?

我使用的是 jdk1.8.0_181 , jre1.8.0_181
系統是 Windows 7 64bit
已下這段 code 無法在 D:/ 看到存檔 P6.JPG
請幫忙指導!! 謝謝大家!

int w = 100;
int h = 100;
int pix[] = new int[w * h];
int index = 0;
for (int y = 0; y < h; y++) {
int red = (y * 255) / (h - 1);
for (int x = 0; x < w; x++) {
int blue = (x * 255) / (w - 1);
pix[index++] = (255 << 24) | (red << 16) | blue;
}
}
Image img = toolkit.createImage(new MemoryImageSource(w, h, pix, 0, w));
toolkit.createImage("d:\\p6.JPG");
Graphics gg1=getGraphics();
gg1.drawImage(img, 350,50,this);


reply to postreply to post
作者 Re:toolkit.createImage 看不到存檔 [Re:bearhcc]
ynchang





發文: 151
積分: 0
於 2018-11-23 07:06 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你是這下面這個API?
https://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html#createImage-java.lang.String-

這個method是去讀檔不是寫檔的


reply to postreply to post
作者 Re:toolkit.createImage 看不到存檔 [Re:ynchang]
bearhcc





發文: 10
積分: 0
於 2018-11-23 07:23 user profilesend a private message to usersend email to bearhccreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ynchhang 大哥您好!
感謝您的指正!

寫檔的部分, 能請您在指教小弟嗎?
謝謝您!


reply to postreply to post
作者 Re:toolkit.createImage 看不到存檔 [Re:ynchang]
bearhcc





發文: 10
積分: 0
於 2018-11-23 07:53 user profilesend a private message to usersend email to bearhccreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ynchhang 大哥您好!
謝謝您!

我用以下的方法 : 解了這個問題

BufferedImage bi = new BufferedImage(300, 168, BufferedImage.TYPE_3BYTE_BGR);

Graphics g = bi.getGraphics();
try {
g.drawImage(img2, 0, 0, null);

ImageIO.write(bi,"jpg",new File("d:/p6.jpg"));
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}

非常感謝!


reply to postreply to post
» JWorld@TW »  Java 新手區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8