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");
}
}
分享到:
相关推荐
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....
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....
在Java中,`java.net.URL`类代表了一个URL对象,可以用于建立与指定URL的连接。 进行URL远程请求,通常有两种主要方式:`HttpURLConnection`和`HttpClient`。`HttpURLConnection`是Java标准库的一部分,而`...
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"); ...
ResultSet rs = stmt.executeQuery("select * from image"); ``` `ResultSet`对象`rs`包含了查询结果,可以通过迭代遍历每一行数据。 在循环中,代码读取每条记录的`id`字段和`data`字段,`data`字段包含了二进制...
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")); ...
- `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%...
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"); ...
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 = ...
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...
f.write(image_data) ``` 在实际应用中,可能还需要处理内存限制、错误处理和性能优化等问题。例如,对于大量图片的查询,可以考虑使用游标或分页查询来减少内存占用。 此外,文件`www.pudn.com.txt`可能是对PUDN...
String sql = "SELECT data FROM images WHERE id=?"; PreparedStatement statement = conn.prepareStatement(sql); statement.setInt(1, Integer.parseInt(imageId)); ResultSet resultSet = statement....
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 Database Connectivity (JDBC) API来实现。本篇文章将详细讲解如何利用Java和JDBC与SQL Server 2000或其他数据库交互,以存储和检索图片...
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(...
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....
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(); ...
String sql = "SELECT slserverimage FROM myTable WHERE someCondition=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, conditionValue); ``` 4. **执行查询并获取结果**: 执行...
程序代码:sql = "select * from tablename"; rs = stmt.executeQuery(sql); //新建Excel文件 String filePath=request.getRealPath("aaa.xls"); File myFilePath=new File(filePath); if(!myFilePath....
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ``` 然后,我们可以使用Intent来启动系统的图片选择器,如下所示: ```java Intent intent = new Intent(Intent.ACTION_PICK); ...