[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Obtaining a portion of an image without loss of quality

Steve Bugden

10/13/2004 5:59:00 PM

Hello,

I'm trying to obtain a portion of an image and save it as a jpeg file. I
have some code to do this (attached) which works but the quality of the image
is not as good as the image created simply by saving the bitmap.

I assume therefore that method I have used to obtain a portion of the image
causes the degradation. I'm just wondering if it's possible to obtain a
portion of an image without losing quality?

Regards,

Steve.


Dim clrR As Integer
Dim clrG As Integer
Dim clrB As Integer
Dim x As Integer
Dim y As Integer
Dim intHeight As Integer = 100
Dim intWidth As Integer = 100

'Size the bitmap
Dim bmpCopy As New Bitmap(intWidth, intHeight)
'Get the image
Dim bm As Bitmap = Me.PictureBox1.Image

Dim NewX As Integer = 0
Dim Newy As Integer = 0

For y = 0 To intHeight - 1
For x = 0 To intWidth - 1
' Convert this pixel.
With bm.GetPixel(x, y)
clrR = .R
clrG = .G
clrB = .B
End With
bmpCopy.SetPixel(NewX, Newy, _
Color.FromArgb(255, clrR, clrG, clrB))
NewX = NewX + 1
Next x
Newy = Newy + 1
NewX = 0
Next y

Return bmpCopy
8 Answers

Bob Powell

10/14/2004 3:14:00 PM

0

When you save the bitmap as a jpeg ensure that the encoder uses a 100% image
quality setting. See the GDI+ FAQ for details on how to set JPEG image
quality.

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

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob''s Blog: http://bobpowelldotnet.blogspot.co...






"Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
> Hello,
>
> I''m trying to obtain a portion of an image and save it as a jpeg file. I
> have some code to do this (attached) which works but the quality of the
image
> is not as good as the image created simply by saving the bitmap.
>
> I assume therefore that method I have used to obtain a portion of the
image
> causes the degradation. I''m just wondering if it''s possible to obtain a
> portion of an image without losing quality?
>
> Regards,
>
> Steve.
>
>
> Dim clrR As Integer
> Dim clrG As Integer
> Dim clrB As Integer
> Dim x As Integer
> Dim y As Integer
> Dim intHeight As Integer = 100
> Dim intWidth As Integer = 100
>
> ''Size the bitmap
> Dim bmpCopy As New Bitmap(intWidth, intHeight)
> ''Get the image
> Dim bm As Bitmap = Me.PictureBox1.Image
>
> Dim NewX As Integer = 0
> Dim Newy As Integer = 0
>
> For y = 0 To intHeight - 1
> For x = 0 To intWidth - 1
> '' Convert this pixel.
> With bm.GetPixel(x, y)
> clrR = .R
> clrG = .G
> clrB = .B
> End With
> bmpCopy.SetPixel(NewX, Newy, _
> Color.FromArgb(255, clrR, clrG, clrB))
> NewX = NewX + 1
> Next x
> Newy = Newy + 1
> NewX = 0
> Next y
>
> Return bmpCopy


Steve Bugden

10/14/2004 5:37:00 PM

0

Hi Bob,

Many thanks for the reply.

I have implemented the change suggested but still have the same effect. The
bitmap taken directly from the picture box when saved is fine but the bitmap
created from the picture box and which is a portion of the image is
significantly degraded in quality.

It seems to me that the loss occurs when creating the new bitmap pixel by
pixel. I''m just wondering if there is a better way to do this or perhaps you
disagree with my assumtion?

Steve.
"Bob Powell [MVP]" wrote:

> When you save the bitmap as a jpeg ensure that the encoder uses a 100% image
> quality setting. See the GDI+ FAQ for details on how to set JPEG image
> quality.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/gdipl...
>
> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
> Bob''s Blog: http://bobpowelldotnet.blogspot.co...
>
>
>
>
>
>
> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
> > Hello,
> >
> > I''m trying to obtain a portion of an image and save it as a jpeg file. I
> > have some code to do this (attached) which works but the quality of the
> image
> > is not as good as the image created simply by saving the bitmap.
> >
> > I assume therefore that method I have used to obtain a portion of the
> image
> > causes the degradation. I''m just wondering if it''s possible to obtain a
> > portion of an image without losing quality?
> >
> > Regards,
> >
> > Steve.
> >
> >
> > Dim clrR As Integer
> > Dim clrG As Integer
> > Dim clrB As Integer
> > Dim x As Integer
> > Dim y As Integer
> > Dim intHeight As Integer = 100
> > Dim intWidth As Integer = 100
> >
> > ''Size the bitmap
> > Dim bmpCopy As New Bitmap(intWidth, intHeight)
> > ''Get the image
> > Dim bm As Bitmap = Me.PictureBox1.Image
> >
> > Dim NewX As Integer = 0
> > Dim Newy As Integer = 0
> >
> > For y = 0 To intHeight - 1
> > For x = 0 To intWidth - 1
> > '' Convert this pixel.
> > With bm.GetPixel(x, y)
> > clrR = .R
> > clrG = .G
> > clrB = .B
> > End With
> > bmpCopy.SetPixel(NewX, Newy, _
> > Color.FromArgb(255, clrR, clrG, clrB))
> > NewX = NewX + 1
> > Next x
> > Newy = Newy + 1
> > NewX = 0
> > Next y
> >
> > Return bmpCopy
>
>
>

N Thorell

10/16/2004 8:03:00 PM

0

I have a similar problem when shrinking an image.
The result is too soft, even with different InterpolationMode filters.
Is looks like I need a sharpening filter. Any hints?

"Steve Bugden" wrote:

> Hello,
>
> I''m trying to obtain a portion of an image and save it as a jpeg file. I
> have some code to do this (attached) which works but the quality of the image
> is not as good as the image created simply by saving the bitmap.
>
> I assume therefore that method I have used to obtain a portion of the image
> causes the degradation. I''m just wondering if it''s possible to obtain a
> portion of an image without losing quality?
>
> Regards,
>
> Steve.
>
>
> Dim clrR As Integer
> Dim clrG As Integer
> Dim clrB As Integer
> Dim x As Integer
> Dim y As Integer
> Dim intHeight As Integer = 100
> Dim intWidth As Integer = 100
>
> ''Size the bitmap
> Dim bmpCopy As New Bitmap(intWidth, intHeight)
> ''Get the image
> Dim bm As Bitmap = Me.PictureBox1.Image
>
> Dim NewX As Integer = 0
> Dim Newy As Integer = 0
>
> For y = 0 To intHeight - 1
> For x = 0 To intWidth - 1
> '' Convert this pixel.
> With bm.GetPixel(x, y)
> clrR = .R
> clrG = .G
> clrB = .B
> End With
> bmpCopy.SetPixel(NewX, Newy, _
> Color.FromArgb(255, clrR, clrG, clrB))
> NewX = NewX + 1
> Next x
> Newy = Newy + 1
> NewX = 0
> Next y
>
> Return bmpCopy

Allan McLemore

10/18/2004 4:50:00 PM

0

Hi Steve,

Have you tried using Graphics.DrawImage? You can then take the required
piece out allot quicker.

Nick.

"Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
news:423D7477-5EB3-448E-A639-712512EEB9FB@microsoft.com...
> Hi Bob,
>
> Many thanks for the reply.
>
> I have implemented the change suggested but still have the same effect.
> The
> bitmap taken directly from the picture box when saved is fine but the
> bitmap
> created from the picture box and which is a portion of the image is
> significantly degraded in quality.
>
> It seems to me that the loss occurs when creating the new bitmap pixel by
> pixel. I'm just wondering if there is a better way to do this or perhaps
> you
> disagree with my assumtion?
>
> Steve.
> "Bob Powell [MVP]" wrote:
>
>> When you save the bitmap as a jpeg ensure that the encoder uses a 100%
>> image
>> quality setting. See the GDI+ FAQ for details on how to set JPEG image
>> quality.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Answer those GDI+ questions with the GDI+ FAQ
>> http://www.bobpowell.net/gdipl...
>>
>> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
>> Windows Forms Tips and Tricks RSS:
>> http://www.bobpowell.net/tips...
>> Bob's Blog: http://bobpowelldotnet.blogspot.co...
>>
>>
>>
>>
>>
>>
>> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
>> news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
>> > Hello,
>> >
>> > I'm trying to obtain a portion of an image and save it as a jpeg file.
>> > I
>> > have some code to do this (attached) which works but the quality of the
>> image
>> > is not as good as the image created simply by saving the bitmap.
>> >
>> > I assume therefore that method I have used to obtain a portion of the
>> image
>> > causes the degradation. I'm just wondering if it's possible to obtain a
>> > portion of an image without losing quality?
>> >
>> > Regards,
>> >
>> > Steve.
>> >
>> >
>> > Dim clrR As Integer
>> > Dim clrG As Integer
>> > Dim clrB As Integer
>> > Dim x As Integer
>> > Dim y As Integer
>> > Dim intHeight As Integer = 100
>> > Dim intWidth As Integer = 100
>> >
>> > 'Size the bitmap
>> > Dim bmpCopy As New Bitmap(intWidth, intHeight)
>> > 'Get the image
>> > Dim bm As Bitmap = Me.PictureBox1.Image
>> >
>> > Dim NewX As Integer = 0
>> > Dim Newy As Integer = 0
>> >
>> > For y = 0 To intHeight - 1
>> > For x = 0 To intWidth - 1
>> > ' Convert this pixel.
>> > With bm.GetPixel(x, y)
>> > clrR = .R
>> > clrG = .G
>> > clrB = .B
>> > End With
>> > bmpCopy.SetPixel(NewX, Newy, _
>> > Color.FromArgb(255, clrR, clrG, clrB))
>> > NewX = NewX + 1
>> > Next x
>> > Newy = Newy + 1
>> > NewX = 0
>> > Next y
>> >
>> > Return bmpCopy
>>
>>
>>


Steve Bugden

10/20/2004 1:17:00 PM

0

Hi Nick,

Many tHanks for the reply.

Yes, I tried using drawimage (please see the a section of the code attached).

But this still results in a poor quality jpeg image and is no different to
the image created by looping through each pixel.

I assume there must be something else that needs to be done when creating a
bitmap from part of another one, the question is what.

Best Regards,

Steve

'Create new bitmap
Dim bmpCopy As New Bitmap(intWidth, intHeight)
Dim bm As Bitmap = Me.PictureBox1.Image

'Size the bitmap
'Get the image
y = (Me.PictureBox1.Top + Me.PictureBox1.Height) -
(Me.lblBottomBorder.Top + Me.lblBottomBorder.Height)
Dim srcrect As New Rectangle(intImageLeftStart, y, intWidth,
intHeight)

Dim destrect As New Rectangle(0, 0, intWidth, intHeight)
Dim g As Graphics = Graphics.FromImage(bmpCopy)
g.DrawImage(bm, destrect, srcrect, GraphicsUnit.Pixel)
Return bmpCopy

"Nak" wrote:

> Hi Steve,
>
> Have you tried using Graphics.DrawImage? You can then take the required
> piece out allot quicker.
>
> Nick.
>
> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> news:423D7477-5EB3-448E-A639-712512EEB9FB@microsoft.com...
> > Hi Bob,
> >
> > Many thanks for the reply.
> >
> > I have implemented the change suggested but still have the same effect.
> > The
> > bitmap taken directly from the picture box when saved is fine but the
> > bitmap
> > created from the picture box and which is a portion of the image is
> > significantly degraded in quality.
> >
> > It seems to me that the loss occurs when creating the new bitmap pixel by
> > pixel. I'm just wondering if there is a better way to do this or perhaps
> > you
> > disagree with my assumtion?
> >
> > Steve.
> > "Bob Powell [MVP]" wrote:
> >
> >> When you save the bitmap as a jpeg ensure that the encoder uses a 100%
> >> image
> >> quality setting. See the GDI+ FAQ for details on how to set JPEG image
> >> quality.
> >>
> >> --
> >> Bob Powell [MVP]
> >> Visual C#, System.Drawing
> >>
> >> Answer those GDI+ questions with the GDI+ FAQ
> >> http://www.bobpowell.net/gdipl...
> >>
> >> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> >> Windows Forms Tips and Tricks RSS:
> >> http://www.bobpowell.net/tips...
> >> Bob's Blog: http://bobpowelldotnet.blogspot.co...
> >>
> >>
> >>
> >>
> >>
> >>
> >> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> >> news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
> >> > Hello,
> >> >
> >> > I'm trying to obtain a portion of an image and save it as a jpeg file.
> >> > I
> >> > have some code to do this (attached) which works but the quality of the
> >> image
> >> > is not as good as the image created simply by saving the bitmap.
> >> >
> >> > I assume therefore that method I have used to obtain a portion of the
> >> image
> >> > causes the degradation. I'm just wondering if it's possible to obtain a
> >> > portion of an image without losing quality?
> >> >
> >> > Regards,
> >> >
> >> > Steve.
> >> >
> >> >
> >> > Dim clrR As Integer
> >> > Dim clrG As Integer
> >> > Dim clrB As Integer
> >> > Dim x As Integer
> >> > Dim y As Integer
> >> > Dim intHeight As Integer = 100
> >> > Dim intWidth As Integer = 100
> >> >
> >> > 'Size the bitmap
> >> > Dim bmpCopy As New Bitmap(intWidth, intHeight)
> >> > 'Get the image
> >> > Dim bm As Bitmap = Me.PictureBox1.Image
> >> >
> >> > Dim NewX As Integer = 0
> >> > Dim Newy As Integer = 0
> >> >
> >> > For y = 0 To intHeight - 1
> >> > For x = 0 To intWidth - 1
> >> > ' Convert this pixel.
> >> > With bm.GetPixel(x, y)
> >> > clrR = .R
> >> > clrG = .G
> >> > clrB = .B
> >> > End With
> >> > bmpCopy.SetPixel(NewX, Newy, _
> >> > Color.FromArgb(255, clrR, clrG, clrB))
> >> > NewX = NewX + 1
> >> > Next x
> >> > Newy = Newy + 1
> >> > NewX = 0
> >> > Next y
> >> >
> >> > Return bmpCopy
> >>
> >>
> >>
>
>
>

Bob Powell

10/20/2004 2:05:00 PM

0

Chuck out your pixel by pixel code and just use Graphics.DrawImage.

Dim bm as new Bitmap(100,75)
Dim g as Graphics
g=Graphics.FromImage(bm)
g.DrawImage(this.pictureBox1.Image,new
Rectangle(0,0,100,75),200,300,100,75,GraphicUnit.Pixel)
g.Dispose()

The bitmap bm now contains a chunk chopped from the middle of the picturebox
image...

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

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob's Blog: http://bobpowelldotnet.blogspot.co...






"Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
news:423D7477-5EB3-448E-A639-712512EEB9FB@microsoft.com...
> Hi Bob,
>
> Many thanks for the reply.
>
> I have implemented the change suggested but still have the same effect.
The
> bitmap taken directly from the picture box when saved is fine but the
bitmap
> created from the picture box and which is a portion of the image is
> significantly degraded in quality.
>
> It seems to me that the loss occurs when creating the new bitmap pixel by
> pixel. I'm just wondering if there is a better way to do this or perhaps
you
> disagree with my assumtion?
>
> Steve.
> "Bob Powell [MVP]" wrote:
>
> > When you save the bitmap as a jpeg ensure that the encoder uses a 100%
image
> > quality setting. See the GDI+ FAQ for details on how to set JPEG image
> > quality.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdipl...
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tips...
> > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> >
> >
> >
> >
> >
> >
> > "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> > news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
> > > Hello,
> > >
> > > I'm trying to obtain a portion of an image and save it as a jpeg file.
I
> > > have some code to do this (attached) which works but the quality of
the
> > image
> > > is not as good as the image created simply by saving the bitmap.
> > >
> > > I assume therefore that method I have used to obtain a portion of the
> > image
> > > causes the degradation. I'm just wondering if it's possible to obtain
a
> > > portion of an image without losing quality?
> > >
> > > Regards,
> > >
> > > Steve.
> > >
> > >
> > > Dim clrR As Integer
> > > Dim clrG As Integer
> > > Dim clrB As Integer
> > > Dim x As Integer
> > > Dim y As Integer
> > > Dim intHeight As Integer = 100
> > > Dim intWidth As Integer = 100
> > >
> > > 'Size the bitmap
> > > Dim bmpCopy As New Bitmap(intWidth, intHeight)
> > > 'Get the image
> > > Dim bm As Bitmap = Me.PictureBox1.Image
> > >
> > > Dim NewX As Integer = 0
> > > Dim Newy As Integer = 0
> > >
> > > For y = 0 To intHeight - 1
> > > For x = 0 To intWidth - 1
> > > ' Convert this pixel.
> > > With bm.GetPixel(x, y)
> > > clrR = .R
> > > clrG = .G
> > > clrB = .B
> > > End With
> > > bmpCopy.SetPixel(NewX, Newy, _
> > > Color.FromArgb(255, clrR, clrG, clrB))
> > > NewX = NewX + 1
> > > Next x
> > > Newy = Newy + 1
> > > NewX = 0
> > > Next y
> > >
> > > Return bmpCopy
> >
> >
> >


Steve Bugden

10/20/2004 6:53:00 PM

0

Hi Bob,

I've implemented the suggestion here and there's no visible loss in image
quality now.

THank you very much for the suggestions.

Best Regards,

Steve.

"Bob Powell [MVP]" wrote:

> Chuck out your pixel by pixel code and just use Graphics.DrawImage.
>
> Dim bm as new Bitmap(100,75)
> Dim g as Graphics
> g=Graphics.FromImage(bm)
> g.DrawImage(this.pictureBox1.Image,new
> Rectangle(0,0,100,75),200,300,100,75,GraphicUnit.Pixel)
> g.Dispose()
>
> The bitmap bm now contains a chunk chopped from the middle of the picturebox
> image...
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/gdipl...
>
> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
> Bob's Blog: http://bobpowelldotnet.blogspot.co...
>
>
>
>
>
>
> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> news:423D7477-5EB3-448E-A639-712512EEB9FB@microsoft.com...
> > Hi Bob,
> >
> > Many thanks for the reply.
> >
> > I have implemented the change suggested but still have the same effect.
> The
> > bitmap taken directly from the picture box when saved is fine but the
> bitmap
> > created from the picture box and which is a portion of the image is
> > significantly degraded in quality.
> >
> > It seems to me that the loss occurs when creating the new bitmap pixel by
> > pixel. I'm just wondering if there is a better way to do this or perhaps
> you
> > disagree with my assumtion?
> >
> > Steve.
> > "Bob Powell [MVP]" wrote:
> >
> > > When you save the bitmap as a jpeg ensure that the encoder uses a 100%
> image
> > > quality setting. See the GDI+ FAQ for details on how to set JPEG image
> > > quality.
> > >
> > > --
> > > Bob Powell [MVP]
> > > Visual C#, System.Drawing
> > >
> > > Answer those GDI+ questions with the GDI+ FAQ
> > > http://www.bobpowell.net/gdipl...
> > >
> > > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > > Windows Forms Tips and Tricks RSS:
> http://www.bobpowell.net/tips...
> > > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> > >
> > >
> > >
> > >
> > >
> > >
> > > "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
> > > news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
> > > > Hello,
> > > >
> > > > I'm trying to obtain a portion of an image and save it as a jpeg file.
> I
> > > > have some code to do this (attached) which works but the quality of
> the
> > > image
> > > > is not as good as the image created simply by saving the bitmap.
> > > >
> > > > I assume therefore that method I have used to obtain a portion of the
> > > image
> > > > causes the degradation. I'm just wondering if it's possible to obtain
> a
> > > > portion of an image without losing quality?
> > > >
> > > > Regards,
> > > >
> > > > Steve.
> > > >
> > > >
> > > > Dim clrR As Integer
> > > > Dim clrG As Integer
> > > > Dim clrB As Integer
> > > > Dim x As Integer
> > > > Dim y As Integer
> > > > Dim intHeight As Integer = 100
> > > > Dim intWidth As Integer = 100
> > > >
> > > > 'Size the bitmap
> > > > Dim bmpCopy As New Bitmap(intWidth, intHeight)
> > > > 'Get the image
> > > > Dim bm As Bitmap = Me.PictureBox1.Image
> > > >
> > > > Dim NewX As Integer = 0
> > > > Dim Newy As Integer = 0
> > > >
> > > > For y = 0 To intHeight - 1
> > > > For x = 0 To intWidth - 1
> > > > ' Convert this pixel.
> > > > With bm.GetPixel(x, y)
> > > > clrR = .R
> > > > clrG = .G
> > > > clrB = .B
> > > > End With
> > > > bmpCopy.SetPixel(NewX, Newy, _
> > > > Color.FromArgb(255, clrR, clrG, clrB))
> > > > NewX = NewX + 1
> > > > Next x
> > > > Newy = Newy + 1
> > > > NewX = 0
> > > > Next y
> > > >
> > > > Return bmpCopy
> > >
> > >
> > >
>
>
>

Allan McLemore

10/20/2004 7:00:00 PM

0

Hi there,

I have just had a thought, what type is your source image? Is it
possible that the source image contains an alpha channel, and that you
setting the Alpha level to 255 for every pixel is causing it to look very
blocky? That is the only thing that I can think of from the top of my head
unless of course the JPEG encoder is not working correctly for whatever
reason, I have experienced it failing to perform transformations on images,
so I wouldn't be suprised if the other parameter fails sometimes.

Nick.

"Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
news:AB686558-8B06-4C9B-AB87-A868E9020CAE@microsoft.com...
> Hi Nick,
>
> Many tHanks for the reply.
>
> Yes, I tried using drawimage (please see the a section of the code
> attached).
>
> But this still results in a poor quality jpeg image and is no different to
> the image created by looping through each pixel.
>
> I assume there must be something else that needs to be done when creating
> a
> bitmap from part of another one, the question is what.
>
> Best Regards,
>
> Steve
>
> 'Create new bitmap
> Dim bmpCopy As New Bitmap(intWidth, intHeight)
> Dim bm As Bitmap = Me.PictureBox1.Image
>
> 'Size the bitmap
> 'Get the image
> y = (Me.PictureBox1.Top + Me.PictureBox1.Height) -
> (Me.lblBottomBorder.Top + Me.lblBottomBorder.Height)
> Dim srcrect As New Rectangle(intImageLeftStart, y, intWidth,
> intHeight)
>
> Dim destrect As New Rectangle(0, 0, intWidth, intHeight)
> Dim g As Graphics = Graphics.FromImage(bmpCopy)
> g.DrawImage(bm, destrect, srcrect, GraphicsUnit.Pixel)
> Return bmpCopy
>
> "Nak" wrote:
>
>> Hi Steve,
>>
>> Have you tried using Graphics.DrawImage? You can then take the
>> required
>> piece out allot quicker.
>>
>> Nick.
>>
>> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in message
>> news:423D7477-5EB3-448E-A639-712512EEB9FB@microsoft.com...
>> > Hi Bob,
>> >
>> > Many thanks for the reply.
>> >
>> > I have implemented the change suggested but still have the same effect.
>> > The
>> > bitmap taken directly from the picture box when saved is fine but the
>> > bitmap
>> > created from the picture box and which is a portion of the image is
>> > significantly degraded in quality.
>> >
>> > It seems to me that the loss occurs when creating the new bitmap pixel
>> > by
>> > pixel. I'm just wondering if there is a better way to do this or
>> > perhaps
>> > you
>> > disagree with my assumtion?
>> >
>> > Steve.
>> > "Bob Powell [MVP]" wrote:
>> >
>> >> When you save the bitmap as a jpeg ensure that the encoder uses a 100%
>> >> image
>> >> quality setting. See the GDI+ FAQ for details on how to set JPEG image
>> >> quality.
>> >>
>> >> --
>> >> Bob Powell [MVP]
>> >> Visual C#, System.Drawing
>> >>
>> >> Answer those GDI+ questions with the GDI+ FAQ
>> >> http://www.bobpowell.net/gdipl...
>> >>
>> >> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
>> >> Windows Forms Tips and Tricks RSS:
>> >> http://www.bobpowell.net/tips...
>> >> Bob's Blog: http://bobpowelldotnet.blogspot.co...
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> "Steve Bugden" <SteveBugden@discussions.microsoft.com> wrote in
>> >> message
>> >> news:56DCE5B7-7F32-4C97-ACDE-F59F520DB2D3@microsoft.com...
>> >> > Hello,
>> >> >
>> >> > I'm trying to obtain a portion of an image and save it as a jpeg
>> >> > file.
>> >> > I
>> >> > have some code to do this (attached) which works but the quality of
>> >> > the
>> >> image
>> >> > is not as good as the image created simply by saving the bitmap.
>> >> >
>> >> > I assume therefore that method I have used to obtain a portion of
>> >> > the
>> >> image
>> >> > causes the degradation. I'm just wondering if it's possible to
>> >> > obtain a
>> >> > portion of an image without losing quality?
>> >> >
>> >> > Regards,
>> >> >
>> >> > Steve.
>> >> >
>> >> >
>> >> > Dim clrR As Integer
>> >> > Dim clrG As Integer
>> >> > Dim clrB As Integer
>> >> > Dim x As Integer
>> >> > Dim y As Integer
>> >> > Dim intHeight As Integer = 100
>> >> > Dim intWidth As Integer = 100
>> >> >
>> >> > 'Size the bitmap
>> >> > Dim bmpCopy As New Bitmap(intWidth, intHeight)
>> >> > 'Get the image
>> >> > Dim bm As Bitmap = Me.PictureBox1.Image
>> >> >
>> >> > Dim NewX As Integer = 0
>> >> > Dim Newy As Integer = 0
>> >> >
>> >> > For y = 0 To intHeight - 1
>> >> > For x = 0 To intWidth - 1
>> >> > ' Convert this pixel.
>> >> > With bm.GetPixel(x, y)
>> >> > clrR = .R
>> >> > clrG = .G
>> >> > clrB = .B
>> >> > End With
>> >> > bmpCopy.SetPixel(NewX, Newy, _
>> >> > Color.FromArgb(255, clrR, clrG, clrB))
>> >> > NewX = NewX + 1
>> >> > Next x
>> >> > Newy = Newy + 1
>> >> > NewX = 0
>> >> > Next y
>> >> >
>> >> > Return bmpCopy
>> >>
>> >>
>> >>
>>
>>
>>