全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1532
推到 Plurk!
推到 Facebook!

Java image problem???

尚未結案
Zonda
一般會員


發表:23
回覆:40
積分:12
註冊:2003-10-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-12-20 02:42:44 IP:202.175.xxx.xxx 未訂閱
請問一下,如何用FileInputStream以及bytearray去讀取一章圖片如png,jpeg...??? Is there any example>???
neoart
版主


發表:22
回覆:582
積分:425
註冊:2003-05-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-12-22 10:07:08 IP:61.64.xxx.xxx 未訂閱
to read file output to byte array,please refer to following code:
        java.io.File srcFile=new java.io.File(filePath);
        java.io.BufferedInputStream bis=new
           java.io.BufferedInputStream(new java.io.FileInputStream(srcFile));
        byte byte2output[]=new byte[bis.available()];
        bis.read(byte2output);
         bis.close();
for jpg or gif,use ---- javax.swing.ImageIcon icon=new ImgeIcon("your image file path"); --- to load gif/jpg file directly. for png file, please use: java.awt.Tookit.getImage(....) or createImage(....) please take a look at flowing sample,seems helpful to your need: http://developers.sun.com/techtopics/mobility/midp/ttips/animatedimages/ 發表人 - neoart 於 2003/12/22 21:13:59
Zonda
一般會員


發表:23
回覆:40
積分:12
註冊:2003-10-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-12-23 01:25:10 IP:202.175.xxx.xxx 未訂閱
Thanks!!! it is really helpful. By the way, i have some problem about J2me, like i don't know why the function paint(graphic g) cannot perform the image on the screen of the MIDP emulator??? I want to know the problem {Note: The constructor is okay!!!} class ShowImageCanvas extends Canvas { private Image img = null; private StringItem item = null; public ShowImageCanvas(Image img, StringItem item) { this.img = img; this.item = item; Graphics g = null; } ------> protected void paint(Graphics g) { item.setText("Show Picture!!!"); if (img != null) { g.drawImage(img, 5, 5, Graphics.TOP| Graphics.LEFT); } else { item.setText("Image cannot be opened ERROR!!!"); } } }
neoart
版主


發表:22
回覆:582
積分:425
註冊:2003-05-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-12-23 09:52:43 IP:61.64.xxx.xxx 未訂閱
引言: Thanks!!! it is really helpful. By the way, i have some problem about J2me, like i don't know why the function paint(graphic g) cannot perform the image on the screen of the MIDP emulator??? I want to know the problem {Note: The constructor is okay!!!} class ShowImageCanvas extends Canvas { private Image img = null; private StringItem item = null; public ShowImageCanvas(Image img, StringItem item) { this.img = img; this.item = item; Graphics g = null; } ------> protected void paint(Graphics g) { item.setText("Show Picture!!!"); if (img != null) { g.drawImage(img, 5, 5, Graphics.TOP| Graphics.LEFT); } else { item.setText("Image cannot be opened ERROR!!!"); } } }
Dear Zonda: Base on my poor knowledge, I am not expert in J2ME/MIDP(majority of my projects are J2EE application or Swing client design), but I think the following web site should be more helpful to your development: The J2ME board of jsptw site: http://www.jsptw.com/jute/post/page?bid=26&sty=1&age=0 and a very friendly personal website of j2me developer: http://www.j2mer.idv.tw/modules/mylinks/viewcat.php?cid=3 you may post your questions and get more proper answer there. By the way,for your current "drawImage" question,below are a sample code for MIDP http://www.j2mer.idv.tw/modules/news/article.php?storyid=187 or http://www2.tw.ibm.com/developerWorks/tutorial/SelectTutorial.do?tutorialId=133 發表人 - neoart 於 2003/12/23 10:02:59
Zonda
一般會員


發表:23
回覆:40
積分:12
註冊:2003-10-30

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-12-23 23:54:17 IP:202.175.xxx.xxx 未訂閱
Thanks!!!
系統時間:2024-05-09 21:37:09
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!