drawimage大小(QPainter如何自适应大小画图)

本文目录
QPainter如何自适应大小画图
函数声明:void QPainter::drawImage ( const QRectF & target, const QImage & image, const QRectF & source, Qt::ImageConversionFlags flags = Qt::AutoColor )举例:QRectF target(10.0, 20.0, 80.0, 60.0); //建立目标矩形
//(10.0, 20.0, 80.0, 60.0)位置上,大小自适应1:voidImageWidget::paintEvent(QPaintEvent *event) {2:QPainter painter(this);3:QRectF target(0, 0,
网页里自动调整图片大小的问题
很简单,在这个图片后面照样加上宽和高的设置,像这样,我这里把限制图片的代码也发上来了
《script language="JavaScript"》
《!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width》0 && image.height》0){
flag=true;
if(image.width/image.height》= iwidth/iheight){
if(image.width》iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height》iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//--》
《/script》
调用:《img src="图片" onload="javascript:drawImage(this,100,100)" width=100 height=100》
image的大小如何设置
System.Drawing.Image img = System.Drawing.Image.FromFile(sSourceFile);//原图形
System.Drawing.Bitmap desImg = new System.Drawing.Bitmap(640,480);//目标图形640X480
Graphics g; //创建一个图形对象。
g = Graphics.FromImage(desImg);
g.DrawImage(img, new Rectangle(0, 0, desImg.Width, desImg.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); //将原img图形,缩放到目标640X480大小
通过DrawImage方法后,生成的desImg可以再使用Bitmap的Save方法再次存储为图形文件或者直接绘制到WinForm界面。
以上代码的具体含义可查看MSDN关于.Net FrameWork的Graphics一节。
javascript如何调整调整图片大小,裁剪代码实例详解
调整图片大小,不走形(FF IE 兼容)
// 用法 《img src="this_image_path.jpg" onload="DrawImage(this,450,450);" /》
function DrawImage(ImgD,FitWidth,FitHeight){
var image=new Image();
image.src=ImgD.src;
if(image.width》0 && image.height》0){
if(image.width/image.height》= FitWidth/FitHeight){
if(image.width》FitWidth){
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
} else{
if(image.height》FitHeight){
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}通过 overflow:hidden进行剪切:
function clipImage(o, w, h){
var img = new Image();
img.src = o.src;
if(img.width 》0 && img.height》0)
{
if(img.width/img.height 》= w/h)
{
if(img.width 》 w)
{
o.width = (img.width*h)/img.height;
o.height = h;
//o.setAttribute("style", "marginLeft:-" + ((o.width-w)/2).toString() + "px");
$(o).css("margin-left", "-"+((o.width-w)/2).toString() + "px");
}
else
{
o.width = img.width;
o.height = img.height;
}
}
else
{
if(img.height 》 h)
{
o.height = (img.height*w)/img.width;
o.width = w;
//o.setAttribute("style", "margin-top:-" + ((o.height-h)/2).toString() + "px");
//$(o).css("style", "margin-top:-" + ((o.height-h)/2).toString() + "px");
$(o).css("margin-top", "-"+((o.height-h)/2).toString() + "px");
}
else
{
o.width = img.width;
o.height = img.height;
}
}
}
}实例:
《style type="text/css"》
ul{list-style:none;}
ul li{float:left;padding:1px;border:#ccc 1px solid;width:120px;height:120px;overflow:hidden;text-align:center;over-flow:hidden;}
《/style》
《ul》
《li》《img src="1.jpg" onload="DrawImage(this,120,120);" /》《/li》
《li》《img src="2.jpg" onload="clipImage(this,120,120);" /》《/li》
《/ul》

本文相关文章:
visual studio code字体大小设置(vs2013设置界面信息字体大小如何更改)
2026年9月16日 01:15
html表格单元格长度(html中table每个单元格大小)
2026年7月19日 07:45
excel比较函数的使用方法(excel比较大小的函数用法)
2026年5月26日 08:45
imagebutton设置图片大小(android里面button的背景图片大小怎么能根据button大小缩放)
2026年5月18日 10:45
mongodb查看数据库(如何获取mongoDB数据库大小)
2026年5月17日 02:30
更多文章:
javascript动效(怎样用js编写一个开关按钮实现动态效果)
2025年7月1日 02:30
雪花秀essential(essentialfirmingcreamex是什么意思)
2026年8月21日 20:30
javasublist用法(Java中linkedlist集合取出部分元素的方法)
2026年5月11日 20:00
literaturereview网站(literaturereview的查重率很高要紧吗)
2026年4月30日 13:30
javamain打包jar运行(java 如何运行带有main方法的jar文件)
2025年6月24日 16:45
paper软件下载(小红车wallpaper电脑端怎么下载)
2025年12月21日 15:15
搜狗浏览器在线使用(电脑如何给搜狗浏览器加速|电脑使用搜狗浏览器加速功能的方法)
2026年9月6日 10:15
html版权标签(html 代码 meta name=“Copyright“ content=“Tencent“的意思)
2026年3月29日 02:15
python读取桌面上的文件(python读取文件操作文件放在哪里)
2025年10月29日 06:30
文本编辑器的(Git Window 下设置默认的文本编辑器)
2025年7月25日 20:30
AT、CVT和双离合究竟哪个更好,老?sigmaplot、spss和R语言的区别 相同点和不同点 总的说哪个更好
2025年11月27日 00:45
html跳转页面(HTML的A标签在本页跳转,这个页面是重新下载的吗)
2026年7月24日 15:45


![声明数组时可以直接指定数组的大小(怎么理解java中不允许在声明时指定数组的大小,int a[] = new int[7];这样没错啊)](/static/images/nopic/5.jpg)








