Solved

Avoiding "dithering" when using DrawImage

Posted on 2004-08-17
47
807 Views
Last Modified: 2011-09-20
I'm using the GDI to slice an image into bits. The code I use is show below. The problem is that even if I start with an image filled with a single websafe colour, when I slice an area off, the resulting image is no longer a solid colour, it has little flecks in it. Consequently, when I display the slices, they don't match the single-colour background.

I'm not well up on graphics, so I'd appreciate any ideas or comments as to what's going on. I've tried it with GIF, JPEG and PNG images and get the same results. I tried changing "PixelFormat.Format24bppRgb" to an 8-bit setting, but it complained that it was "indexed". I've commented out the "'grPhoto.InterpolationMode" stuff, but that made no difference.

Any ideas?



    Private Function Slice(ByVal imgPhoto As Image, ByVal FromX As Integer, ByVal FromY As Integer, _
    ByVal nWidth As Integer, ByVal nHeight As Integer) As Image

        Dim bmPhoto As Bitmap = New Bitmap(nWidth, nHeight, PixelFormat.Format24bppRgb)
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
        'grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

        Dim rectSlice As Rectangle = New Rectangle
        rectSlice.X = FromX
        rectSlice.Y = FromY
        rectSlice.Height = nHeight
        rectSlice.Width = nWidth

        grPhoto.DrawImage(imgPhoto, 0, 0, rectSlice, GraphicsUnit.Pixel)
        grPhoto.Dispose()
        Return bmPhoto

    End Function
0
Comment
Question by:crescendo
  • 19
  • 15
  • 5
  • +2
47 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 11821226
grPhoto.SmoothingMode = SmoothingMode.HighQuality

?
0
 
LVL 7

Expert Comment

by:psdavis
ID: 11821280
Also try

grPhoto.CompositingQuality = CompositingQuality.HighQuality
0
 
LVL 27

Expert Comment

by:planocz
ID: 11821293
You need to change to this....
        grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)
0
 
LVL 7

Expert Comment

by:psdavis
ID: 11821303
One last one if the others don't work...              grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
0
 
LVL 9

Author Comment

by:crescendo
ID: 11821943
psdavis:

Nope, none of those worked.

planocz:

<<You need to change to this....>>

What's the difference between that and what I'm already doing?
0
 
LVL 27

Expert Comment

by:planocz
ID: 11822066
I had the same problem when I was moving bmps around.
But after I change to  add new rect. the images it came in nice and clear.
the grphoto has to have a new base to start with.
0
 
LVL 9

Author Comment

by:crescendo
ID: 11822091
I tried it, and it didn't work.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11823480
I am curious about something:

Does nWidth=imgPhoto.HorizontalResolution and nHeight = imgPhoto.VerticalResolution?

Bob

0
 
LVL 9

Author Comment

by:crescendo
ID: 11823838
Bob:

Are they even in the same units? Surely nWidth is pixels, and resolution is dots per inch or something? Or am I missing something here?

I just checked it, the resolution is 96.0, width and height are 160 and 40 respectively.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11823872
I was curious, because I never found a need to SetResolution (which is DPI btw).  Was there a reason for using this?

Bob
0
 
LVL 7

Expert Comment

by:psdavis
ID: 11823903
Only reason I've ever set the DPI is during scanning so I can set items on my image based on resolution.

I'm thinking his problem is that his original image is 8-bit paletized and when he's making 24 bit images from them, the palette isn't moving over properly.  Try setting your destination to

PixelFormat.Format8bppIndexed

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11823964
I would go with the default:

Dim bmPhoto As Bitmap = New Bitmap(nWidth, nHeight)

Bob
0
 
LVL 7

Expert Comment

by:psdavis
ID: 11823978
I'm thinking the default is 24 bit though.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824024
No, it is Format32bppARGB.  I do this all the time without anti-aliasing and smoothing, with JPG images, by just using the height and width properties, and I don't get any dithering or speckles, so I am struggling to see why you are having this problem.  This is a straight-forward approach that is usually a simple process, without a lot of magic.

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824101
Bob

I commented out the SetResolution line and had some success with a single-colour image. However, my real image again gave a speckly result. It should be websafe, the colour which gets speckled is #99CCFF. It also gets some coloured speckles around a line which was originally pure black.

psdavis

I tried PixelFormat.Format8bppIndexed, but you get an error, "A Graphics object cannot be created from an image that has an indexed pixel format".
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824128
Bob

