首先,读取一个图片文件到UIImage对象中,添加到一个UIImageView视图中。UIImageView的size设置成和图片的size一样。保证图片能全部展现。
// Create the image from a png file
UIImage *image = [UIImage imageNamed:@"prgBinary.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// Get size of current image
CGSize size = [image size];
// Frame location in view to show original image
[imageView setFrame:CGRectMake(0, 0, size.width, size.height)];
[[self view] addSubview:imageView];
[imageView release];
这样UIIma...
以下是代码:【运行代码】【复制代码】 <script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //定义允许图片宽度
var iheight = 100; //定义允许图片高度
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+"&...
图片文件格式转换最核心的问题就是要解决各种图片格式的编码和解码,推荐用jimi包,可从http://java.sun.com/products/jimi/下载该包及其源码和demo。 需要注意的是:jimi提供了对几乎所有图片格式的解码支持,但是为提供gif和tif/tiff格式的编码api,gif编码问题在网上可以找到县相关的源码,tiff好像jai:http://java.sun.com/products/java-media/jai/index.jsp提供了它的编码,不过我没有用jai,暂时用jpeg编码代替了。 察看jimi的源码,在com.sun.jimi.core中是jimi的核心处理api。public void toJPG(String source, String dest, int quality) {if (dest == null || dest.trim().equals("")) dest = source;if (!dest...