• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

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
0
krydea
Asked:
krydea
  • 5
  • 3
  • 2
  • +3
1 Solution
 
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
0
 
ZhaawZSoftware DeveloperCommented:
i suppose it should be 'c:\image.bmp', not .jpg
0
 
geobulCommented:
Of course :-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
krydeaAuthor Commented:
application doesn't responed.

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

for
Application.ProcessMessages;
and a progressbar?
0
 
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:>
0
 
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.
0
 
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;
0
 
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
0
 
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
0
 
krydeaAuthor Commented:
ArhiCoder, your code works:>
But i don't understand your pointer?
0
 
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.
0
 
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
0
 
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)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now