I just tried the default, no success.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824134
Did you test the other suggestion of just using this line?

Dim bmPhoto As Bitmap = New Bitmap(nWidth, nHeight)

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824173
Yes, as above, we must have overlapped.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824198
Was is the image format for the source image?

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824264
It's a gif, 160 x 105, 3 unique colours, created in Paint Shop Pro 6. I've uploaded it to one of my servers if you want to see the little troublemaker.

http://www.crescendo.ltd.uk/images/callout.gif
0
 
LVL 27

Expert Comment

by:planocz
ID: 11824274
you keep saying websafe is this a web app?

If so there maybe the problem.
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824324
I'm using ASP.NET to run the code, and ultimately I want to use the sliced images on the web. But that's largely irrelevant, because after I run the code to create the second image I view in Paint Shop Pro, and the problem shows up there, so it's nothing specific to the web or a browser.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 11824338
HTH:

HOW TO: Save a .gif File with a New Color Table By Using Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q319061

It has some information about the limitations of GIF files with GDI+

Bob
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Author Comment

by:crescendo
ID: 11824347
Oh, and here's what I get for the second image, with speckles....

http://www.crescendo.ltd.uk/images/safetop.gif
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824513
Bob

Hmmmm.... that link seems to be saying, in the usual MS way, that GDI+ and GIF files don't go well together. Apart from the code being in C#, and I use VB.Net, it has to run in "unsafe" mode to work.

However, I get the same problems when I save the image as PNG or JPEG if I remember rightly, so this may be a red herring. Let me check.
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824558
Yes, I get similar, but not as pronounced, problems with JPEG and PNG formats.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824589
Okay, back up and take a look at the whole picture:

What are you doing here?  What version of ASP.NET 1.0 or 1.1?  Where is this image drawn where the dithering occurs?

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824674
I'm using ASP.NET 1.1. As I'm just trying to get the code to work at this point, I just click on a button and all the work is done in code-behind. I use an existing image "callout.gif" (see link above) and always create "safetop.gif" (see link above) from the top 40 pixels. I then use Paint Shop Pro to view the newly-created safetop.gif because I can zoom in to see the problems in detail. On a browser it's hard to see exactly what's wrong.

I've posted the code I use. The Button1_Click routine just loads the picture from a file and calls the slice function, then saves the resulting image to a file.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824711
Are you saving the image to a file, and then opening with Paint Shop Pro?  

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824730
Yes
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824745
How are you saving the image to a file?  Does the file look okay when opened with something like Internet Explorer?

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11824909
I'm saving it with

    imgSlice.Save(sFilename, ImageFormat.Gif)

where imgSlice is the image returned by the Slice function posted above.

It looks bad in Explorer too, but because it's not a large image you can't tell what's wrong, the colour just doesn't match. Then you blow it and you can see it's dithered.

Did you look at the images via the links?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11824944
Yes, the images look dithered for me also, just like you described.  I feel like this should be because of the color palette differences--changing from 24-bit or 32-bit color to 8-bit color.

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11825075
I'm inclined to agree, and give up on it. It's disappointing because I thought GDI+ would be better, but I guess it was more designed for graphics such as charts, though even there you would surely want to save it as a GIF to keep the size down?

0
 
LVL 9

Author Comment

by:crescendo
ID: 11825109
Thanks for the suggestions. I hope you think a 'B' is fair, if you're unhappy just say so.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11825137
No, I think that "B" is fair.  I was going to try to find a solution to saving the file as GIF, but you accepted quickly.  Just for fun, I will try to discover an answer for this for myself.  I work so much with JPGs in Windows Forms applications, that I am not always sure what the solution to this kind of problem is.

Bob
0
 
LVL 9

Author Comment

by:crescendo
ID: 11825262
Do you find JPGs work OK in a similar scenario? I tried saving to a JPG and got some dithering, though not as bad as the GIF.

If you find a solution, let me know.

I would use windows forms too, but haven't got round to it yet. I have a background in "classic" ASP and VB6, and had to convert to ASP.NET pretty quickly, which I've done, and feel I'm fairly proficient. Windows Forms with VB.Net should be pretty much the same, but I suspect there will be just enough quirks to require some homework time! The biggest problem is finding my way around the new IDE. I ran up a VB Windows Forms app as a test, and it took me a while just to run a "hello world" program.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11825292
Yes, I can understand that.  I came from a predominately VB6 background, and it was such a huge learning curve just to do those simple tasks that I could in my sleep with VB6.

