包含tagrectjava的词条

博主:adminadmin 2022-12-25 04:45:09 57

本篇文章给大家谈谈tagrectjava,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java 将pdf转成JPG。。

BufferedImage tag = new BufferedImage(rect.width, rect.height,

BufferedImage.TYPE_INT_RGB);

这句是读入图片的流,传入的参数是图片本身的长,高,RGB色位。

tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,

null);

这句是输出图片的方法,几个参数分别是,图片对象,0,0,图片的长,高,null。

所以应该是改下句的这两个参数,你把rect.width和rect.height的数值放大两倍看看。

应该是这里。

java 登陆时的验证码怎么做?

后台写一个生成图片随机的代码,生成图片给前台。切换图片的时候,使用ajax获取图片数据就行。

附上生成图片的代码

public class ValidateCode {

private int width=180;

private int height=60;

private int codeCount = 4;

private int x = 0;

private int codeY;

private String Code;

private BufferedImage buffImg;

static char[] codeSequence = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',

'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',

'X', 'Y', 'Z','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',

'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',

'x', 'y', 'z', 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

private int fontHeight;

public ValidateCode() {

x = width / (codeCount + 2);

fontHeight = height - 2;

codeY = height - 4;

CreateCode();

}

public void CreateCode(){

// 定义图像buffer

BufferedImage buffImg = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);

Graphics2D g = buffImg.createGraphics();

// 创建一个随机数生成器类

Random random = new Random();

// 将图像填充为白色

g.setColor(Color.WHITE);

g.fillRect(0, 0, width, height);

// 创建字体,字体的大小应该根据图片的高度来定。

Font font = new Font("Fixedsys", Font.PLAIN, fontHeight);

// 设置字体。

g.setFont(font);

// 画边框。

g.setColor(Color.BLACK);

g.drawRect(0, 0, width - 1, height - 1);

// randomCode用于保存随机产生的验证码,以便用户登录后进行验证。

StringBuffer randomCode = new StringBuffer();

int red = 0, green = 0, blue = 0;

// 随机产生codeCount数字的验证码。

for (int i = 0; i codeCount; i++) {

// 得到随机产生的验证码数字。

String strRand = String.valueOf(codeSequence[random.nextInt(62)]);

// 产生随机的颜色分量来构造颜色值,这样输出的每位数字的颜色值都将不同。

red = random.nextInt(255);

green = random.nextInt(255);

blue = random.nextInt(255);

// 用随机产生的颜色将验证码绘制到图像中。

g.setColor(new Color(red, green, blue));

g.drawString(strRand, (i ) * x+20, codeY);

// 将产生的四个随机数组合在一起。

randomCode.append(strRand);

}

this.Code=randomCode.toString().toUpperCase();

this.buffImg=buffImg;

}

public String getCode() {

return Code;

}

public void setCode(String code) {

Code = code;

}

public BufferedImage getBuffImg() {

return buffImg;

}

public void setBuffImg(BufferedImage buffImg) {

this.buffImg = buffImg;

}

}

javaweb pdf流转jpg流怎么操作?

package pdf;

import java.awt.Image;

import java.awt.Rectangle;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.RandomAccessFile;

import java.nio.ByteBuffer;

import java.nio.channels.FileChannel;

import javax.swing.SwingUtilities;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGEncodeParam;

import com.sun.image.codec.jpeg.JPEGImageEncoder;

import com.sun.pdfview.PDFFile;

import com.sun.pdfview.PDFPage;

public class PdfToJpg {

public static void setup() throws IOException {

// 加载一个pdf从一个字节缓冲区

File file = new File("D:\\yangliu\\test.pdf");

RandomAccessFile raf = new RandomAccessFile(file, "r");

FileChannel channel = raf.getChannel();

ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0,

channel.size());

PDFFile pdffile = new PDFFile(buf);

System.out.println("页数:" + pdffile.getNumPages());

String getPdfFilePath = System.getProperty("user.dir") + "\\pdfPicFile";

System.out.println("getPdfFilePath is :" + getPdfFilePath);

for (int i = 1; i pdffile.getNumPages(); i++) {

// 画第一页到一个图像

PDFPage page = pdffile.getPage(i);

// 获得宽度和高度的文件在默认的变焦

Rectangle rect = new Rectangle(0, 0, (int) page.getBBox()

.getWidth(), (int) page.getBBox().getHeight());

// 生成图像

Image img = page.getImage(rect.width, rect.height, rect, null,

true, true);

BufferedImage tag = new BufferedImage(rect.width, rect.height,

BufferedImage.TYPE_INT_RGB);

tag.getGraphics().drawImage(img, 0, 0, rect.width, rect.height,

null);

// 输出到文件流

FileOutputStream out = new FileOutputStream(getPdfFilePath + "\\"

+ i + ".jpg");

System.out.println("成功保存图片到:"+getPdfFilePath+"\\"+i+".jpg");

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);

JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(tag);

param.setQuality(1f, false); //1f是提高生成的图片质量

encoder.setJPEGEncodeParam(param);

encoder.encode(tag); // JPEG编码

out.close();

}

}

