このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


正確な Pixel Plotting
HOME - - - - - Lazarus Tutorials TOC - - - - - - Other 構成要素 for programmers
Delicious.Com Bookmark this on Delicious     StumbleUpon.Com Recommend to StumbleUpon

製図/抽選 in Lazarus or Delphi

Getting it 正確に/まさに 権利

とじ込み/提出する: PixelProblem.htm

I've been doing tutorials on 製図/抽選 pixels, lines, etc for more than thirty years. And often getting it わずかに wrong.

In this, I will try again to get it (正確に/まさに) 権利. Sigh.

要約....

How would you draw....?

-

You don't have to draw the yellow lines. Inside each yellow square is a 選び出す/独身 pixel. You don't have to draw the gray squares... they 代表する the form on which your graphic 陳列する,発揮するd. The white squares (pixels) ARE part of what you have to draw.

存在 only 5 pixels across, it will be very tiny on most 審査するs today. You can use the 基準 Windows "Magnifier" to magnify your 創造, to make sure it is what has been requested. (XP: The "Magnifier" 使用/適用 is in the start menu under All Programs/ 従犯者s/ Accessibility. 勝利,勝つ 7: All Programs/ 従犯者s/ 緩和する Of 接近.)

Good luck! I've been programming with moveto, lineto, rectangle, fillrect since before Windows... and still managed to have trouble while 令状ing this. But it isn't unreliable. I'm just, perhaps, easily 混乱させるd? Maybe you too?

Below, I show you the heart of the code to do the diagram with Lazarus. I believe that the same code would work with Delphi. Then I discuss the code.

