Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TOleGraphic shrinks images width height with ~10%

Status
Not open for further replies.

HelpMEDude

Programmer
Feb 27, 2005
21
SE
Hello, once again, for those who remember me ^^!

I've tried to make a procedure that simply loads any frequently used image type (jpg, gif etc.) and then converts it to a 24 or 8-bit bmp-file.

I decided that OLE was a good solution for this, since it's built-in in Delphi and all...

I'd wrote this code, inspired from the delphitricks website:

Code:
procedure ImageToBmp(Source :Tfilename; Destination :Tfilename; format :TPixelformat ;Forcewidth:integer; ForceHeight:integer);
var
  OleGraphic: TOleGraphic;
  fs: TFileStream;
  BM    : Tbitmap;
begin
  try
    OleGraphic := TOleGraphic.Create;
    fs         := TFileStream.Create(Source, fmOpenRead or fmSharedenyNone);
    OleGraphic.LoadFromStream(fs);
    bm:=Tbitmap.Create;
    Bm.PixelFormat := format;
    if  (Forcewidth=0) and (ForceHeight=0) then begin
    bm.Height:= OleGraphic.Height;
    bm.Width:= OleGraphic.Width;
    bm.Canvas.Draw(0,0,OleGraphic);
    end else begin
    Bm.Height := ForceHeight;
    Bm.Width := Forcewidth;
    bm.Canvas.StretchDraw(rect(point(0,0),point(Forcewidth,ForceHeight)),OleGraphic);
    end;
    bm.SaveToFile(Destination);
  finally
    bm.Free;
    fs.Free;
    OleGraphic.Free
  end;
end;

I saw somehow the output image was in wrong size, and when I debugged, I put a breakpoint at line bm.width:=etc. .I found out that the width and height are about 10 percent lower than the real dimensions of the image. It applies to both gif and bmp files I load (I have not tested other).

So reading images with TOleGraphic fails, if you guys know what the solution to this is, or other way to convert images to bmp 24 and 8-bit. Please help me.

I use Delphi 2005, in case of that will matter.

Thanks in advice :)
 
maybe its this
Width property (TOleGraphic)
Note: Width assumes the screen resolution, so arithmetic conversions may not be as accurate.

Aaron
 
That's true aaronjme, I see it when I load an image with a lower screen resolution, I did not know this, but how can I solve the problem then :eek: ?

Is the solution maybe that I must use the OleGraphic.picture.get_width?

If it is, how can I call the function get_width?, it seems to require an input integer, how does that make sense?. And when I input an random integer value then the compiler responds with this error message.

[Error] Unit1.pas(35): E2033 Types of actual and formal var parameters must be identical

Hmm... I must say I'm not at all experienced programmer, and I've never ever experienced any kind of these functions (the functions in OleGraphic.picture), which I instead find logical to be procedures or values.

The Olegraphic.picture.get_width is like this:

Code:
IPicture.get_Width(Integer@) Method 


Declared in ActiveX.IPicture


Parameters

width 
System.Integer 

Returns

System.Integer

Just that it wants an integer as parameter just don't make sense to me :(

As said I'm no experienced programmer, and seeing the word ActiveX in the declaration really scares me :x

Again, thanks in advice :)
 
if your only loading an image to resize and convert it why use TOleGraphic, TGraphic should do.

when i get a chance ill try and get you some code.

Aaron
 
Thanks again :)

I thought TOleGraphic is the one because other classes can't convert most image kinds, or have I misunderstood something ^^?

TGraphic is abstract, can I use it anyway?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top