public static void main(final String[] args){

SwingUtilities.invokeLater(new Runnable() {

public void run() {

try {

PdfToJpg.setup();

} catch (IOException e) {

e.printStackTrace();

}

}

});

}

}

VC++ MFC CRect中opearor LPRECT如何实现。

首先确定这是一个重载。就好比int a = 5; 凭什么 = 就能直接用。c语言也许想当然,但是到java中你就会明白 = 其实是重载了的。再比如 char c = 65;这其实都是编译器做好了转换。如果不做转换,编译都不能通过。

返回的LPRECT很简单,也许CRect里面有个成员变量RECT rc,那么重载函数返回 rc 就行了。

Java怎么把PDF转化成图片

表示不会使用Java将pdf转换成图片,但是要将pdf转换成图片可以使用专业的pdf转换工具啊。

大致的转换方法如下:

打开并运行迅捷pdf转换器,选择PDF转成其他文件中的“转成图片”选项;

点击上方或者是下方的“添加文件”选项,将要转换的pdf添加进来;

文件被添加完成点击“开始转换”按钮,等待一会之后文件就会被转换完成,进行打开查看即可

请进!!如何把绘制的图片直接以二进制流存入数据库(java)

怎样在mysql中存储比较大的图片?

如果你想把二进制的数据,比如说图片文件和HTML文件,直接保存在你的MySQL数据库,那么这篇文章就是为你而写的!我将告诉你怎样通过HTML表单来储存这些文件,怎样访问和使用这些文件。

一、本文概述

本文的主要内容如下:

* 在MySQL中建立一个新的数据库

* 一个怎样储存文件的例子程序

* 一个怎样访问文件的例子程序

二、在MySQL中建立一个新的database

首先,你必须在你的MySQL中建立一个新的数据库,我们将会把那些二进制文件储存在这个数据库里。在例子中我会使用下列结构,为了建立数据库,你必须做下列步骤:

1. 进入MySQL控制器

2. 输入命令"create database binary_data;"

3. 输入命令"use binary_data;"

输入如下命令:

"CREATE TABLE binary_data ( id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,description CHAR(50), bin_data LONGBLOB, filename CHAR(50), filesize CHAR(50), filetype CHAR(50));" (不能断行)

如果没有意外,数据库 和 表 应该建立好了。

三、一个怎样储存文件的例子程序

用这个例子你可以通过Html表单将文件传输到数据库中。

store.php3

// store.php3 - by Florian Dittmer

?

// 如果提交了表单,代码将被执行:

if ($submit) {

// 连接到数据库

// (你可能需要调整主机名,用户名和密码)

MYSQL_CONNECT( "localhost", "root", "password");

MySQL_select_db( "binary_data");

$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

$result=MYSQL_QUERY( "INSERT INTO binary_data (description,bin_data,filename,filesize,filetype)VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");

$id= MySQL_insert_id();

print "This file has the following Database ID: $id";

MYSQL_CLOSE();

} else {

// 否则显示储存新数据的表单

?

@MySQL_select_db( "binary_data");

$query = "select bin_data,filetype from binary_data where id=$id";

$result = @MYSQL_QUERY($query);

$data = @MYSQL_RESULT($result,0, "bin_data");

$type = @MYSQL_RESULT($result,0, "filetype");

Header( "Content-type: $type");

echo $data;

};

?

程序必须知道要访问那个文件, 你必须将ID作为一个参数。

例如: 一个文件在数据库中的ID为2. 你可以这样调用它: getdata.php3?id=2

如果你将图片储存在数据库里, 你可以向调用图片一样调用它。

Example: 一个图片文件在数据库中的ID为3. 你可以这样调用它:

五、怎样储存大于1MB的文件

如果你想储存大于1MB的文件,你必须对你的程序、PHP设置、SQL设置进行许多修改。

下面几条也许可以帮助你储存小于24MB的文件:

1) 修改 store.php3,将 MAX_FILE_SIZE 的值改成 24000000。

