// 这是一个嵌入到网页中动态显示50是张的java小应用程序,希望你对有帮助!
import javaawt;
import javaapplet;
public class Picture extends Applet
{
Image[] theImages;
int nNum = 50;
int nNow = 0;
public void init()
{
theImages = new Image[nNum];
for(int i = 0; i < nNum ; i++)//将装入数组
theImages[i] = getImage(getDocumentBase(), "pic" + IntegertoString(i) + "jpg");
}
public void start()
{
nNow = 0;
}
public void paint(Graphics g)
{
gdrawImage(theImages[nNow],500,500,this);
nNow++;
if(nNow>=nNum)
nNow = 0;
try
{
Threadsleep(50);
}
catch(Exception e){showStatus(etoString());}
repaint();
}
public void main()
{
Graphics g;
g=thisgetGraphics ();
init();
start();
paint(g);
}
}
依次读取照片的路径,输入路径字符串,得到文件对象;全程同步顺序 *** 作;
手机文件详情中路径:内部存储/Pictures/IMG_1589761748105jpg
程序中获取的路径:file:///storage/emulated/0/Pictures/IMG_1589761748105jpg
class imgFileToFileObj{
constructor(){
}
submit: function (){
var box=new imgFileToFileObj();
var fileAllPath = 'file:///storage/emulated/0/Pictures/IMG_1589761748105jpg';
var imgFileStrList = new Array();
imgFileStrListpush(fileAllPath);
imgFileStrListpush(fileAllPath);
imgFileStrListpush(fileAllPath);
(async () => {
var fileArrayOne= await boxdoChange(imgFileStrList);
consolelog(' 我应该是最后的最后 fileArray = '+fileArrayOne)
})()
}
里的值?这个我不知道,但你把链接加上字段不行嘛?
<a href="testaspxid=100"><img src="showjpg"></a>
在testaspx那个页面RequestQueryString["id"]就能得到那个传值了。
JFreeChart chart =null;
PiePlot pieplot = (PiePlot) chartgetPlot();//获取对象
// 中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
piePlotsetLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}({2})", NumberFormatgetNumberInstance(),
new DecimalFormat("000%")));
以上为关键代码。需要通过setLableGenerator方法设置标签显示格式。StandardPieSectionLabelGenerator对象构造方法中,{0},{2}都将被替换为相应字符,{0}显示的是花生、大豆等信息,{2}显示的是百分比,后面两个参数是设置百分比格式,可以不设置,默认不保留小数点。最后图表显示的信息为:花生(xxxx%) 小麦(xxxx%)。
图下面的描述也可以设置显示格式,关键代码为:
// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例piePlotsetLegendLabelGenerator(new StandardPieSectionLabelGenerator(
"{0} ({2})"));
注意,这是setLegendLableGenerator()。可以多试试new StandardPieSectionLabelGenerator("{0} ({2})")里的参数设置。
将保存到数据库中:
步骤1以二进制方式读取图像文件
//利用FileStream读取制定路径的文件
FileStream fs = new FileStream(thistxtImagePathText, FileModeOpen);
int iLength = intParse(fsLengthToString());//获取当前文件的长度
Byte[] fileByte = new Byte[iLength];//创建一个byte[]的数组,用来保存文件的内容
fsRead(fileByte, 0, iLength);//通过Read方法,把文件的内容读取到byte[]数组中。
fsDispose();
步骤2将信息插入到数据库中
SqlConnection conn = new SqlConnection(@"server=\SQLEXPRESS;database=ImageDataBase;uid=sa");
//插入数据库
string strSql = "Insert Into tbl_Image (ImageFile) Values(@img)";
SqlCommand cmd = new SqlCommand(strSql, conn);
cmdParametersAdd("@img", SqlDbTypeImage, iLength)Value = fileByte;
//通过赋值保存的的参数的值,为SqlDbTypeBinary
connOpen(); //打开连接
cmdExecuteNonQuery(); //执行命令
connClose();
将从数据库中读取显示:
步骤1从数据库中读取Image字段信息
Byte[] fileContent;
using (SqlConnection conn = new SqlConnection(@"server=\SQLEXPRESS;database=ImageDataBase;uid=sa;pwd=12345")){
string strSql = "select ImageFile from tbl_Image";
SqlCommand cmd = new SqlCommand(strSql, conn);
connOpen();
SqlDataReader dr = cmdExecuteReader();
//以上步骤完成一般的SqlCommand的命令的执行,
//返回了一个SqlDataReader把的内容赋值到一个byte[]数组上。
if (drRead()) {
fileContent = (Byte[])dr["ImageFile"];
}else {
fileContent = new Byte[0];
}
drClose();
}
步骤2将二进制信息显示在PictureBox控件中
//通过内存流MemoryStream,
//把byte[]数组fileContent加载到Image中并赋值给框的Image属性,
//让数据库中的直接显示在窗体上。
MemoryStream ms = new MemoryStream(fileContent, 0, fileContentLength);
thispbShowImageImage = ImageFromStream(ms);
//关闭内存流
msClose();
以下为我写过一一个函数用来获取,首先得到img标签的HtmlElement对象,然后IHTMLControlRange复制的方式得到。
/// <summary>
/// 返回指定WebBrowser中<IMG></IMG>中的图内容
/// </summary>
/// <param name="WebCtl">WebBrowser控件</param>
/// <param name="ImgeTag">IMG元素</param>
/// <returns>IMG对象</returns>
private Image GetWebImage(WebBrowser wb, string id)
{
HtmlElement ImgeTag = wbDocumentGetElementById(id);
if (ImgeTag == null)
{
return null;
}
HTMLDocument doc = (HTMLDocument)wbDbDocumentDomDocument;
HTMLBody body = (HTMLBody)docbody;
IHTMLControlRange rang = (IHTMLControlRange)bodycreateControlRange();
IHTMLControlElement Img = (IHTMLControlElement)ImgeTagDomElement; //地址
object oldobj = ClipboardGetDataObject(); //备份粘贴版数据
rangadd(Img);
rangexecCommand("Copy", false, null); //拷贝到内存
Image numImage = ClipboardGetImage();
try
{
ClipboardSetDataObject(oldobj); //恢复粘贴板内容
}
catch { }
return numImage;
}
效果如下:
以上就是关于Java如何获取网页上的图片转成Image对象全部的内容,包括:Java如何获取网页上的图片转成Image对象、h5+ 读取本地图片文件,转为file对象、html中有几张图片,点击之后都跳到另一个页面,怎么在这个页面获取刚才图片页里面的值和对象等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)