- PR -

Graphics.PageUnit=Displayの場合の単位はほんとに1/75インチ?

1
投稿者投稿内容
ジブ
大ベテラン
会議室デビュー日: 2005/09/22
投稿数: 135
投稿日時: 2005-10-25 21:02
PrintDocumentを使用して印刷していますが不可解な現象に遭遇したのでお知恵をお貸しください。

Graphics.PageUnit=Displayである状態で
DrawRectangle(Pens.Black,10,10,75,75)とやると一辺が1インチの正方形が描けるはずですよね?
1/75(インチ/単位) * 75(単位) = 1インチですよね?

ところが実際には3/4インチの正方形が印刷されます。

DrawRectangle(Pens.Black,10,10,100,100)とやると一辺が1インチの正方形になります。

私はなにか大きな勘違いをしているのでしょうか?
ジブ
大ベテラン
会議室デビュー日: 2005/09/22
投稿数: 135
投稿日時: 2005-10-26 12:10
Graphics.PageUnit=Displayの場合の単位は1/75インチなんかじゃありません。

ディスプレイとプリンタで検証しました。
ディスプレイの場合はピクセルが単位となり
プリンターの場合は1/100インチが単位となっています。
(VB.net2003です)

以下検証コードです。

フォームにPrintDocumentとPictureBoxをはりつけて

コード:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
With e.Graphics
.PageUnit = GraphicsUnit.Point
.DrawRectangle(Pens.Black, 0, 0, 72, 72)
.PageUnit = GraphicsUnit.Display
.DrawRectangle(Pens.Black, 0, 100, 100, 100)
.PageUnit = GraphicsUnit.Millimeter
.DrawRectangle(Pens.Black, 0, 25.4F * 2, 25.4F, 25.4F)
.PageUnit = GraphicsUnit.Pixel
.DrawRectangle(Pens.Black, 0, .DpiY * 3, .DpiX, .DpiY)
End With
e.HasMorePages = False

End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
With e.Graphics
.PageUnit = GraphicsUnit.Point
.DrawRectangle(Pens.Black, 0, 0, 72, 72)
.PageUnit = GraphicsUnit.Display
.DrawRectangle(Pens.Black, 0, .DpiY, .DpiX, .DpiY)
.PageUnit = GraphicsUnit.Millimeter
.DrawRectangle(Pens.Black, 0, 25.4F * 2, 25.4F, 25.4F)
.PageUnit = GraphicsUnit.Pixel
.DrawRectangle(Pens.Black, 0, .DpiY * 3, .DpiX, .DpiY)
End With

End Sub




[ メッセージ編集済み 編集者: ジブ 編集日時 2005-10-26 12:19 ]

[ メッセージ編集済み 編集者: ジブ 編集日時 2005-10-26 12:21 ]
Kazuki
ぬし
会議室デビュー日: 2004/10/13
投稿数: 298
投稿日時: 2005-10-26 12:24
そこらへんの詳しい情報は
http://www.microsoft.com/japan/msdn/net/books/ProgWinCsharp/default.asp
にのってたと思います。

# 前読んだけど忘れてしまった…
Hongliang
ぬし
会議室デビュー日: 2004/12/25
投稿数: 576
投稿日時: 2005-10-26 13:18
ちなみに、.NET 2.0のリファレンスではDisplayの解説にしっかり
引用:

Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers.


と書かれてたり。
ジブ
大ベテラン
会議室デビュー日: 2005/09/22
投稿数: 135
投稿日時: 2005-10-26 13:49
引用:

Hongliangさんの書き込み (2005-10-26 13:18) より:
ちなみに、.NET 2.0のリファレンスではDisplayの解説にしっかり
引用:

Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers.


と書かれてたり。



あ、ほんとだ、直ってる。

なんでこっちのほうは直さないんだろう?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdrawinggraphicsunitclasstopic.asp

Hongliangさん、ありがとうございました。
1

スキルアップ/キャリアアップ(JOB@IT)