christina sen
asked on
delphi
how to save image in image object
if SavePictureDialog1.Execute then
Image1.Picture.SaveToFile( SavePictur eDialog1.F ileName);
this is not happening
if SavePictureDialog1.Execute
Image1.Picture.SaveToFile(
this is not happening
What type is you image in Image1? (bmp, jpg, ...)
try to use: Image1.Picture.Graphic.Sav eToFile(.. .)
try to use: Image1.Picture.Graphic.Sav
ASKER
Ganesh Gurudu I tried to write code but I do save the file in the form of file, I want the jpeg extension
Do you have jpeg stored in TImage object? Do you load it in design time?
why dont you trying converting the extension and save with that extension only
var
s : string;
Icon: TIcon;
begin
OpenDialog1.DefaultExt := '.ICO';
OpenDialog1.Filter := 'icons (*.ico)|*.ICO';
OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ];
if OpenDialog1.Execute then
begin
Icon := TIcon.Create;
try
Icon.Loadfromfile(OpenDial og1.FileNa me);
s:= ChangeFileExt(OpenDialog1. FileName,' .BMP');
Image1.Width := Icon.Width;
Image1.Height := Icon.Height;
Image1.Canvas.Draw(0,0,Ico n);
Image1.Picture.SaveToFile( s);
ShowMessage(OpenDialog1.Fi leName + ' Saved to ' + s);
finally
Icon.Free;
end;
end;
end;
var
s : string;
Icon: TIcon;
begin
OpenDialog1.DefaultExt := '.ICO';
OpenDialog1.Filter := 'icons (*.ico)|*.ICO';
OpenDialog1.Options := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ];
if OpenDialog1.Execute then
begin
Icon := TIcon.Create;
try
Icon.Loadfromfile(OpenDial
s:= ChangeFileExt(OpenDialog1.
Image1.Width := Icon.Width;
Image1.Height := Icon.Height;
Image1.Canvas.Draw(0,0,Ico
Image1.Picture.SaveToFile(
ShowMessage(OpenDialog1.Fi
finally
Icon.Free;
end;
end;
end;
ASKER
I say the first time I wrote the code works, but when I write the drawing.jpeg I am having trouble opening the file at this time
ASKER
ı would say so. the code you wrote first works , but when ı save it, the drawing.jpeg is saved. ı am having a hard time filing this file
Please, explain more what you trying to do? Which image you need to save where?
I only get that you need to save in jpeg file format.
Ganesh ... you cannot load bmp file into TIcon object.
I only get that you need to save in jpeg file format.
Ganesh ... you cannot load bmp file into TIcon object.
ASKER
sorry i can not tell;
I am making a drawing program I am saving a folder in the image that is drawn in the image with the following code;
SavePictureDialog1.Execute
Image2.Picture.SaveToFile( SavePictur eDialog1.F ileName);
but when saving with this code, it saves it as a file, so I found the solution as follows: I save the drawing as a drawing window.jpg when saving, I can save it as a picture afterwards;
this time when I click on the image file open button that I saved as jpeg, it gives an error :(
I am making a drawing program I am saving a folder in the image that is drawn in the image with the following code;
SavePictureDialog1.Execute
Image2.Picture.SaveToFile(
but when saving with this code, it saves it as a file, so I found the solution as follows: I save the drawing as a drawing window.jpg when saving, I can save it as a picture afterwards;
this time when I click on the image file open button that I saved as jpeg, it gives an error :(
This is because it is not jpeg file format but .bmp I assume. If you choose in SavePictureDialog1 to save as jpeg - then you need to conver it before save...
There are example how to convert bmp to jpeg ...
if SavePictureDialog1.Execute then
begin
if UpperCase(ExtractFileExt(SavePictureDialog1.FileName)) = '.JPG' then
begin
//save as jpeg file...
if Image2.Picture.Graphic is TJpegImage then
Image2.Picture.SaveToFile(SavePictureDialog1.FileName); //save as is
else
Bmp2Jpeg(...); //convert bmp to jpeg and save to jpeg file
end;
if UpperCase(ExtractFileExt(SavePictureDialog1.FileName)) = '.BMP' then
begin
//save as bmp
if Image2.Picture.Graphic is TBitmap then
Image2.Picture.SaveToFile(SavePictureDialog1.FileName); //save as is
else
Jpeg2Bmp(...); //convert jpg to bmp and save to bmp file
end;
....
end;
There are example how to convert bmp to jpeg ...
can you provide the error message with error code
Genesh,
i doubt there is an error message
it's as sinisa says.
it's an image saved with a wrong extension
changing a file extension doesn't change the contents
if you rename iexplore.exe to iexplore.bmp and then open iexplore.bmp,
i'm certain you won't see a bitmap image on the screen
i doubt there is an error message
it's as sinisa says.
it's an image saved with a wrong extension
changing a file extension doesn't change the contents
if you rename iexplore.exe to iexplore.bmp and then open iexplore.bmp,
i'm certain you won't see a bitmap image on the screen
christina
if you are drawing inside your form with the mouse, then you are drawing on a bitmap
not on a jpeg.
if you want to draw on a jpeg, you need to convert it to a bitmap first upon loading it
then you can draw on the bitmap
upon save, you need to convert to jpeg again
if you are drawing inside your form with the mouse, then you are drawing on a bitmap
not on a jpeg.
if you want to draw on a jpeg, you need to convert it to a bitmap first upon loading it
then you can draw on the bitmap
upon save, you need to convert to jpeg again
ASKER
yapmak istediğim sadece image üzerine çizim yapmak ve bunu resim uzantılı kaydetmek
uhm yeah... english ?
there is no such easy thing as just drawing.
only if it's on a bitmap
so you need to convert the source (when it's not bitmap into bitmap)
and for saving convert it back to the source format
here's a tutorial on creating your own paint program:
http://delphi.wikia.com/wiki/Create_Your_Own_Paint_Program
there is no such easy thing as just drawing.
only if it's on a bitmap
so you need to convert the source (when it's not bitmap into bitmap)
and for saving convert it back to the source format
here's a tutorial on creating your own paint program:
http://delphi.wikia.com/wiki/Create_Your_Own_Paint_Program
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
if SavePictureDialog1.Execute
{ first check if file exists }
if FileExists(SavePictureDial
{ if it exists, raise an exception }
raise Exception.Create('File already exists. Cannot overwrite.')
else
{ otherwise, save the image data into the file }
Image1.Picture.SaveToFile(