请问建立bitmap:=Tbitmap.create,怎样设置可以通过loadfromfile载入合乎自己要求大小的位图,也就是无论位图实际多大,载入后自己缩放为我想要的大小.
  我要通过内存中的位图数据得到自己想要的一定大小的缓存数据

解决方案 »

  1.   

    Tbitmap中没有这种功能,你只能自己写代码来缩放.
      

  2.   

    请问可不可以用api函数将源文件缩放重画到dc中再将dc中的数据取回来哪?
      

  3.   

    设置TBitmap width 和 height同时stretch 为true;
      

  4.   

    不用调用GDI,在Delphi中,已经用Canvas对这些进行了封装!如
    TBitmap.Canvas.StretchDraw
    TBitmap.Canvas.CopyRect
      

  5.   

    谢谢大家的解答,我想得到每点的颜色分析存储为适合led电子显示屏大小的色彩数据.不只是向显示器上画,还要向端口送速据的.所以要先得到合乎要求的数据.大概的数据采集程序如下:清帮忙分析:
    procedure TForm1.PlayClick(Sender: TObject);
    var
      fn,MyfileExt:string;
      imjpg:TJPEGImage;
      prgb:PRGBArraye;
      i,j,k,n,h,w:integer;
      red,green,rbyte,gbyte:byte;begin
      if listview1.Items.Count>0 then
      begin
        form3.Show;
        form3_play:=true;
        while form3_play=true do
        begin
          s.canvasdc:=form3.Image1.Canvas.Handle;
          for i:=0 to listview1.Items.Count-1 do
          begin
            listview1.Items.Item[i].Focused:=true;
            if form3_play=false then break;
            bitmap:=Tbitmap.Create;
            fn:=listview1.Items.Item[i].Caption;
            MyfileExt:=ExtractFileExt(fn);
            if MyfileExt='.bmp' then
            begin
              bitmap.LoadFromFile(fn);
            end;
            if (MyfileExt='.jpg')or (MyfileExt='.jpeg') then
            begin
              imjpg:=TJPEGimage.create;
              imjpg.LoadFromFile(fn);
              imjpg.PixelFormat:=jf24bit;
              bitmap.Assign(imjpg);
            end;
            Bitmap.PixelFormat:=pf24bit;  //问题解决了,载入256色文件后,设定这项就可以了
            IF Bitmap.PixelFormat <> pf24bit
              THEN showmessage('GetImageSpace:  ' +
                     'Bitmap must be 24-bit color.');
            buf_s:=AllocMem((led_Height*led_Width)div 8);
            k:=0;
            rbyte:=0;
            gbyte:=0;
            if led_height>bitmap.Height then h:=bitmap.Height
               else h:=led_height;
            if led_width>bitmap.Width then w:=bitmap.Width
               else w:=led_width;
            for j:=0 to h-1 do
            begin
              prgb:=Bitmap.ScanLine[j];
              for n:=0 to w-1 do
              begin
                if prgb[n].rgbtGreen>128 then green:=1 else green:=0;
                if prgb[n].rgbtRed>128 then red:=1 else red:=0;
                gbyte:=green or (gbyte shl 1);
                rbyte:=red or (rbyte shl 1);
                if ((n+1) mod 8)=0 then
                begin
                  buf_s[k]:=gbyte and rbyte;
                  inc(k);
                  gbyte:=0;
                  rbyte:=0;
                end;
              end;
            end;        s.utdj(bitmap.Canvas.Handle,buf_s,StrToInt(listview1.Items.Item[i].SubItems.Strings[5]),
                 StrToInt(listview1.Items.Item[i].SubItems.Strings[6]),StrToInt(listview1.Items.Item[i].SubItems.Strings[7]),StrToInt(listview1.Items.Item[i].SubItems.Strings[8]));
            bitblt(form3.Image1.Canvas.Handle,0,0,420,420,bitmap.Canvas.Handle,0,0,srccopy);
            delay(strtoint(listview1.Items.Item[i].SubItems.Strings[2])*1000);
            freemem(buf_s,(led_Height*led_Width)div 8);
            bitmap.Free;
            if (MyfileExt='.jpg')or(MyfileExt='.jpeg')then imjpg.Free;
          end;//i
        end;//while
        form3.Close;
      end;//if
    end;
    以上的程序只得到了小于屏幕大小的图像数据或是在大的图像上截取了屏幕大小的数据区!我想得到和屏幕大小相同的图像的数据!就是这样,请多帮忙!
      

  6.   

    是变形了,请问Bitmap.ScanLine得到的会是变形后的图像数据吗?
      

  7.   

    显然不是~!.. ...你有速度要求么?若没速度要求可以直接把你要取的像素(canvas的属性)的十六进制颜色分量运算后直接取出到三个结构里(数组也行,链表也可)就完事了~