Groups | Blog | Home
all groups > dotnet drawing api > october 2003 >

dotnet drawing api : Copying part of image to itself


Benjamin Lukner
10/30/2003 12:16:44 PM
Hi!

I've build a control that bases on the Signature Capture Sample from
Microsoft(load bitmap, print on bitmap, paint on control). Works pretty
fine.

But now I want to copy a part of the displayed image to itself at
another position. For example: Bitmap is ca. 100x100. I printed text on
it at the upper left corner (for testing). Now I want to copy the text
(or whatever has been printed there) to the lower left corner.

Following the code parts from my project.
EVERYTHING works but the "copy" command at the bottom of the code.
But there is no error raised.
So: What do I do wrong?

Maybe someone's got a hint for me :-)

Kind regards,

Benjamin Lukner

'----------------------------

Class MyScreen

Inherits Control

Private _bmp As System.Drawing.Bitmap
Private _graphics As System.Drawing.Graphics

' Load image from resource file embedded in project
Public Sub New()
_bmp = New Bitmap( _
System.Reflection.Assembly.GetExecutingAssembly(). _
GetManifestResourceStream( _
System.Reflection.Assembly.GetExecutingAssembly.GetName.Name + _
"." + "tcscreen.png"))

' Creating graphics object from image
_graphics = Graphics.FromImage(_bmp)

_graphics.DrawString("Test!", _
New System.Drawing.Font("Courier New", 10, FontStyle.Regular), _
New System.Drawing.SolidBrush(System.Drawing.Color.Red), 1, 1)
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

'START new part for copying

Dim oRect As New System.Drawing.Rectangle
oRect.FromLTRB(1, 1, 100, 50)
_graphics.DrawImage(_bmp, 1, 51, oRect, GraphicsUnit.Pixel)

'END new part for copying

e.Graphics.DrawImage(_bmp, 0, 0)

End Sub

End Class
Bob Powell [MVP]
10/30/2003 1:51:37 PM
You can't copy an image from itself to itself. You'll have to copy it to a
temporary bitmap first and then copy it back to itself again.

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Benjamin Lukner" <Benjamin.Lukner_at_trinomix.de@mp3mounter.de> wrote in
message news:%23OIUsctnDHA.2432@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

Benjamin Lukner
10/30/2003 2:59:17 PM
[quoted text, click to view]

I'm sorry, but I can't manage it...
I'm quite new to the compact framework so I'm afraid I need another hint...

I changed my code, but no errors and no effect...
I seem to do it completely wrong:

' Moving 100x50 pixels from the upper left corner 100 pixels down
Dim oRect As New System.Drawing.Rectangle
oRect.FromLTRB(0, 0, 99, 49)

Dim _bmpCache As New System.Drawing.Bitmap(100, 50)
Dim _graphicsCache As System.Drawing.Graphics =
Graphics.FromImage(_bmpCache)

_graphicsCache.DrawImage(_bmp, 0, 0, oRect, GraphicsUnit.Pixel)
_graphics.DrawImage(_bmpCache, 0, 100, oRect, GraphicsUnit.Pixel)


Kind regards,

Benjamin Lukner
Bob Powell [MVP]
10/30/2003 7:28:38 PM
Try this...

' Moving 100x50 pixels from the upper left corner 100 pixels down
Dim oRect As New System.Drawing.Rectangle
oRect.FromLTRB(0, 0, 99, 49)

Dim _bmpCache As New System.Drawing.Bitmap(100, 50)
Dim _graphicsCache As System.Drawing.Graphics =
Graphics.FromImage(_bmpCache)

_graphicsCache.DrawImage(_bmp, 0, 0, oRect, GraphicsUnit.Pixel)

_graphicsCache.Dispose()
_graphicsCache=Graphics.FromImage(_bmp)

_graphics.DrawImage(_bmpCache, 0, 100, oRect, GraphicsUnit.Pixel)

_graphicsCache.Dispose()

--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

"Benjamin Lukner" <Benjamin.Lukner_at_trinomix.de@mp3mounter.de> wrote in
message news:ujQdh3unDHA.424@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

Benjamin Lukner
10/31/2003 10:49:02 AM
[quoted text, click to view]

ARRRGGGHH!!!
I've found the error...

oRect = oRect.FromLTRB(0, 0, 99, 49)

AND:
I don't know why, but copying an image DIRECTLY on itself WORKS on
compact framework:

Dim oRect As New System.Drawing.Rectangle
oRect = oRect.FromLTRB(0, 0, 99, 49)
_graphics.DrawImage(_bmp, 0, 50, oRect, GraphicsUnit.Pixel)
Invalidate()

It DOESN'T work with normal VB.Net 2003.

Very very curious....

P.S.: Thanks for the support! :-)


So long,

Benjamin Lukner
AddThis Social Bookmark Button