(Don't try to use the に引き続いて just yet. There are a few things you need before it will work... but, 恐れる not, they are given to you just before the next bit of code.)

iImageWidth:=5; //Not 4, not 6
iImageHeight:=5;

Image1.width:=iImageWidth;
Image1.高さ:=iImageHeight;

//Next two 決定する background color. Delphi bitmaps default to white, Lazarus to 黒人/ボイコット.

Bitmap.canvas.pen.color:=clWhite;
Bitmap.canvas.Rectangle
  (0,0,iImageWidth,iImageHeight);
//公式文書,認める rectangle dimensions: "5,5" fills TO, (除外するing
//  the 独房 identified by "5,5". If the image was
//  始める,決める up with WIDTH 5, the IDENTIFIER of the
//  lower 権利 手渡す 独房 is "4,4", because the
//  upper left 手渡す 独房 is "0,0"

Image1.Picture.Graphic:=Bitmap; //割り当てる the bitmap
  //to the image 構成要素 The size of the image
  //seems to adjust to the size of the bitmap 割り当てるd
  //to it, at least if you use the default 所有物/資産/財産s
  //for Image1, which 含む 提携させる= alNone,
  //AutoSize= 誤った, Stretch= 誤った.
  //I'm not やめる sure why Autosize doesn't need
  //to be "true"... it may relate to something else.

//So far, we've created a white 製図/抽選 surface, 5x5
//Now 実験(する), 増強する what we've seen...
//Remember: iImageHeight and Width are 5.

//N.B.: Once the bitmap has been 割り当てるd to
//  Image1, you can no longer draw 直接/まっすぐに to
//  the bitmap, as we did to 設立する the background
//  color, but must use Image1.Picture.Bitmap.canvas....

//Draw a filled rectangle in the 中心 of the
//  製図/抽選 area... leaving a 1 pixel 国境 of
//  white pixels.
//公式文書,認める we have changed to using FillRect
//  and setting the BRUSH (not pen) color...
Image1.Picture.Bitmap.canvas.小衝突.color:=clLime;
Image1.Picture.Bitmap.canvas.FillRect
    (1,1,iImageWidth-1,iImageHeight-1);

//証明する that the pixel we THINK is 0,0 IS 0,0
Image1.Picture.Bitmap.canvas.pixels[0,0]:=clRed;

//Draw a line, in the central part
//  of the 製図/抽選 area. 公式文書,認める we are 支援する to
//  using the pen 所有物/資産/財産. First: choose color...
Image1.Picture.Bitmap.canvas.pen.color:=clBlack;

//Continue with 製図/抽選 line...
//A diagonal from NEAR upper 権利 to
//   NEAR lower left. Remember that lineTO
//   does not color in the last pixel, but
//   DOES color in the pixel the line starts
//   from. (Our line will leave one white
//   pixel 不変の at the 辛勝する/優位 of the image.

Image1.Picture.Bitmap.canvas.moveto
    (iImageWidth-2,1);

Image1.Picture.Bitmap.canvas.lineto
    (0,iImageHeight-1);

I have been using MoveTo and LineTo for perhaps 30 years... and using them incorrectly, as often as not. They were part of Borland's Turbo Pascal, in the good old days "BW" (Before Windows)

I have been 令状ing Delphi programs and tutorials for a long time. First in my teaching in the 1980s, and for やめる some time on the internet.

And now the 最新の 子孫 of Turbo Pascal also has MoveTo and LineTo, And, にもかかわらず trying VERY HARD to, finally, get it 権利... there were still errors in the 早期に 草案s of a new tutorial, May 2014.

So in this essay, I am going to try to give you some Basic Facts. With them, I hope you will be able to 避ける making the mistakes I so often 落ちる into. And I must crave the indulgence of people using all of my tutorials... please take the contents of any tutorial with a 穀物 of salt. Please 適用する what you can know from the examples I am about to 現在の, and use them to 訂正する errors in the use of MoveTo and LineTo you may come across in my tutorials. (If you are feeling 肉親,親類d, 警報 me to errors which are still in them? Spare the next reader the hassles?)

The errors are almost always of the "off by one" variety. I may, for instance, say such and such will make a line 5 pixels long... when it fact it makes a line six pixels long. Or maybe 4.

In many 事例/患者s, it "doesn't 事柄"... in any すぐに obvious way. But, I 約束 you, 存在 sloppy, 受託するing "の近くに enough", will very, very often come 支援する to give you far more grief in the long run than just getting something RIGHT in the first place would ever have cost you.


So.

Moving on.

Before I go into "十分な lecture 方式", here's a little diagram which, I hope, mostly "explains itself"....

-

If you understand さまざまな other things, you'll know that the green "line" (all two pixels of it!) in the above could be drawn with....

moveto(1,1);
lineto(3,1);

公式文書,認める the 調整するs carefully. The white squares 代表する the bitmap we are 製図/抽選 on. The green dots around the 辛勝する/優位 of pixel 3,1 are meant to draw your attention to the fact that the "lineto(3,1) 命令(する) did NOT change the color of pixel 3,1.

I 港/避難所't really "explained" all of that. It was a "要約" 声明 of some useful (警察などへの)密告,告訴(状). If questions 固執する, read on!....



First some "paper" to "draw" on...

In Lazarus, which is very 類似の to Delphi in this regard, here's what I do when I want to 陰謀(を企てる) points, draw lines, etc.

FIRST....

1) Put a TImage type 構成要素 on the 使用/適用's from,
2) Create a bitmap,
3) 割り当てる the bitmap to the TImage 構成要素.

THEN.... you will be able to use the に引き続いて code.

In many 事例/患者s, you do these things once, during the handler for the FormCreate event. Viz, in a 天然のまま form....

   Image1.width:=30;
   Image1.高さ:=20;

   Bitmap:=TBitmap.create;
   Bitmap.width:=30;
   Bitmap.高さ:=20;
   Image1.Picture.Graphic:=Bitmap;

The above will work if you have....

a) Used the IDE to place a TImage 構成要素 on the 使用/適用's main form, and called the 構成要素 Image1, and

b) 宣言するd a variable called Bitmap of type TBitmap. (This is "unremarkable". You do it the same way that you will 宣言する variables called iImageWidth and iImageHeight, type integer, in a little bit.... but I draw attention to it, as you may not have used a TBitmap variable 以前, or you might think that the "TBitmap.create" somehow takes care of the variable 宣言.)

Up in the type 宣言 for your form's class, in "public" or "私的な"....

   Bitmap:TBitmap;

