Wiatm, otwieram jpg`a z dysku ale chce go pomniejszyc i wyswietlic a poźniej zapisać :( jak to zrobić ??
to się popisales szczegolami. jakis kod?
po prostu otwieram w ten sposób:
JPG := TJPEGImage.Create;
JPG.LoadFromFile('C:\obraz.jpg');
Canvas.Draw(0, 0, JPG);
uh, zmęczony byłem i przeczytałem, że coś już napisałeś, ale nie chce działać. Proste - poszukaj w google "delphi jpeg thumbnail"
robie ta tak:
JPG := TJPEGImage.Create;
JPG.LoadFromFile(OpenPictureDialog1.Files.Strings[i]);
ratio := JPG.Width/180;
Bmp := TBitmap.Create;
Bmp.Width := Round(JPG.Width / ratio);
Bmp.Height := Round(JPG.Height / ratio);
Bmp.Canvas.StretchDraw(Rect(0, 0, Bmp.Width - 1, Bmp.Height - 1),JPG);
JPG.Assign(Bmp);
JPG.Compress;
ale jak teraz zapisze ten obraz do pliku to jest fajnie, tylko że linie na tym obrazku są strasznie poszarpane :( jak mam tego uniknąć ??
Zastosuj algorytm interpolacji.
http://pl.wikipedia.org/wiki/Interpolacja_%28grafika_komputerowa%29
http://www.7880.com/Info/Article-6ae82a00.html
troche mnie zgieło :( <ort>nieda </ort>sie prościej ?? a jeśli sie nie da to jak mam to zastosować :(??
Przecież w drugim linku masz gotowy kod, gotowe funkcje z kilkoma rodzajami interpolacji. Wystarczy zaznaczyć cały kod albo jedną funkcję i zrobić kopiuj -> wklej w swoim programie. Czy da się prościej?
probuje coś z tego zrobić ale mi nic nie wychodzi :( mam zastosować jedną z tych funkcji czy jak ?? :(
tak
udało się :) ale przy wszystkich 3 sposobach jest tak samo - lipnie :( jest jakaś inna metoda ??
Coś źle robisz, ja korzystam z interpolacji w swojej aplikacji i zdjęcia wyglądają rewelacyjnie. Innej metody nie ma tzn. może znajdziesz inne kody, komponenty itp. jednak każdy będzie oparty na jednym z algorytmów interpolacji.
Pokaż jak wygląda teraz Twój kod.
const PixelCountMax = 32768;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array [0..PixelCountMax - 1] of TRGBTriple;
TForm1 = class(TForm)
Button2: TButton;
............
procedure ResizeNearestNeighbor(Src: TBitmap; var Dest: TBitmap;
DestWidth, DestHeight, SrcWidth, SrcHeight: integer);
var
hScale, wScale: double;
fNew: TRGBTriple;
tempSrc, tempDst: PRGBTripleArray;
x, y, i, j: integer;
begin
Dest := TBitmap.Create;
Dest.PixelFormat := pf24Bit;
Dest.Width := DestWidth;
Dest.Height := DestHeight;
Src.PixelFormat := pf24Bit;
Src.Width := SrcWidth;
Src.Height := SrcHeight;
hScale := DestHeight / SrcHeight;
wScale := DestWidth / SrcWidth;
for i := 0 to DestHeight - 1 do
begin
x := round(i / hScale);
if x > SrcHeight - 1 then x := SrcHeight - 1;
tempSrc := Src.ScanLine[x];
tempDst := Dest.ScanLine[i];
for j := 0 to DestWidth - 1 do
begin
y := round(j / wScale);
if y > SrcWidth - 1 then y := SrcWidth - 1;
fNew := tempSrc^[y];
tempDst^[j] := fNew;
end;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
JPG : TJPEGImage;
Bmp, Bmp2 : TBitmap;
SrcWidth, SrcHeight : integer;
begin
Bmp := TBitmap.Create;
Bmp.LoadFromFile('c:\obraz.bmp');
SrcWidth := Bmp.Width;
SrcHeight := Bmp.Height;
ResizeNearestNeighbor(Bmp, Bmp2, 180, 135, SrcWidth, SrcHeight);
JPG.Assign(Bmp2);
image1.Picture.Assign(JPG);
end;
to są dwa fragmenty kody.
bo wykorzystałeś najgorszą metodą
wykorzystaj ResizeBilinear
efekt końcowy był bez różnicy :(
zastosowałem ResizeBilinear i oto efekt :-( :-( :-( :
ja używam odpowiednio zmodyfikowanego kodu SmoothResize
http://www.swissdelphicenter.ch/torry/showcode.php?id=1896
ale tobie powinno wystarczyć Ctrl+C/Ctrl+V ;]