I feel that the effort that I have put into learning VB.NET will pay huge dividends with future versions of Visual Studio.NET (like 2005).  I don't think that it was fully fleshed out by Micro$oft.  It is still a work in progress as far as I am concerned.  I saw some of the changes proposed by 2005, and they look like significant improvements.

Bob
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11826071
Can you post an example of how you use that function?
0
 
LVL 9

Author Comment

by:crescendo
ID: 11828910
No problem. See the Button1_Click event handler. My web form has an image imgMain, and textboxes txtX, txtY, txtWidth, txtHeight. These are self-explanatory and are pre-filled. There is also a textbox txtFilename which is the name to save the portion to, and a dropdown with the extension to use. The pre-filled values are:

imgMain - callout.gif (see link in a post above)
txtX - 0
txtY - 0
txtWidth - 160
txtHeight - 40
txtFilename - safetop
cmbType - .gif

Here's the code:

    Private Function Slice(ByVal imgPhoto As Image, ByVal FromX As Integer, ByVal FromY As Integer, _
    ByVal nWidth As Integer, ByVal nHeight As Integer) As Image

        Dim bmPhoto As Bitmap = New Bitmap(nWidth, nHeight)
        'bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)

        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
        'grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic

        Dim rectSlice As Rectangle = New Rectangle
        rectSlice.X = FromX
        rectSlice.Y = FromY
        rectSlice.Height = nHeight
        rectSlice.Width = nWidth

        grPhoto.DrawImage(imgPhoto, 0, 0, rectSlice, GraphicsUnit.Pixel)
        grPhoto.Dispose()
        Return bmPhoto

    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim WorkingDirectory As String = Server.MapPath("images/test") + "\"
        Dim sFilename As String = WorkingDirectory + txtFilename.Text + cmbType.SelectedValue
        Dim imgPhoto As Image = Image.FromFile(Server.MapPath(imgMain.ImageUrl))
        Dim imgSlice As Image = Slice(imgPhoto, txtX.Text, txtY.Text, txtWidth.Text, txtHeight.Text)
        Select Case cmbType.SelectedValue
            Case ".gif"
                imgSlice.Save(sFilename, ImageFormat.Gif)
            Case ".jpg"
                imgSlice.Save(sFilename, ImageFormat.Jpeg)
            Case ".bmp"
                imgSlice.Save(sFilename, ImageFormat.Bmp)
            Case ".png"
                imgSlice.Save(sFilename, ImageFormat.Png)
        End Select

        imgPart.ImageUrl = "images/test/" + txtFilename.Text + cmbType.SelectedValue
    End Sub
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11830152
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11830195
Now, that's what we're talking about *GRIN*  One for the memory banks.

Bob
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11830228
What do you mean by this *GRIN*?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11830241
I was looking for a link just like that one.  *GRIN* is the text equivalent of the grin emoticon in Yahoo instant messenger.

Bob
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11835335
Copy this code into a class and run it

i already tried and it worked.

'This is the linnk

'http://www.bobpowell.net/giftransparency.htm

Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices

Namespace TransparentGifCreator
    Public Class Form1

        Inherits System.Windows.Forms.Form

        Private pictureBox1 As System.Windows.Forms.PictureBox

        Private WithEvents panel1 As System.Windows.Forms.Panel

        Private WithEvents button1 As System.Windows.Forms.Button

        Private WithEvents button2 As System.Windows.Forms.Button

        Private WithEvents button3 As System.Windows.Forms.Button

        Private components As System.ComponentModel.IContainer



        Private _gifImage As Image

        Private WithEvents timer1 As System.Windows.Forms.Timer

        Private cp As ColorPalette
        Private CurrentEntry As Integer

        Public Sub New()

            '

            ' Required for Windows Form Designer support

            '

            InitializeComponent()

        End Sub 'New



        '

        ' TODO: Add any constructor code after InitializeComponent call

        '



        '/ <summary>

        '/ Clean up any resources being used.

        '/ </summary>

        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

            If disposing Then

                If Not (components Is Nothing) Then

                    components.Dispose()

                End If

            End If

            MyBase.Dispose(disposing)

        End Sub 'Dispose



