Tbitmap save problem

hello,
i'm programming a programme to sort foto's for a poster.
when i'm trying to save my Tbitmap windows go's crasy "not enough virtual memory" and stuff like that.
i think this is quit logic because the size of my Tbitmap is 14080x10560
I'm saving the Tbitmap with  procedure SaveToFile().

is there an solution?
maybe SaveToStream();

Greetz Carlas Smith
krydeaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

geobulCommented:
Hello,

If your bitmap is 24 bits per pixel then it occupies more than 400 MB. Try the following procedure:

procedure SaveBmpAsFile(gr: TBitmap; f: string);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create(f, fmCreate);
  try
    gr.SaveToStream(fs);
  finally
    fs.Free;
  end;
end;

call it like:

SaveBmpAsFile(Image1.Picture.Bitmap, 'c:\image.jpg');

Regards, Geo
ZhaawZSoftware DeveloperCommented:
i suppose it should be 'c:\image.bmp', not .jpg
geobulCommented:
Of course :-)
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

krydeaAuthor Commented:
application doesn't responed.

maybe add an
fs.onprogress:=....;

for
Application.ProcessMessages;
and a progressbar?
krydeaAuthor Commented:
function BmpToJpeg(bmp: TBitmap): TJpegImage;

var
jpeg: TJpegImage;
begin

jpeg := TJpegImage.Create;

jpeg.assign(bmp);

result:=jpeg;

end;

//app
var
jpeg : Tjpegimage;


jpg:=BmpToJpeg(BigBmp);
FreeAndNil(BigBmp);
jpg.savetofile('d:\bla.jpeg');


works it's only 9 mb:>
saravananvgCommented:
Hello Sir,

  Check the following if it is of any use to you

http://www.swissdelphicenter.ch/torry/showcode.php?id=140

with regards,
padmaja.
ArhiCoderCommented:
Hello, try this:

procedure TForm1.Button1Click(Sender: TObject);
const
    COUNT=100;  // bytes per write subaction
var
    bmp:TBitmap;
    fs:TFileStream;
    s:TMemoryStream;
    i:Integer;
    buf:Pointer;
begin
    bmp:=TBitmap.Create;
    bmp.LoadFromFile('D:\\test.bmp');  // Your picture (use any else load of it if you want)
    s:=TMemoryStream.Create;
    fs:=TFileStream.Create('D:\\testing.bmp',fmCreate or fmOpenWrite); // Output file
    bmp.SaveToStream(s);
    s.Position:=0;
    buf:=AllocMem(COUNT);
    repeat
        i:=s.Read(buf^,COUNT);
        fs.WriteBuffer(buf^,i);
    until i<COUNT;
    FreeMem(buf,COUNT);
    fs.Free;
    s.Free;
    bmp.Free;
end;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gandalf_the_whiteCommented:
using a 9mb jpg is not really desireable

why do you need such a big bitmap?
if you try to find a solution that uses more smaller bitmaps
they would be easier to handle and will not take so much memory
krydeaAuthor Commented:
i have about 600 foto's witch i want to print with a high resolution printer add school on a poster. doing this by hand is not really desireable:p
krydeaAuthor Commented:
ArhiCoder, your code works:>
But i don't understand your pointer?
ArhiCoderCommented:
buf:Pointer; - this is just pointer to buffer in the memory, where I storing parts of file.
Th&#1077;n write their (parts) into HDD.
Size of one part defines with COUNT constant.
krydeaAuthor Commented:
Shit ArhiCoder,
i do get an entry error when i'm saving the bitmap (in dutch a: "ingang foutmelding:0 ") .
and if i use savetofile(); i get a streamerror.
what is going wrong????

Greetz Carlas Smith
ArhiCoderCommented:
I do not know... May be problem in you bitmap content or structure.
May be TBitmap class not created for saving so big images.
My advise - start creating own class for BMP files.
However you can just search such souces in Torry (www.torry.net)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.