-----
The code shown will work, but is isn't very clever to do the 職業 so crudely.

Doing it better

宣言する two その上の variables, iImageWidth, iImageHeight, and 改訂する our previous code to....

   iImagewidth:=30;
   iImageHeight:=20;

   Image1.width:=iImagewidth;
   Image1.高さ:=iImageHeight;

   Bitmap:=TBitmap.create;

   Bitmap.width:=iImagewidth;
   Bitmap.高さ:=iImageHeight;

   Bitmap.canvas.pen.color:=clWhite;//1 of 2
   Bitmap.canvas.Rectangle
       (0,0,iImagewidth,iImageHeight);//2 of 2

   Image1.Picture.Graphic:=Bitmap;

Besides using variables for the things we 以前 hardcoded as 30 and 20, I've 追加するd the "of 2" lines. More on them in a moment.

Doing things thus... putting things you'll 言及する to over and over into variables... is enormously useful if you decide to change a dimension. Even if you don't ever want to change a dimesion, it makes 生成するing 訂正する sourcecode easier. For one thing, un-noticed typo will get caught. Type 40 where you 手配中の,お尋ね者 30, and the program will run, but the results probably won't be what you 手配中の,お尋ね者. Type iImgeHeight for iImageHeight and the compiler will help you by 拒絶するing it.

Now a word about the lines 示すd "1 of 2" and "2 of 2": If you want to draw on a white background, these two lines are not needed in Delphi. They are 要求するd in Lazarus. (It defaults to a 黒人/ボイコット 製図/抽選 surface.) The parameters of Rectangle 明示する where it is to be drawn as follows: The first two numbers are the X and Y of the upper left corner of the rectangle. The second pair of numbers give... almost... the 調整するs of the diagonally opposite corner.

===

The 権利 values for the parameters of the Rectangle 命令(する) bring us to the area where I've made mistakes many times.

I have not made a mistake is in 説 that the upper, left 手渡す, pixel is at position 0,0, as far as Turbo Pascal, Delphi, and Lazarus are 関心d.

It is at the other end of both axes that things get tricky.

We're going to look at a somewhat smaller Image1 for a bit, to settle, once and for all, I hope, some of the 詳細(に述べる)s.

We're going to be using...

   iImagewidth:=5;
   iImageHeight:=5;

   Image1.width:=iImagewidth;
   Image1.高さ:=iImageHeight;

   Bitmap:=TBitmap.create;

   Bitmap.width:=iImagewidth;
   Bitmap.高さ:=iImageHeight;

   Bitmap.canvas.pen.color:=clGreen;//1 of 2
   Bitmap.canvas.Rectangle
       (0,0,iImagewidth,iImageHeight);//2 of 2

   Image1.Picture.Graphic:=Bitmap;

Run that, and you should see a very small green square, with its upper left corner wherever you had the upper left corner of the TImage 構成要素 you placed on the form.

This makes a 確かな 量 of sense, I hope.

What happens if, using Lazarus, you make the second two numbers of the Rectangle 声明 one smaller?....

  Bitmap.canvas.Rectangle
    (0,0,iImagewidth-1,iImageHeight-1);//2 of 2

The above gives rise to a 5x5 製図/抽選 area, too.. but this time the 権利 手渡す 辛勝する/優位 and the 底(に届く) 辛勝する/優位, to a depth of one pixel, have remained 黒人/ボイコット if you're using Lazarus, white if you're using Delphi. They weren't under the green rectangle. The green only went out to the 4th pixel.

So we can see, if I have, for once, 解釈する/通訳するd that 正確に, that on a 製図/抽選 area which is 5x5 pixels, invoking Rectangle 0,0,5,5 is just 権利 to change the color of all the pixels.

If, still on a 5x5 bitmap, we do Rectangle(0,0,4,4). we have two 辛勝する/優位s with not-colored pixels: 確定/確認 of what I said a moment ago about 0,0,5,5 存在 "just 権利".

(Remember the 基準 Windows helper 使用/適用 called "Magnifier" which I について言及するd earlier. It can be a big help in checking, in 詳細(に述べる), what your code does after whatever tweaks you make.)

What happens with (0,0,5,5) and (0,0,4,4) may seem "obvious", but things aren't as simple as they seem. Consider the results of the next 実験s....

What happens if we use numbers that are too big? If we draw "outside" the bitmap?

I tried (0,0,6,6) to find out. No problem. Even (-1,-1,6,6) "worked".... there doesn't seem to be a problem if you try to draw "outside" the bitmap.

=== Cast your mind 支援する to the "just 権利" numbers.

For a 5x5 bitmap, the "just 権利" numbers are (0,0,5,5).

But wait a moment... look at this diagram....


-

The upper left 手渡す corner is "0,0". Do you see what's "wrong" with 0,0,5,5 存在 the "権利" numbers to cover the 製図/抽選 area? Pixel 5,5 is NOT the pixel at the lower 権利. The "指名する" for the pixel at the lower 権利 is 4,4... because we started counting from 0, not from the 1 that we use in everyday things.

So when we say "do a rectangle", "from 0,0 ", "to 5,5", we 現実に mean "to" やめる literally. "To BUT NOT INCLUDING". But the for the first corner of the rectangle (0,0) the pixel we have 明示するd will be colored. Sigh. First corner included. Second corner (and 列/漕ぐ/騒動 and column it is part of excluded.

There's probably a 推論する/理由 for this, but I 収容する/認める that it escapes me. There ARE 推論する/理由s for "counting from 無". I understand them.

The "含む first 明示するd pixel, 除外する last" 支配する also 適用するs to the moveto/ lineto 手続きs.

If you say....

moveto(0,0);
lineto(3,3);

... then you will get a very short line indeed. Only the に引き続いて pixels will have been colored in...

0,0
1,1
2,2

公式文書,認める... 特に: Pixel 3,3 will NOT be colored. When we said lineto(3,3), we meant color in the pixel along that line UP TO, but NOT INCLUDING, the pixel at 3,3.

Happily, this is at least 一貫した with what we saw in the 事柄 of the Rectangle 手続き earlier.


So... as I said... I hope I have these things 権利 finally. いつかs, though it is not wise, you can get away with 存在 a little bit sloppy in these 事柄s... but I'd advise against that.

Even in 令状ing this very simple 公式文書,認める, while concentrating only on the 問題/発行するs raised in it, I made mistakes about which 独房s would colored, which would not.

Sigh.

Finally...

The "pixels" 命令(する) should probably get a について言及する here before we end. This code...

Image1.canvas.pixels[0,0]:=clBlue;

... will make the pixel in the upper left 手渡す corner of the 製図/抽選 area blue.

Image1.canvas.pixels[0,2]:=clBlue;

... will make the pixel on the left 手渡す 辛勝する/優位 of the 製図/抽選 surface blue. The blue pixel will be the THIRD one 負かす/撃墜する from the 最高の,を越す, because we count from 無. Or, to put it another way, the "演説(する)/住所s" of the pixels start at 無.





Search across all my 場所/位置s with the Google search...

Custom Search
            力/強力にするd by FreeFind
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search This search 単に looks for the words you enter. It won't answer "Where can I download InpOut32?"
広告 from page's editor: Yes.. I do enjoy 収集するing these things for you. I hope they are helpful. However... this doesn't 支払う/賃金 my 法案s!!! Sheepdog ソフトウェア (tm) is supposed to help do that, so if you 設立する this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and 循環させる it for me? Links on your page to this page would also be 高く評価する/(相場などが)上がるd!
Click here to visit editor's freeware, shareware page.

Link to Lazarus Tutorials main page
How to 接触する the editor of this page, Tom Boyd


Please consider 与える/捧げるing to the author of this 場所/位置... and if you don't want to do that, at least check out his introduction to the new micro-寄付s system Flattr.htm....



Valid HTML 4.01 Transitional Page 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes. There were two "unknown せいにするs" in Google+ button code. Sigh.


If this page 原因(となる)s a script to run, why? Because of things like Google パネル盤s, and the code for the search button. Why do I について言及する scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....