Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

problem with TImage canvas

[b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
[b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.

However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.

The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).

Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?

many thanks





Comments

  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    :
    : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    :
    : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    :
    : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    :
    : many thanks
    :
    :
    You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
  • GarryPaxtonGarryPaxton Posts: 66Member
    : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    : :
    : : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    : :
    : : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    : :
    : : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    : :
    : : many thanks
    : :
    : :
    : You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    : If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
    :
    Thanks, I will investigate TPaintbox. However, I do need to load bitmaps so I might be compelled to use TImage.

    I do resize TImage before loading the next picture (Img1.width and height properties), and although the Timage does indeed incresse in size, the usable canvas within it just stays the same.
  • zibadianzibadian Posts: 6,349Member
    [b][red]This message was edited by zibadian at 2004-11-15 6:2:46[/red][/b][hr]
    : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : : : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    : : :
    : : : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    : : :
    : : : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    : : :
    : : : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    : : :
    : : : many thanks
    : : :
    : : :
    : : You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    : : If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
    : :
    : Thanks, I will investigate TPaintbox. However, I do need to load bitmaps so I might be compelled to use TImage.
    :
    : I do resize TImage before loading the next picture (Img1.width and height properties), and although the Timage does indeed incresse in size, the usable canvas within it just stays the same.
    :
    The Canvas itself doesn't have a real size. It should be the same size as the picture, which has been loaded. So if you first edit a 100x100 bitmap, and subsequently load a 200x200 bitmap, the canvas should also be 200x200.


  • GarryPaxtonGarryPaxton Posts: 66Member
    : [b][red]This message was edited by zibadian at 2004-11-15 6:2:46[/red][/b][hr]
    : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : : : : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    : : : :
    : : : : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    : : : :
    : : : : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    : : : :
    : : : : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    : : : :
    : : : : many thanks
    : : : :
    : : : :
    : : : You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    : : : If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
    : : :
    : : Thanks, I will investigate TPaintbox. However, I do need to load bitmaps so I might be compelled to use TImage.
    : :
    : : I do resize TImage before loading the next picture (Img1.width and height properties), and although the Timage does indeed incresse in size, the usable canvas within it just stays the same.
    : :
    : The Canvas itself doesn't have a real size. It should be the same size as the picture, which has been loaded. So if you first edit a 100x100 bitmap, and subsequently load a 200x200 bitmap, the canvas should also be 200x200.
    :
    :

    Hello, here is an example - drop a TImage on a form and manually set its dimensions to a height of 50, and a width of 50.

    Then try the following code (I placed this in a Button1 Click event)
    [code]
    Image1.canvas.brush.color:=clBlue;
    Image1.width:=1047;
    Image1.Height:=1047;
    Image1.canvas.fillrect(Rect(0,0,1047,1047));
    [/code]

    For me, all I see is a 50 x 50 blue square. It never changes size, no matter what dimensions I give it.
    Many thanks.
  • zibadianzibadian Posts: 6,349Member
    : : [b][red]This message was edited by zibadian at 2004-11-15 6:2:46[/red][/b][hr]
    : : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : : : : : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    : : : : :
    : : : : : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    : : : : :
    : : : : : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    : : : : :
    : : : : : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    : : : : :
    : : : : : many thanks
    : : : : :
    : : : : :
    : : : : You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    : : : : If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
    : : : :
    : : : Thanks, I will investigate TPaintbox. However, I do need to load bitmaps so I might be compelled to use TImage.
    : : :
    : : : I do resize TImage before loading the next picture (Img1.width and height properties), and although the Timage does indeed incresse in size, the usable canvas within it just stays the same.
    : : :
    : : The Canvas itself doesn't have a real size. It should be the same size as the picture, which has been loaded. So if you first edit a 100x100 bitmap, and subsequently load a 200x200 bitmap, the canvas should also be 200x200.
    : :
    : :
    :
    : Hello, here is an example - drop a TImage on a form and manually set its dimensions to a height of 50, and a width of 50.
    :
    : Then try the following code (I placed this in a Button1 Click event)
    : [code]
    : Image1.canvas.brush.color:=clBlue;
    : Image1.width:=1047;
    : Image1.Height:=1047;
    : Image1.canvas.fillrect(Rect(0,0,1047,1047));
    : [/code]
    :
    : For me, all I see is a 50 x 50 blue square. It never changes size, no matter what dimensions I give it.
    : Many thanks.
    :
    I have no idea why, but it works if you first set the Width and Height, then the Brush and then fill the rect; like this:
    [code]
    Image1.width:=1047;
    Image1.Height:=1047;
    Image1.canvas.brush.color:=clBlue;
    Image1.canvas.fillrect(Rect(0,0,1047,1047));
    [/code]
  • softmansoftman Posts: 157Member
    : : : [b][red]This message was edited by zibadian at 2004-11-15 6:2:46[/red][/b][hr]
    : : : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : : : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : : : : : : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    : : : : : :
    : : : : : : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    : : : : : :
    : : : : : : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    : : : : : :
    : : : : : : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    : : : : : :
    : : : : : : many thanks
    : : : : : :
    : : : : : :
    : : : : : You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    : : : : : If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
    : : : : :
    : : : : Thanks, I will investigate TPaintbox. However, I do need to load bitmaps so I might be compelled to use TImage.
    : : : :
    : : : : I do resize TImage before loading the next picture (Img1.width and height properties), and although the Timage does indeed incresse in size, the usable canvas within it just stays the same.
    : : : :
    : : : The Canvas itself doesn't have a real size. It should be the same size as the picture, which has been loaded. So if you first edit a 100x100 bitmap, and subsequently load a 200x200 bitmap, the canvas should also be 200x200.
    : : :
    : : :
    : :
    : : Hello, here is an example - drop a TImage on a form and manually set its dimensions to a height of 50, and a width of 50.
    : :
    : : Then try the following code (I placed this in a Button1 Click event)
    : : [code]
    : : Image1.canvas.brush.color:=clBlue;
    : : Image1.width:=1047;
    : : Image1.Height:=1047;
    : : Image1.canvas.fillrect(Rect(0,0,1047,1047));
    : : [/code]
    : :
    : : For me, all I see is a 50 x 50 blue square. It never changes size, no matter what dimensions I give it.
    : : Many thanks.
    : :
    : I have no idea why, but it works if you first set the Width and Height, then the Brush and then fill the rect; like this:
    : [code]
    : Image1.width:=1047;
    : Image1.Height:=1047;
    : Image1.canvas.brush.color:=clBlue;
    : Image1.canvas.fillrect(Rect(0,0,1047,1047));
    : [/code]
    :
    Hi!

    When TImage is created, the picture is nil. When you first invoke any canvas function, a picture.bitmap is created with the size of the TImage itself, where TImage will paint. If you resize the image, the bitmap will stay the same, unless you resize it programmatically:

    [code]
    Image1.canvas.brush.color:=clBlue;
    Image1.Picture.Bitmap.Width := 1047;
    Image1.Picture.Bitmap.Height := 1047;
    Image1.width:=1047;
    Image1.Height:=1047;
    Image1.canvas.fillrect(Rect(0,0,1047,1047));
    [/code]
    \///
    /O O
    | | |
    | _ |
    ___/
    SoftMan

  • GarryPaxtonGarryPaxton Posts: 66Member
    : : : : [b][red]This message was edited by zibadian at 2004-11-15 6:2:46[/red][/b][hr]
    : : : : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:33:43[/red][/b][hr]
    : : : : : : : [b][red]This message was edited by GarryPaxton at 2004-11-15 3:28:39[/red][/b][hr]
    : : : : : : : I have a TImage canvas onto which I draw a picture, using a variety of methods (loading a bitmap, flooding an drawing lines , etc). This is in Delphi 6.
    : : : : : : :
    : : : : : : : However, the pictures I create can be various sizes, but the canvas seems always to be cropped at the original size it had at design time. So, if I drop a TImage on the form of 100 x 100, and then try to fillrect at some larger size, like 200 x 200, the resulting image remains cropped to 100 x 100.
    : : : : : : :
    : : : : : : : The only way I can get round this is to set the TImage to be sized at design time to the largest possible picture size I ever intend to create. Unfortunately, if the TImage is larger than the desktop that causes a program interrupt (unless I make it Visible:=false, which kind of defeats the object).
    : : : : : : :
    : : : : : : : Is there something I am doing wrong ? Does TImage need to be "initialsed" prior to use, or somehow "invalidated" to allow it to be resized ?
    : : : : : : :
    : : : : : : : many thanks
    : : : : : : :
    : : : : : : :
    : : : : : : You can set the Width and Height of any control in code. Also the TImage supports stretching of images. You don't need to invalidate the control to resize it, Delphi takes care of this. You do however create a picture in it to directly write to the canvas.
    : : : : : : If you only want to directly write (and not load any image files) to the canvas you can better the TPaintBox. That control has its own canvas and doesn't need an image to be loaded into.
    : : : : : :
    : : : : : Thanks, I will investigate TPaintbox. However, I do need to load bitmaps so I might be compelled to use TImage.
    : : : : :
    : : : : : I do resize TImage before loading the next picture (Img1.width and height properties), and although the Timage does indeed incresse in size, the usable canvas within it just stays the same.
    : : : : :
    : : : : The Canvas itself doesn't have a real size. It should be the same size as the picture, which has been loaded. So if you first edit a 100x100 bitmap, and subsequently load a 200x200 bitmap, the canvas should also be 200x200.
    : : : :
    : : : :
    : : :
    : : : Hello, here is an example - drop a TImage on a form and manually set its dimensions to a height of 50, and a width of 50.
    : : :
    : : : Then try the following code (I placed this in a Button1 Click event)
    : : : [code]
    : : : Image1.canvas.brush.color:=clBlue;
    : : : Image1.width:=1047;
    : : : Image1.Height:=1047;
    : : : Image1.canvas.fillrect(Rect(0,0,1047,1047));
    : : : [/code]
    : : :
    : : : For me, all I see is a 50 x 50 blue square. It never changes size, no matter what dimensions I give it.
    : : : Many thanks.
    : : :
    : : I have no idea why, but it works if you first set the Width and Height, then the Brush and then fill the rect; like this:
    : : [code]
    : : Image1.width:=1047;
    : : Image1.Height:=1047;
    : : Image1.canvas.brush.color:=clBlue;
    : : Image1.canvas.fillrect(Rect(0,0,1047,1047));
    : : [/code]
    : :
    : Hi!
    :
    : When TImage is created, the picture is nil. When you first invoke any canvas function, a picture.bitmap is created with the size of the TImage itself, where TImage will paint. If you resize the image, the bitmap will stay the same, unless you resize it programmatically:
    :
    : [code]
    : Image1.canvas.brush.color:=clBlue;
    : Image1.Picture.Bitmap.Width := 1047;
    : Image1.Picture.Bitmap.Height := 1047;
    : Image1.width:=1047;
    : Image1.Height:=1047;
    : Image1.canvas.fillrect(Rect(0,0,1047,1047));
    : [/code]
    : \///
    : /O O
    : | | |
    : | _ |
    : ___/
    : SoftMan
    :
    :
    Hey that's fantastic - problem solved.
    many thanks
    Garry
Sign In or Register to comment.