簡體   English   中英

ImageIO 類型中的方法 read(File) 不適用於參數 (String)

[英]The method read(File) in the type ImageIO is not applicable for the arguments (String)

因此,當我將 urlImage 替換為實際圖像路徑時,例如“BufferedImage image = ImageIO.read("F:/Java/data/photo.jpg") 在代碼的第一行它返回以下錯誤“方法讀取( ImageIO 類型中的 File)不適用於參數(String)”我嘗試了不同的方法,但沒有奏效,這聽起來很明顯,我只是無法將 String 類型轉換為 File。

BufferedImage image = ImageIO.read(urlImage);
int x;
int y;
int c = image.getRGB(x,y);
int  red = (c & 0x00ff0000) >> 16;
int  green = (c & 0x0000ff00) >> 8;
int  blue = c & 0x000000ff;
// and the Java Color is ...
Color color = new Color(red,green,blue);

ImageIO 類型中的方法 read(File) 不適用於參數 (String)

是一個非常明顯的錯誤。 您正在傳遞一個字符串,您需要傳遞一個文件。 做就是了:

BufferedImage image = ImageIO.read(new File(urlImage));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM