`
e_soft
  • 浏览: 48760 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

java write image from URL

    博客分类:
  • java
 
阅读更多
package com.mkyong.image;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

public class WriteImage
{
    public static void main( String[] args )
    {
    BufferedImage image = null;
        try {

            URL url = new URL("http://www.mkyong.com/image/mypic.jpg");
            image = ImageIO.read(url);

            ImageIO.write(image, "jpg",new File("C:\\out.jpg"));
            ImageIO.write(image, "gif",new File("C:\\out.gif"));
            ImageIO.write(image, "png",new File("C:\\out.png"));

        } catch (IOException e) {
        e.printStackTrace();
        }
        System.out.println("Done");
    }
}
分享到:
评论

相关推荐

    利用URL下载

    2. **Java**: Java中可以使用`java.net.URL`和`java.nio`包来实现下载: ```java import java.io.FileOutputStream; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels....

    java保存文件到数据库

    String sql = "SELECT image FROM images WHERE id = ?"; try (PreparedStatement pstmt = conn.prepareStatement(sql)) { pstmt.setInt(1, your_image_id); ResultSet rs = pstmt.executeQuery(); if (rs....

    url远程请求

    在Java中,`java.net.URL`类代表了一个URL对象,可以用于建立与指定URL的连接。 进行URL远程请求,通常有两种主要方式:`HttpURLConnection`和`HttpClient`。`HttpURLConnection`是Java标准库的一部分,而`...

    sqlserver2005 JDBC存取图片演示代码 亲测通过

    ResultSet rs = stmt.executeQuery("SELECT image FROM images WHERE id = 1"); if (rs.next()) { Blob blob = rs.getBlob("image"); FileOutputStream fos = new FileOutputStream("retrieved_image.jpg"); ...

    java连接Access2010读取图片二进制

    ResultSet rs = stmt.executeQuery("select * from image"); ``` `ResultSet`对象`rs`包含了查询结果,可以通过迭代遍历每一行数据。 在循环中,代码读取每条记录的`id`字段和`data`字段,`data`字段包含了二进制...

    java,Blob字段操作,将图片或者文件保存到数据库中.zip

    ResultSet rs = pstmt.executeQuery("SELECT image FROM images WHERE id = ?"); if (rs.next()) { Blob blob = rs.getBlob("image"); FileOutputStream fos = new FileOutputStream(new File("output_path")); ...

    java抓取网站数据

    - `lang=c&stype=1&postchannel=0000&fromType=1&line=&keywordtype=2&keyword=java` - `btnJobarea=%E9%80%89%E6%8B%A9%E5%9C%B0%E5%8C%BA&jobarea=0000&image=&btnFuntype=%E9%80%89%E6%8B%A9%2F%E4%BF%AE%E6%94%...

    JAVA操作Oracle blob类型

    ResultSet rs = stmt.executeQuery("SELECT image_data FROM images WHERE id = 1")) { if (rs.next()) { Blob blob = rs.getBlob("image_data"); File outputFile = new File("output.jpg"); ...

    在java web中显示存入mysql数据库的图片

    PreparedStatement ps = connection.prepareStatement("SELECT image FROM images WHERE id = ?"); ps.setInt(1, Integer.parseInt(id)); ResultSet rs = ps.executeQuery(); if (rs.next()) { byte[] imageData = ...

    Java存取数据库中的图片.rar_JAVA数据库_java 数据库_图片 java_图片数据库_数据库 图片

    ResultSet rs = stmt.executeQuery("SELECT image_data FROM images WHERE id = 1"); if (rs.next()) { byte[] imageData = rs.getBytes("image_data"); FileOutputStream fos = new FileOutputStream("output.jpg...

    DATABASE_image.rar_DATABASE_image_SQL SAVE IMAGE PUDN_SQL 图片_sql

    f.write(image_data) ``` 在实际应用中,可能还需要处理内存限制、错误处理和性能优化等问题。例如,对于大量图片的查询,可以考虑使用游标或分页查询来减少内存占用。 此外,文件`www.pudn.com.txt`可能是对PUDN...

    Java+MySql图片数据保存与读取的具体实例

    String sql = "SELECT data FROM images WHERE id=?"; PreparedStatement statement = conn.prepareStatement(sql); statement.setInt(1, Integer.parseInt(imageId)); ResultSet resultSet = statement....

    java实现数据库存储图片

    st.execute("CREATE TABLE [mytable] ([id] AUTOINCREMENT, [picname] VARCHAR(50), picimage BLOB);"); st.close(); con.close(); } catch (Exception e) { e.printStackTrace(); } } } ``` ##### 3.2 保存...

    Java访问数据库存取图片

    在Java编程中,访问数据库存取图片涉及到一系列的步骤和技术,主要依赖于Java Database Connectivity (JDBC) API来实现。本篇文章将详细讲解如何利用Java和JDBC与SQL Server 2000或其他数据库交互,以存储和检索图片...

    java Web 读取数据库存储图片

    PreparedStatement ps = conn.prepareStatement("SELECT image FROM Images WHERE id = ?")) { ps.setInt(1, imageId); ResultSet rs = ps.executeQuery(); if (rs.next()) { Blob blobImage = rs.getBlob(...

    Java邮件开发Fundamentals of the JavaMail API

    His latest book is titled Java Collections from Apress . Fundamentals of the JavaMail API Page 2 Presented by developerWorks, your source for great tutorials ibm.com/developerWorks Section 2....

    java版生成二维码

    ImageIO.write(image, "PNG", new File("qrcode.png")); ``` - Java QRCode示例代码: ```java QRCode qr = QRCode.from("http://example.com").withSize(300, 300); BufferedImage image = qr.getBitmap(); ...

    java读取slserverimage字段.doc

    String sql = "SELECT slserverimage FROM myTable WHERE someCondition=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, conditionValue); ``` 4. **执行查询并获取结果**: 执行...

    通过java操作excel表格的工具类库jxl

     程序代码:sql = "select * from tablename";  rs = stmt.executeQuery(sql);  //新建Excel文件  String filePath=request.getRealPath("aaa.xls");  File myFilePath=new File(filePath);  if(!myFilePath....

    Android获取SD卡中选中图片的路径(URL)

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ``` 然后,我们可以使用Intent来启动系统的图片选择器,如下所示: ```java Intent intent = new Intent(Intent.ACTION_PICK); ...

Global site tag (gtag.js) - Google Analytics