#Region "Windows Form Designer generated code"



        '/ <summary>

        '/ Required method for Designer support - do not modify

        '/ the contents of this method with the code editor.

        '/ </summary>

        Private Sub InitializeComponent()

            Me.components = New System.ComponentModel.Container

            Me.pictureBox1 = New System.Windows.Forms.PictureBox

            Me.panel1 = New System.Windows.Forms.Panel

            Me.button1 = New System.Windows.Forms.Button

            Me.button2 = New System.Windows.Forms.Button

            Me.button3 = New System.Windows.Forms.Button

            Me.timer1 = New System.Windows.Forms.Timer(Me.components)

            Me.SuspendLayout()

            '

            ' pictureBox1

            '

            Me.pictureBox1.Location = New System.Drawing.Point(96, 8)

            Me.pictureBox1.Name = "pictureBox1"

            Me.pictureBox1.Size = New System.Drawing.Size(144, 144)

            Me.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage

            Me.pictureBox1.TabIndex = 0

            Me.pictureBox1.TabStop = False

            '

            ' panel1

            '

            Me.panel1.Location = New System.Drawing.Point(8, 168)

            Me.panel1.Name = "panel1"

            Me.panel1.Size = New System.Drawing.Size(144, 144)

            Me.panel1.TabIndex = 1

            '

            ' button1

            '

            Me.button1.Location = New System.Drawing.Point(200, 176)

            Me.button1.Name = "button1"

            Me.button1.Size = New System.Drawing.Size(88, 24)

            Me.button1.TabIndex = 2

            Me.button1.Text = "Open"

            '

            ' button2

            '

            Me.button2.Location = New System.Drawing.Point(200, 216)

            Me.button2.Name = "button2"

            Me.button2.Size = New System.Drawing.Size(88, 24)

            Me.button2.TabIndex = 2

            Me.button2.Text = "Save"

            '

            ' button3

            '

            Me.button3.Location = New System.Drawing.Point(200, 256)

            Me.button3.Name = "button3"

            Me.button3.Size = New System.Drawing.Size(88, 24)

            Me.button3.TabIndex = 2

            Me.button3.Text = "Exit"

            '

            ' timer1

            '

            Me.timer1.Enabled = True

            Me.timer1.Interval = 250

            '

            ' Form1

            '

            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

            Me.ClientSize = New System.Drawing.Size(328, 325)

            Me.Controls.Add(button1)

            Me.Controls.Add(panel1)

            Me.Controls.Add(pictureBox1)

            Me.Controls.Add(button2)

            Me.Controls.Add(button3)

            Me.Name = "Form1"

            Me.Text = "Form1"

            Me.ResumeLayout(False)

        End Sub 'InitializeComponent