2) 修改你的PHP设置,在一般情况下,PHP只允许小于2MB的文件,你必须将max_filesize(在php.ini中)的值改成24000000

3) 去掉MYSQL的数据包大小限制,在一般情况下 MYSQL 小于1 MB的数据包。

4) 你必须用以下参数重启你的MYSQL :/usr/local/bin/safe_MySQLd -O key_buffer=16M -O table_cache=128 -O sort_buffer=4M -O record_buffer=1M -O max_allowed_packet=24M

5) 如果仍然出错:可能是超时错误,如果你通过一个很慢的连接来储存一个很大的文件,PHP缺省的时间限制为30秒。你可以将max_execution_time(在php.ini中)的值改为-1

下面是一个老外写的,可以读

Saving Images in MySQL

Sometimes, it's more convenient to save images in a database than as files.

MySQL and PHP make it very easy to do this. In this article, I will describe

how to save images in a MySQL database and display them later on.

Setting up the database

The difference between any regular text or integer fields and a field that

needs to save an image is the amount of data that is needed to be held in the

field. MySQL uses special fields to hold large amounts of data. These fields

are known as blobs (blob).

Here is the BLOB definition from the MySQL site :

A BLOB is a binary large object that can hold a variable amount of data. The

four BLOB types TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB differ only in the

maximum length of the values they can hold

For more information about MySQL BLOBs check out

hapter/manual_Reference.html#BLOB

Use the next syntax to create a basic table that will hold the images:

CREATE TABLE Images (

PicNum int NOT NULL AUTO_INCREMENT PRIMARY KEY,

Image BLOB

);

Setting the upload script

An example of a file upload front end can be seen at File Uploading by berber

(29/06/99). What we need now is the PHP script that will get the file and

insert it into MySQL. The next script does just that. In the script, I'm

assuming that the name of the file field is "icture".

?

If($Picture != "none") {

$PSize = filesize($Picture);

$mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize));

unlink($Picture);

mysql_connect($host,$username,$password)

or die("Unable to connect to SQL server");

@mysql_select_db($db)

or die("Unable to select database");

mysql_query("INSERT INTO Images (Image) VALUES '($mysqlPicture')")

or die("Can't Perform Query");

}

else {

echo"You did not upload any picture";

}

?

This is all that is needed to enter the image into the database. Note that in

some cases you might get an error when you try to insert the image into

MySQL. In such a case you should check the maximum packet size allowed by

your MySQL ver. It might be too small and you will see an error about this in

the MySQL error log.

What we did in the above file is :

1. Check if a file was uploaded with If($Picture != "none").

2. addslashes() to the picture stream to avoide errors in MySQL.

3. Delete the temporary file.

3. Connect to MySQL, choose the database and insert the image.

Displaying the Images

Now that we know how to get the images into the database we need to figure

out how to get them out and display them. This is more complicated than

getting them in but if you follow these steps you will have this up and

running in no time.

Since showing a picture requires a header to be sent, we seem to be in an

impossible situation in which we can only show one picture and than we can't

show anymore Since once the headers are sent we can't send any more headers.

This is the tricky part. To outsmart the system we use two files. The first

file is the HTML template that knows where we want to display the image(s).

It's a regular PHP file, which builds the HTML that contains the IMG tags,

as we want to display them. The second file is called to provide the actual

file stream from the database directly into the SRC property of the IMG

tag.

This is how a simple script of the first type should look like:

HTML

BODY

?

mysql_connect($host,$username,$password)

or die("Unable to connect to SQL server");

@mysql_select_db($db)

or die("Unable to select database");

mysql_query("SELECT * FROM Images")

or die("Can't Perform Query");

While($row=mysql_fetch_object($result)) {

echo "IMG SRC=\"SecondType.php3?PicNum=$row-icNum\"";

}

?

/BODY

/HTML

While the HTML is being displayed, the SecondType.php3 file is called for

each image we want to display. The script is called with the Picture ID

(PicNum) which allows us to fetch the image and display it.

The SecondType.php3 file looks like this :

?

$result=mysql_query("SELECT * FROM Images WHERE PicNum=$PicNum")

or die("Can't perform Query");

$row=mysql_fetch_object($result);

Header( "Content-type: image/gif");

echo $row-Image;

?

This is the whole theory behind images and MySQL. The scripts in this example

are the basics. You can now enhance these scripts to include thumbnails, set

the images in various positions, enhance the database table to hold an ALT

field, Check the width and height of the images before you insert them into

the database and keep that data in the table too etc...

关于tagrectjava和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-25,除非注明,否则均为首码项目网原创文章,转载请注明出处。