Recent

Author Topic: Resizing a TImage.Canvas  (Read 11070 times)

cov

  • Full Member
  • ***
  • Posts: 241
Resizing a TImage.Canvas
« on: April 26, 2013, 09:33:37 am »
I've got a TImage component on a form.

The form is 500x500 and the TImage component is 480x500 and it's anchored [akTop, akLeft, akRight, akBottom]

In the Form.Resize procedure I have
Code: [Select]
  Image1.Canvas.Brush.Color:=clBlack;
  Image1.Canvas.FillRect(0,0,Image1.Width,Image1.Height);

I'm expecting the TImage to be painted black when the form is resized.

However, if the form is maximised, only a rectangle on the top left 480x500 is painted black.

What do I need to do to ensure that this behaves as expected?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Resizing a TImage.Canvas
« Reply #1 on: April 26, 2013, 09:38:27 am »
TImage is something like a proxy to various image formats. The TImage.canvas is linked to a TBitmap which holds the image in memory, you need to resize that bitmap using image1.Picture.Bitmap.SetSize to change the drawing surface.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Resizing a TImage.Canvas
« Reply #2 on: April 26, 2013, 09:43:07 am »
Thank you very much for informations, taazz,  I had the same problem.
Regards.
« Last Edit: April 26, 2013, 09:46:09 am by exdatis »

cov

  • Full Member
  • ***
  • Posts: 241
Re: Resizing a TImage.Canvas
« Reply #3 on: April 26, 2013, 10:18:51 am »
Yes, thanks for the response. Worked a treat! :)

If TImage is a wrapper for Bitmap formats then I'm probably wasting it by using it to draw a vector image.

What component would be more appropriate?
« Last Edit: April 26, 2013, 10:27:30 am by cov »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Resizing a TImage.Canvas
« Reply #4 on: April 26, 2013, 10:37:27 am »
That's a good question. There are many alternatives and the correct answer depends heavily on what abilities you need that component to have. for example do you require scrolling resizing zooming to be able to edit the vector nodes with the mouse etc. How about speed and memory use? If it is a one of draw with scrolling then creating a memory bitmap and drawing the vector once when loaded will be faster than redrawing it every time something changes so an image with autosize set to true inside a scrollbox will probably be best resizing the bitmap to a smaller size should be fairly easy as well but  editting the nodes is probably out of the question. If you need editing capabilities like inkscape for example then a custom control that manages a list of predefined shapes and lines is the best course of action. Of course if you go to a custom control you need to think if you are going to support multiple widgetsets or not. As you can see it is not an easy answer.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

cov

  • Full Member
  • ***
  • Posts: 241
Re: Resizing a TImage.Canvas
« Reply #5 on: April 26, 2013, 11:37:11 am »
No, just to display a vector file.

I need zoom and pan so that the contents of the vector file can be examined. Don't even need scroll boxes.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Resizing a TImage.Canvas
« Reply #6 on: April 26, 2013, 11:53:18 am »
pan = scroll, as for zoom you can always set the image.width, image.height to what ever you want and set the image.proportional and image.stretch to true to have the bitmap resized.
Just use a TImage inside a TScrollbox to accomplish the pan feature and the image width,  height and stretch properties to implement the zooming. Of course you should use the image.picture.bitmap as the drawing surface of the vector giving it the fulle size of the vector and not only what the image can show.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Resizing a TImage.Canvas
« Reply #7 on: April 26, 2013, 01:44:23 pm »
taazz
In general, the overall size of the drawing can be very large and contain lot fine detail.
If the scale of the overall and scale fine details are different in a lot of times, the bitmap scaling gives poor results.
The easiest way - full redraw vector data for zoom and pan
« Last Edit: April 26, 2013, 01:46:27 pm by zamtmn »

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Resizing a TImage.Canvas
« Reply #8 on: April 26, 2013, 01:56:58 pm »
I am very happy, this is an increase of 300% :)
Regards

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Resizing a TImage.Canvas
« Reply #9 on: April 26, 2013, 01:59:34 pm »
True, as I said it all depends on the OP needs but the fastest way to show a vector drawing is the one I described. For anything else there is a tone of work to be done including internal data types, lists, algorithms etc. That can not be covered in a thread post.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Resizing a TImage.Canvas
« Reply #10 on: April 26, 2013, 02:02:24 pm »
I agree with you.

zamtmn

  • Hero Member
  • *****
  • Posts: 594
Re: Resizing a TImage.Canvas
« Reply #11 on: April 26, 2013, 07:36:06 pm »
cov
Try zсad http://sourceforge.net/projects/zcad/, there is a simple example of viewing DXF files (folder "simplecad" in sources) with zoom and pan autocad like http://a.fsdn.com/con/app/proj/zcad/screenshots/screen.PNG
« Last Edit: April 26, 2013, 07:39:59 pm by zamtmn »

cov

  • Full Member
  • ***
  • Posts: 241
Re: Resizing a TImage.Canvas
« Reply #12 on: April 27, 2013, 08:20:33 am »
taazz
In general, the overall size of the drawing can be very large and contain lot fine detail.
If the scale of the overall and scale fine details are different in a lot of times, the bitmap scaling gives poor results.
The easiest way - full redraw vector data for zoom and pan

Yes, that's what I'm doing.

The reading of the Vector file and rendering to the TCanvas is very quick (at least on modern machines), so if I'm zooming in to the fine detail, then that's the way I'll go.

 

TinyPortal © 2005-2018