StretchDraw i Image

0

Sluchajcie, mam taki problem... mam na formie jeden komponent TImage oraz dwa komponenty SpinEdit , chcialbym , aby za pomaca spineditow mozna bylo kontrolowac rozmiary (tzn. wysokosc i szerokosc) obrazka wczytanego do image'a ( chcialbym , aby obrazek byl powiekszany lub pomniejszany automatycznie) probowalem z czyms takim

  image.Width:=spinedit1.Value;
  image.Height:=spinedit2.Value;

oraz z czyms takim

  
  r:=Rect(0, 0, spinedit1.Value, spinedit2.Value);
  bitmap:=TBitmap.Create;
  bitmap.LoadFromFile('plik.bmp');
  image.canvas.StretchDraw(r,bitmap);

niestety... obraz jest rozciagany, ale obszar jego wyswietlania nie zmienia sie :(, stad doszedlem do wniosku, ze kod

  image.Width:=spinedit1.Value;
  image.Height:=spinedit2.Value;

nie spelnia moich oczekiwan... w jaki sposob rozwiazac ten problem ?

0
//wczytywanie
Image1.Picture.LoadFromFile('D:\Documents and Settings\Wiktor\Moje dokumenty\m02e.jpg');
Image1.Width := Image1.Picture.Width;
Image1.Height := Image1.Picture.Height;
Image1.Stretch := true;

//...

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
  Image1.Width := SpinEdit1.Value;
end;

procedure TForm1.SpinEdit2Change(Sender: TObject);
begin
  Image1.Height := SpinEdit2.Value;
end;
0

ok dziala ;]

0

Mam inny problem z StretchDraw:

procedure Tmainform.odbijWPoziomie;
var Bmp : TBitMap;
begin
  Bmp :=TBitMap.Create;
  Bmp.Width :=Image.width;
  Bmp.Height :=Image.Height;
  bmp.PixelFormat :=pf24bit;
  bmp.Canvas.StretchDraw(Rect(Image.Width,0,0, Image.Height),Image.Picture.Bitmap);
  Image.Picture.Bitmap := Bmp;
  Bmp.Free;
end;

Ucina mi jeden rząd pixeli

procedure Tmainform.OdbijWPionie;
var Bmp : TBitMap;
begin
  Bmp :=TBitMap.Create;
  Bmp.Width :=Image.width;
  Bmp.Height :=Image.Height;
  bmp.PixelFormat :=pf24bit;
  Bmp.Canvas.StretchDraw(Rect(0,Bmp.Height,Bmp.Width,0),Image.Picture.Bitmap);
  Image.Picture.Bitmap := Bmp;
  Bmp.Free;
end;

Ucina mi 3 rzędy pixeli.

Stosując Bmp.Height :=Image.Picture.Bitmap.Height; dzieje się tak samo.

Ucina/modyfikuje/nadpisuje.

0

Oto kod:

procedure Tform1.OdbijWPionie;
var Bmp : TBitMap;
begin
  Bmp :=TBitMap.Create;
  Bmp.Width :=Image.picture.bitmap.width;
  Bmp.Height :=Image.picture.bitmap.Height;
  bmp.PixelFormat :=pf24bit;
  Bmp.Canvas.StretchDraw(Rect(0,Bmp.Height,Bmp.Width,0),Image.Picture.Bitmap);
  Image.Picture.Bitmap := Bmp;
  Bmp.Free;
end;

procedure Tform1.odbijWPoziomie;
var Bmp : TBitMap;
begin
  Bmp :=TBitMap.Create;
  Bmp.Width :=Image.width;
  Bmp.Height :=Image.Height;
  bmp.PixelFormat :=pf24bit;
  bmp.Canvas.StretchDraw(Rect(Image.Width,0,0, Image.Height),Image.Picture.Bitmap);
  Image.Picture.Bitmap := Bmp;
  Bmp.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
var bmp : TBitmap;
    wsk : ^byte;
    i:integer;
begin
// tworzymy i wypełniamy bitmape
  bmp := TBitmap.create;
  Image.Picture.Bitmap := bmp;
  Image.Picture.Bitmap.Height := 100;
  Image.Picture.Bitmap.Width := 100;
  Image.Picture.Bitmap.PixelFormat :=pf24bit;
  Image.Picture.Bitmap.Canvas.Brush.Color := clWhite;
  Image.Picture.Bitmap.Canvas.Rectangle(0,0,Image.Picture.Bitmap.width,Image.Picture.Bitmap.Height);
  Image.Picture.Bitmap.Canvas.FloodFill(0,0,clWhite,fsBorder);

// zmieniamy kolor 1 rzedu pixeli na czarny:
  wsk := Image.Picture.Bitmap.ScanLine[0];
  for i:=0 to (Image.Width)*3 do
  begin
    wsk^ := 0;
    inc(wsk);
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
odbijwpoziomie;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
odbijwpionie;
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1