本文目录一览:
- 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