Click here to Skip to main content
16,009,156 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionneed twain copy to use in my project Pin
nickib5811-Jan-07 10:23
nickib5811-Jan-07 10:23 
AnswerRe: need twain copy to use in my project Pin
Christian Graus11-Jan-07 11:20
protectorChristian Graus11-Jan-07 11:20 
QuestionDeclaring a form dynamically Pin
FrodoTeeBagins11-Jan-07 8:50
FrodoTeeBagins11-Jan-07 8:50 
AnswerRe: Declaring a form dynamically Pin
nlarson1111-Jan-07 10:31
nlarson1111-Jan-07 10:31 
AnswerRe: Declaring a form dynamically Pin
nlarson1111-Jan-07 10:40
nlarson1111-Jan-07 10:40 
QuestionPublishing in the 2.0 framework Pin
KreativeKai11-Jan-07 8:20
professionalKreativeKai11-Jan-07 8:20 
QuestionHELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg11-Jan-07 6:38
vbbeg11-Jan-07 6:38 
AnswerRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Duncan Edwards Jones12-Jan-07 3:11
professionalDuncan Edwards Jones12-Jan-07 3:11 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg12-Jan-07 5:11
vbbeg12-Jan-07 5:11 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak12-Jan-07 6:28
mveDave Kreskowiak12-Jan-07 6:28 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg12-Jan-07 6:44
vbbeg12-Jan-07 6:44 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak12-Jan-07 12:15
mveDave Kreskowiak12-Jan-07 12:15 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg13-Jan-07 6:12
vbbeg13-Jan-07 6:12 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
Dave Kreskowiak15-Jan-07 5:36
mveDave Kreskowiak15-Jan-07 5:36 
GeneralRe: HELP WITH PRINTING MARGINS PLS READ! Pin
vbbeg16-Jan-07 3:24
vbbeg16-Jan-07 3:24 
QuestionAnyone know any good resources on developing right-click/context menus for form controls??? Pin
Joey Picerno11-Jan-07 5:41
Joey Picerno11-Jan-07 5:41 
AnswerRe: Anyone know any good resources on developing right-click/context menus for form controls??? Pin
Kschuler11-Jan-07 9:07
Kschuler11-Jan-07 9:07 
QuestionAnother question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 4:10
Savas Cilve11-Jan-07 4:10 
AnswerRe: Another question about Graphics.DrawString Pin
Dave Kreskowiak11-Jan-07 4:15
mveDave Kreskowiak11-Jan-07 4:15 
GeneralRe: Another question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 4:23
Savas Cilve11-Jan-07 4:23 
GeneralRe: Another question about Graphics.DrawString Pin
Dave Kreskowiak11-Jan-07 5:37
mveDave Kreskowiak11-Jan-07 5:37 
Again, nowhere in your code do you call Dispose() on the Graphics object you're creating. You MUST ALWAYS call .Dispose() on a Graphics object when you're done using it, otherwise you get odd behavior, kind of like changes not being saved, when manipulating images and your app is suddenly leaking GDI Handles and will eventually crash the system! BTW, you also have to .Dispose() Font objects when you're done with them too.

Since you're only using the Graphics object when a property item contains a certain value, I suggest not creating any Graphics or Font objects unless you need them:
Imports System.Drawing.Imaging
.
.
.
For Each img As Image In _images
    Dim changed As Boolean = False
    Dim pi() As Drawing.Imaging.PropertyItem = img.PropertyItems
 
    For Each pItem As Drawing.Imaging.PropertyItem In pi
        If pItem.Id = 36867 Then
            Dim bytes() As Byte = pItem.Value
            Dim f As New Font(FontFamily.GenericSerif, 35.0F, FontStyle.Regular, GraphicsUnit.Point)
            Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)
            Dim enc As New System.Text.UTF8Encoding
 
            graph.DrawString(enc.GetString(bytes), f, Brushes.Yellow, CSng(img.Width) - 400.0F, CSng(img.Height) - 50.0F)
            graph.Dispose()
            f.Dipose()
 
            ' Create a JPEG Encoder and set it's Compression quality
            Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
            Dim encoderParams As New EncoderParameters(1)
            encoderParams.Param[0] = New EncoderParameter(Encoder.Quality, 100)
 
            ' Save the image using the new encoder
            img.Save(_imagesHash.Item(img).ToString() & ".jpg", jpegCodec, encoderParams)
            Exit For
        End If
    Next
Next
 
.
.
.
 
Public Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders()
 
    For i As Integer = 0 To codecs.Length
        If codecs[i].MimeType = mimeType Then
            Return codecs[i]
	End If
    Next
    Return Nothing
End Sub

The reason why it's size changes is because you didn't specify the format to use when the image is saved. In your case, the image is saved as PNG format, not JPG. The filename you give doesn't determine the format of the image written. If you want to save an image in JPG format, you have to tell it to do so. If you want to control the compression used on the JPG image, you have to add EncoderParameters to spell out how the JPG should be handled. Those above has been modified to do this.



Dave Kreskowiak
Microsoft MVP - Visual Basic


GeneralRe: Another question about Graphics.DrawString Pin
Savas Cilve11-Jan-07 6:08
Savas Cilve11-Jan-07 6:08 
QuestionInsert File Pin
jds120711-Jan-07 3:56
jds120711-Jan-07 3:56 
QuestionWhat??? Pin
CPallini11-Jan-07 4:06
mveCPallini11-Jan-07 4:06 
AnswerRe: Insert File Pin
Dave Kreskowiak11-Jan-07 4:12
mveDave Kreskowiak11-Jan-07 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.