能不能不将JPEG流不放到IMAGE里面就将其缩小? ( 积分: 50 )

  • 主题发起人 主题发起人 hansonboy
  • 开始时间 开始时间
H

hansonboy

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DELPHI写了个ASP的上传组件, 上传图片时想生成预览图(即缩小图片),生成大图时我是用文件流生成的, 能不能在这时直接用这个文件流生成预览图?
 
我用DELPHI写了个ASP的上传组件, 上传图片时想生成预览图(即缩小图片),生成大图时我是用文件流生成的, 能不能在这时直接用这个文件流生成预览图?
 
可以先将JPEG文件流转为JPEG文件,或直接将JPEG文件转成BMP文件,用Image显示的!具体的转法应该可以查到的,手边没有了!
 
学了一招。
 
shiyu281hh,你的方法我试过了, 在普通程序上可以, 但写ASP组却不行, 不知是不是因为Image是可视组件的原因呢?
 
自己顶一下
 
第二天了
 
不是很清楚你的意思,把生成文件流的代码贴出来,直接在内存里面操作TJpegImage
 
我写的是ASP的上传组件,这段是生成原图的函数
function TFileUpload.getitem2(const buf:pchar;
const filesize:integer):boolean;
const
head='Content-Disposition: form-data; name="';//上传图片的头数据标记
filetag='"; filename="';//上传图片的地址标记
file_type='Content-Type: ';上传文件的数据类型标记
var
curr:integer;
taglen:integer;
tag:array[0..50] of char;
temp:array[0..300] of char;
i,k,p,t:integer;
savefile,isfile:boolean;
fs:Tfilestream;
filename,Rndname:string;
function seekstring(from:integer;str:pchar):integer;
var //扫描指定字符串
i:integer;
begin
result:=-1;
for i:=from to filesize-1 do
if buf=str^ then
if strLcomp(str,pchar(@buf),strlen(str))=0 then
begin
result:=i;
break;
end;
end;

function seektag(from:integer):integer;
var //快速扫描标记
i:integer;
begin
result:=-1;
for i:=from to filesize-1 do
if pdword(@buf)^=$2d2d2d2d then //$2d2d2d2d ='----'
if strLcomp(tag,pchar(@buf),taglen)=0 then
begin
result:=i;
break;
end;
end;
begin
curr:=0;
tag[0]:=#0;
t:=seekstring(0,#13#10);
taglen:=t;
strlcopy(tag,buf,taglen);
curr:=taglen+2;
while curr+2<filesize do
if strlcomp(head,@buf[curr],strlen(head))=0 then
begin //检查表单域标记
curr:=curr+strlen(head);
t:=seekstring(curr,'&quot;');
strlcopy(temp,@buf[curr],t-curr);
Inputs[fcount].name:=strpas(temp);//获取表单域名
isfile:=false;
if strlcomp(@buf[t],filetag,strlen(filetag))=0 then
begin //若是文件
t:=t+strlen(filetag);
k:=seekstring(t,'&quot;');
strlcopy(temp,@buf[t],k-t);
isfile:=true;
Inputs[fcount].value:=extractfilename(temp); //文件名
t:=seekstring(k,file_type)+strlen(file_type);
curr:=seekstring(t,#13#10);
strlcopy(temp,@buf[t],curr-t);
Inputs[fcount].filetype:=strpas(temp);//文件类型
curr:=curr+4;
end else
curr:=t+5;

t:=seektag(curr); //扫描下个标记
if not isfile then
begin
buf[t-2]:=#0;
Inputs[fcount].value:=strpas(@buf[curr]);//表单域值
inc(fcount);
curr:=t+2+taglen;
end else
begin
Rndname:=RadomFileName+ExtractFileExt(Inputs[fcount].value) ;
filename:=savepath+Rndname;
Inputs[fcount].filesize:=t-2-curr; //文件大小
savefile:=fileexists(filename) and not foverwrite;
if (length(Inputs[fcount].value)>0) and not savefile then
try
fs:=Tfilestream.create(filename,fmCreate); //生成文件
fs.Writebuffer(buf[curr],t-2-curr);
finally
fs.Free;
end;
inc(fcount);
curr:=t+2+taglen;
end;
end else
exit;
end;
 
如果扩展名是jpg用TJpegImage.LoadFromStream不行?如果是bmp用TBitmap.LoadFromStream?如果再不行,就用LoadFromFile,因为你已经用FS生成了文件了,是什么错误呢?
 
我试过TBitmap.LoadFromStream
再TBitmap.SaveToFile保存出来的文件为空的
 
我想用TIMAGE来处理, 但因为是ASP组件, 所以不能用这种TIMAGE可视组件
 
设置一下fs.position :=0再保存看看
 
谢谢, 原来是这里的问题
 
还想问多个问题, 如果是GIF图片,应该怎样处理呢?
 
Delphi里面没有对应的GIF处理类,需要引用三方的东西,http://www.2ccc.com 有一个GriphicEX(好像是)。他可以处理,你去下载看看,不过也只能处理静态GIF,我是看到楼主说2天没有人回答才来的,记得结贴,谢谢[:D][:D][:D]
 
非常感谢chenybin,问题已解决了
 
接受答案了.
 
后退
顶部