PC Review


Reply
Thread Tools Rate Thread

Drawing using NearestNeighbor

 
 
Lance
Guest
Posts: n/a
 
      16th Dec 2003
How do you enable
Graphics.InterpolationMode.NearestNeighbor? When I use
the following code it does not work (i.e., the image
appears to have been drawn using linear interpolation):

Const scale As Single = 10
Dim b As New Drawing.TextureBrush(MyBitmap)
Dim g As Drawing.Graphics = MyPictureBox.CreateGraphics
g.InterpolationMode = InterpolationMode.NearestNeighbor
b.ScaleTransform(scale, scale)
'I've also tried to scale g, but that doesn't work either
'i.e., g.ScaleTransform(scale, scale)
g.FillRectangle(b, MyPictureBox.ClientRectangle)

Thanks,
Lance


 
Reply With Quote
 
 
 
 
Peter Huang
Guest
Posts: n/a
 
      17th Dec 2003
Hi Lance,

I think you may need to scale the image first before your create the brush.

Private bmp As Bitmap
Private b As TextureBrush
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim MyBitmap As New Bitmap("c:\test.bmp")
Const scale As Single = 2
bmp = GetScaledImage(MyBitmap, scale)
b = New Drawing.TextureBrush(bmp)
Me.Size = New Size(MyBitmap.Width * scale, MyBitmap.Height * scale)
End Sub
Private Function GetScaledImage(ByVal srcbmp As Bitmap, ByVal scale As
Single) As Bitmap
Dim bm As New Bitmap(srcbmp.Width * scale, srcbmp.Height * scale,
Imaging.PixelFormat.Format24bppRgb)
Dim g As Graphics
g = Graphics.FromImage(bm)
g.ScaleTransform(scale, scale)
g.InterpolationMode = InterpolationMode.Bilinear
g.DrawImage(srcbmp, 0, 0)
g.Dispose()
Return bm
End Function

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.FillRectangle(b, New Rectangle(New Point(0, 0),
Me.ClientSize))
End Sub

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
Lance
Guest
Posts: n/a
 
      17th Dec 2003
Thanks for the help. I think there must be another way
though. Lets say that a user is viewing a 1600x1200 image
and they zoom in on the image to 100x. So now I have to
create a 160000x120000 image in order for the image to be
displayed as NearestNeighbor?


>-----Original Message-----
>Hi Lance,
>
>I think you may need to scale the image first before your

create the brush.
>
> Private bmp As Bitmap
> Private b As TextureBrush
> Private Sub Form1_Load(ByVal sender As System.Object,

ByVal e As
>System.EventArgs) Handles MyBase.Load
> Dim MyBitmap As New Bitmap("c:\test.bmp")
> Const scale As Single = 2
> bmp = GetScaledImage(MyBitmap, scale)
> b = New Drawing.TextureBrush(bmp)
> Me.Size = New Size(MyBitmap.Width * scale,

MyBitmap.Height * scale)
> End Sub
> Private Function GetScaledImage(ByVal srcbmp As

Bitmap, ByVal scale As
>Single) As Bitmap
> Dim bm As New Bitmap(srcbmp.Width * scale,

srcbmp.Height * scale,
>Imaging.PixelFormat.Format24bppRgb)
> Dim g As Graphics
> g = Graphics.FromImage(bm)
> g.ScaleTransform(scale, scale)
> g.InterpolationMode = InterpolationMode.Bilinear
> g.DrawImage(srcbmp, 0, 0)
> g.Dispose()
> Return bm
> End Function
>
> Private Sub Form1_Paint(ByVal sender As Object, ByVal

e As
>System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
> e.Graphics.FillRectangle(b, New Rectangle(New

Point(0, 0),
>Me.ClientSize))
> End Sub
>
>If you have any concern on this issue, please post here.
>
>Regards,
>Peter Huang
>Microsoft Online Partner Support
>Get Secure! www.microsoft.com/security
>This posting is provided "as is" with no warranties and

confers no rights.
>
>.
>

 
Reply With Quote
 
Peter Huang
Guest
Posts: n/a
 
      18th Dec 2003
Hi Lance,

If you just need to display an image, you may try to use the drawimage
method of Graphics object.

Using Interpolation Mode to Control Image Quality During Scaling
http://msdn.microsoft.com/library/de...us/gdicpp/GDIP
lus/UsingGDIPlus/UsingImagesBitmapsandMetafiles/UsingInterpolationModetoCont
rolImageQualityDuringScaling.asp

Based on my research and test on my side, when using the FillRectangle
method, Graphics object will not care the InterpolationMode setting.

Can you tell me why you need to create an textureBrush with a large bitmap,
maybe there will be a better solution?
e.g. you can create the bitmap with less scale and set the Graphics with
more scale.

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing Custom Shape Using PowerPoint Drawing Tool Mosfiqur Rahman Microsoft Powerpoint 0 6th Jul 2008 01:06 PM
exporting drawing created in PowerPoint in Word as a drawing amit Microsoft Powerpoint 4 16th Mar 2008 04:19 AM
System.Drawing For Drawing Text Images jjbutera@hotmail.com Microsoft ASP .NET 1 9th Jan 2006 09:55 PM
Drawing tool bar and drawing canvas tools are dimmed with new pag. =?Utf-8?B?Sm9obk1j?= Microsoft Frontpage 3 19th Jan 2005 04:11 PM
Drawing tool bar and drawing canvas tools are dimmed with new pag. =?Utf-8?B?am1jY2FkYW1z?= Microsoft Frontpage 2 19th Jan 2005 02:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:20 AM.