#End Region





        '/ <summary>

        '/ The main entry point for the application.

        '/ </summary>

        <STAThread()> _
        Shared Sub Main()

            Application.Run(New Form1)

        End Sub 'Main





        Private Sub panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint

            If cp Is Nothing Then

                Return

            End If

            Dim y As Single

            For y = 0 To 15

                Dim x As Single

                For x = 0 To 15

                    Dim c As Color = Color.Black

                    If 16 * y + x < cp.Entries.Length Then

                        c = cp.Entries(CInt(16 * y + x))

                    End If

                    Dim sb As New SolidBrush(Color.FromArgb(255, c))

                    Dim w As Single = CSng(Me.panel1.Width) / 16

                    Dim h As Single = CSng(Me.panel1.Height) / 16

                    e.Graphics.FillRectangle(sb, w * x, h * y, w, h)

                    If c.A <> 255 Then

                        If showTrans Then

                            e.Graphics.DrawRectangle(Pens.Black, w * x, h * y, w - 1, h - 1)

                        Else

                            e.Graphics.DrawRectangle(Pens.White, w * x, h * y, w - 1, h - 1)

                        End If

                    End If

                    sb.Dispose()

                Next x

            Next y

        End Sub 'panel1_Paint





        Private Sub panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles panel1.MouseMove

            Dim y As Integer = CInt(CSng(e.Y) / (CSng(Me.panel1.Width) / 16.0F))

            Dim x As Integer = CInt(CSng(e.X) / (CSng(Me.panel1.Height) / 16.0F))

            CurrentEntry = CInt(16 * y + x)

            If Not (cp Is Nothing) Then

                If CurrentEntry >= cp.Entries.Length Then

                    CurrentEntry = cp.Entries.Length - 1

                End If 'Little bit of diagnostic for the palette chooser below

            End If 'System.Diagnostics.Trace.WriteLine(string.Format("{0},{1}, adjusted={4},{5} entry={2} Colour={3}",e.X,e.Y,CurrentEntry,cp.Entries[CurrentEntry].ToString(),x,y));

        End Sub 'panel1_MouseMove





        Private Sub panel1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles panel1.Click

            'Creates a new GIF image with a modified colour palette

            If Not (cp Is Nothing) Then

                'Create a new 8 bit per pixel image

                Dim bm As New Bitmap(_gifImage.Width, _gifImage.Height, PixelFormat.Format8bppIndexed)

                'get it's palette

                Dim ncp As ColorPalette = bm.Palette



                'copy all the entries from the old palette removing any transparency

                Dim n As Integer = 0

                Dim c As Color

                For Each c In cp.Entries

                    ncp.Entries(n) = Color.FromArgb(255, c)

                    n += 1

                Next c

                'Set the newly selected transparency

                ncp.Entries(CurrentEntry) = Color.FromArgb(0, cp.Entries(CurrentEntry))

                're-insert the palette

                bm.Palette = ncp



                'now to copy the actual bitmap data

                'lock the source and destination bits

                Dim src As BitmapData = CType(_gifImage, Bitmap).LockBits(New Rectangle(0, 0, _gifImage.Width, _gifImage.Height), ImageLockMode.ReadOnly, _gifImage.PixelFormat)

                Dim dst As BitmapData = bm.LockBits(New Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.WriteOnly, bm.PixelFormat)



                If (True) Then

                    'steps through each pixel

                    Dim y As Integer

                    For y = 0 To _gifImage.Height - 1

                        Dim x As Integer

                        For x = 0 To _gifImage.Width - 1

                            'transferring the bytes

                            Marshal.WriteByte(dst.Scan0, dst.Stride * y + x, Marshal.ReadByte(src.Scan0, src.Stride * y + x))

                        Next x

                    Next y

                End If

                'all done, unlock the bitmaps

                CType(_gifImage, Bitmap).UnlockBits(src)

                bm.UnlockBits(dst)



                'clear out the picturebox

                Me.pictureBox1.Image = Nothing

                _gifImage.Dispose()

                'set the new image in place

                _gifImage = bm

                cp = _gifImage.Palette

                Me.pictureBox1.Image = _gifImage

            End If

        End Sub 'panel1_Click





        Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

            Dim dlg As New OpenFileDialog

            dlg.Filter = "GIF files|*.GIF"

            If dlg.ShowDialog() = DialogResult.OK Then

                _gifImage = Image.FromFile(dlg.FileName)

                Me.pictureBox1.Image = _gifImage

                cp = _gifImage.Palette

                Me.panel1.Invalidate()

            End If

        End Sub 'button1_Click





        Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button2.Click

            Dim dlg As New SaveFileDialog

            dlg.Filter = "GIF files|*.gif"

            dlg.DefaultExt = ".gif"

            dlg.AddExtension = True

            If dlg.ShowDialog() = DialogResult.OK Then

                _gifImage.Save(dlg.FileName, ImageFormat.Gif)

            End If

        End Sub 'button2_Click





        Private Sub button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button3.Click

            Application.Exit()

        End Sub 'button3_Click



        Private showTrans As Boolean





        Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer1.Tick

            showTrans ^= True

            Dim g As Graphics = Me.panel1.CreateGraphics()

            'I do this rather than invalidate the panel because

            'the panel draws its background ans so flickers horribly.

            Dim pe As New PaintEventArgs(g, New Rectangle(0, 0, Me.panel1.Width, Me.panel1.Height))

            Me.panel1_Paint(Me, pe)

            g.Dispose()

        End Sub 'timer1_Tick

    End Class 'Form1

End Namespace 'TransparentGifCreator


0
 
LVL 9

Author Comment

by:crescendo
ID: 11836463
wguerram:

The code sample is for creating a transparent gif. Have you modified it to take a slice off, as in my app?
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11841377
Sorry you are right.

I found this

http://www.visualbasicforum.com/attachment.php?attachmentid=11547

I made changes in order to slice the image after open it, using your function.

And also in the QuantizeImage method i commented the condition which compares the image format with A 24 bits in order to process any image format, i just tried it with your image sample.

i tried and it worked fine.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now