本文目錄一覽:
- 1、一本JAVA教材,作者和出版社都忘記了,封面有一隻蝴蝶的
- 2、JAVA問題:管理員在後台 發表文章,裏面有圖片,發表之後,。。
- 3、java如何獲取.mp3格式文件內置歌曲封面
- 4、用java如何編輯圖片的主題,標題,作者,創建日期等信息?
一本JAVA教材,作者和出版社都忘記了,封面有一隻蝴蝶的
一般的O’Reilly的書是有名的使用動物和昆蟲作為封面的,我做了一些研究,暫時O’Reilly的書籍只有一本叫做 JavaScript: The Good Parts Unearthing the Excellence in JavaScript 的是有一隻很大蝴蝶作為封面的,封面圖:
JAVA問題:管理員在後台 發表文章,裏面有圖片,發表之後,。。
你是只要顯示題目和其中一張圖片嗎???
你需要說清楚的是:你的圖片在數據庫中是如何存儲的,或者新聞表的結構是如何的?
假設:圖片上傳到服務器,在新聞內容中直接包含img scr=”tt.jpg”這樣的標籤,圖片的路徑在數據庫沒有單獨處理的話,你只有讀出新聞內容後,查找其中的第一個 img 標籤,然後顯示圖片。
java如何獲取.mp3格式文件內置歌曲封面
封面就是圖片,用java的類抓取圖片即可
package tool;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
public class ImageViewer extends JFrame
{
private static final long serialVersionUID = 1L;
private static final String DOWNLOADPATH = “download/”;
JTextPane textPane = new JTextPane ();
LinkedListString initString = new LinkedListString ();
LinkedListString initStyles = new LinkedListString ();
LinkedListString path = new LinkedListString ();
public ImageViewer ()
{
setTitle (“圖片預覽下載器 v1.0”);
setLayout (new BorderLayout ());
setSize (500, 300);
setLocationRelativeTo (null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
private void addComponents ()
{
final JTextField urltField = new JTextField ();
JPanel right = new JPanel (new FlowLayout (FlowLayout.RIGHT, 0, 0));
final JButton go = new JButton (“GO”);
textPane.setEditable (false);
JScrollPane content = new JScrollPane (textPane);
go.addActionListener (new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
String url = urltField.getText ().trim ();
resolveHTML (url, “utf8”, “(?i)\\img[^\\]*src[\\=\\s\’\”]+([^\\\’\”]+)[\’\”]?[^\\]*\\”);
}
});
JPanel up = new JPanel (new BorderLayout ());
up.add (urltField, BorderLayout.CENTER);
right.add (go);
JButton download = new JButton (“DOWNLOAD”);
download.addActionListener (new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
downloadImages ();
}
});
right.add (download);
up.add (right, BorderLayout.EAST);
add (up, BorderLayout.NORTH);
add (content, BorderLayout.CENTER);
}
private void downloadImages ()
{
File fp = new File (DOWNLOADPATH);
if (!fp.exists ())
{
fp.mkdir ();
}
for ( int i = 0; i path.size (); i++ )
{
try
{
String p = path.get (i);
URL url = new URL (p);
HttpURLConnection huc = (HttpURLConnection) url.openConnection ();
huc.setRequestMethod (“GET”);
huc.setConnectTimeout (5 * 1000);
InputStream is = huc.getInputStream ();
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
byte[] buffer = new byte[1024];
int len = -1;
while (( len = is.read (buffer) ) != -1)
{
baos.write (buffer, 0, len);
}
baos.flush ();
baos.close ();
is.close ();
huc.disconnect ();
byte[] data = baos.toByteArray ();
String name = p.substring (p.lastIndexOf (“/”) + 1, p.length ());
name = name.contains (“.”) ? name : name + “.jpg”;
FileOutputStream fos = new FileOutputStream (new File (DOWNLOADPATH + name));
fos.write (data);
fos.flush ();
fos.close ();
}
catch (Exception e)
{
continue;
}
}
}
private void loadImages ( ListString initString, ListString initStyles, ListString url )
{
try
{
StyledDocument doc = textPane.getStyledDocument ();
doc.remove (0, doc.getLength ());
addStylesToDocument (doc, url, initStyles);
for ( int i = 0; i initString.size (); i++ )
{
doc.insertString (doc.getLength (), initString.get (i), doc.getStyle (initStyles.get (i)));
}
}
catch (Exception e)
{}
}
protected void addStylesToDocument ( StyledDocument doc, ListString url, ListString initStyles )
{
Style def = StyleContext.getDefaultStyleContext ().getStyle (StyleContext.DEFAULT_STYLE);
for ( int i = 0; i initStyles.size (); i++ )
{
Style s = doc.addStyle (initStyles.get (i), def);
StyleConstants.setAlignment (s, StyleConstants.ALIGN_CENTER);
ImageIcon icon = createImageIcon (url.get (i));
if (icon != null)
{
StyleConstants.setIcon (s, icon);
}
}
}
protected static ImageIcon createImageIcon ( String url )
{
URL imgURL = null;
try
{
imgURL = new URL (url);
if (imgURL != null)
{
return new ImageIcon (imgURL);
}
}
catch (Exception e)
{}
return null;
}
private void resolveHTML ( String spec, String charsetName, String regex )
{
try
{
URL url = new URL (spec);
HttpURLConnection huc = (HttpURLConnection) url.openConnection ();
InputStreamReader isr = new InputStreamReader (huc.getInputStream (), charsetName);
BufferedReader br = new BufferedReader (isr);
StringBuilder builder = new StringBuilder ();
String line = null;
while (null != ( line = br.readLine () ))
{
builder.append (line);
}
br.close ();
isr.close ();
huc.disconnect ();
String bs = builder.toString ();
Pattern pattern = Pattern.compile (regex);
Matcher matcher = pattern.matcher (bs);
initString.clear ();
initStyles.clear ();
path.clear ();
while (matcher.find ())
{
String p = matcher.group (1);
initString.add (” “);
initStyles.add (p);
path.add (p);
}
loadImages (initString, initStyles, path);
}
catch (Exception e)
{
return;
}
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
ImageViewer tester = new ImageViewer ();
tester.addComponents ();
tester.setVisible (true);
}
});
}
}
用java如何編輯圖片的主題,標題,作者,創建日期等信息?
有的信息,是保存在文件裏面的,要使用exif的格式去修改 ,,,,,,,,,,,apache有這樣的lib
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/249177.html