הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Thursday, February 9, 2017 1:29 PM
i had converted 1 icon to a gif.
- if i add the image on run-time mode.. no problems.
- if i add the image on design mode... no problems. but if i execute the program, i will get an error\warning: "SetPixel is not supported for images with indexed pixel formats."
why these error\warning? how can i fix it?
All replies (13)
Thursday, February 9, 2017 3:25 PM ✅Answered
i had converted 1 icon to a gif.
- if i add the image on run-time mode.. no problems.
- if i add the image on design mode... no problems. but if i execute the program, i will get an error\warning: "SetPixel is not supported for images with indexed pixel formats."
why these error\warning? how can i fix it?
I don`t know what you are doing or exactly how you converted the Icon to a Gif but, that error is because a Gif image is an Indexed format which does not support the SetPixel method or creating a Graphics method of it. You would have to draw the Gif image to a Bitmap and then use the SetPixel method on it. For example...
Dim Bm As Bitmap
Using GifBm As New Bitmap("C:\TestFolder\Snail.gif")
Bm = New Bitmap(GifBm.Width, GifBm.Height)
Using g As Graphics = Graphics.FromImage(Bm)
g.DrawImage(GifBm, 0, 0, GifBm.Width, GifBm.Height)
End Using
End Using
'now you can use SetPixel on the new 32bppArgb bitmap
Bm.SetPixel(0, 0, Color.Red)
Me.BackgroundImage = Bm
If you say it can`t be done then i`ll try it
Thursday, February 9, 2017 3:20 PM
Hi
You must be crazy if you think anyone can offer help if you do not show the code that you say is not working!
Regards Les, Livingston, Scotland
in these case i'm not showing code, because i don't have it. i'm tell you what i'm doing on form designer. just drag and drop controls and change their properties... in these case what i can show you??
Thursday, February 9, 2017 3:26 PM | 1 vote
Hi,
if the error is related to changing colors in an image, you somewhere must have the code that does it.
My suggestion is to create a new Bitmap from the gif, or convert the icon to a 24 or 32 bpp bitmap, eg a png image.
Creating a new bitmap in code without any other settings, creates a 32 bpp Bitmap. So if you have your gif-image in a variable, say mygifIcon, do something like:
Dim bmp as Bitmap = Nothing
If not mygifIcon is nothing Then
bmp = new Bitmap(mygifIcon) 'creates a new 32bpp bitmap from the input image
End If
'now use bmp as your image
Regards,
Thorsten
Thursday, February 9, 2017 3:31 PM
please see these gif image(i had converted from ico to gif using an online program):
and yes.. see these function:
Private Sub MakeAnimationRegion()
ReDim rgnFrame(FrameCount - 1)
For i As Integer = 0 To FrameCount - 1
If Me.BackgroundImage IsNot Nothing Then
Me.BackgroundImageLayout = ImageLayout.None
Using gp As New Drawing2D.GraphicsPath
If Me.AutoSize = True Then Me.Size = New Size(Me.BackgroundImage.Width, Me.BackgroundImage.Height) 'automatically resize the control to the size of the BackgroundImage
Dim bm As Bitmap = Me.BackgroundImage.Clone
bm.SelectActiveFrame(FrameDimensions, i)
For y As Integer = 0 To bm.Height - 1
For x As Integer = 0 To bm.Width - 1
If (bm.GetPixel(x, y) <> bm.GetPixel(0, 0) AndAlso bm.GetPixel(x, y).A > 0) Then
gp.AddRectangle(New Rectangle(x, y, 1, 1))
End If
Next
Next
rgnFrame(i) = New Region(gp)
End Using
End If
Next
Frame = 0
End Sub
i use SetPixel() with the Bitmap.. but maybe i'm doing wrong on:
Dim bm As Bitmap = Me.BackgroundImage.Clone
i will test it
Thursday, February 9, 2017 3:45 PM | 1 vote
Hi,
why not do as IronRazerz and I suggested? Just copy the selected frame to a new Bitmap and scan this.
So, after selecting the active frame, create a new Bitmap object with bm as origImage (in a using block) and then loop over the newly created bitmaps pixels.
Air code:
bm.SelectActiveFrame(FrameDimensions, i)
using bmp as new bitmap(bm)
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
If (bmp.GetPixel(x, y) <> bmp.GetPixel(0, 0) AndAlso bmp.GetPixel(x, y).A > 0) Then
gp.AddRectangle(New Rectangle(x, y, 1, 1))
End If
Next
Next
end using
Regards,
Thorsten
Thursday, February 9, 2017 4:07 PM
i'm sorry to all. i had show you the wrong sub. but with that idea, i fix it:
Public Property Opacy() As Double
Get
' Statements of the Get procedure.
' The following statement returns an expression as the property's value.
Return intOpacy
End Get
Set(ByVal NewValue As Double)
' Statements of the Set procedure.
' The following statement assigns newvalue as the property's value.
If Me.BackgroundImage Is Nothing Then Exit Property
intOpacy = NewValue
On Error Resume Next
If intOpacy = 0 Then Exit Property
For y As Integer = 0 To Me.BackgroundImage.Height - 1
For x As Integer = 0 To Me.BackgroundImage.Width - 1
Dim s As Bitmap = New Bitmap(Me.BackgroundImage.Width, Me.BackgroundImage.Height)
Dim gra As Graphics = Graphics.FromImage(s)
gra.DrawImage(Me.BackgroundImage, 0, 0)
If s.GetPixel(x, y) <> s.GetPixel(0, 0) Then
Dim clr As Color = s.GetPixel(x, y)
clr = Color.FromArgb(intOpacy * 244, clr.R, clr.G, clr.B)
s.SetPixel(x, y, clr)
End If
Me.BackgroundImage = s
gra.Dispose()
Next
Next
Me.Refresh()
End Set
End Property
i have i generic GDI+ error. so i add an 'if' if is zero and the 'on error resume next' for avoid more problems... isn't a good programming add these line, but resolves more problems
Thursday, February 9, 2017 5:31 PM
This "intOpacy * 244" can only be 0 To 255 so what is 2 * 244?
La vida loca
Thursday, February 9, 2017 5:50 PM
This "intOpacy * 244" can only be 0 To 255 so what is 2 * 244?
La vida loca
i have much more than that error :(
Thursday, February 9, 2017 5:57 PM | 1 vote
This "intOpacy * 244" can only be 0 To 255 so what is 2 * 244?
La vida loca
i have much more than that error :(
Yes but that is really due to not learning vb.net for the areas you are trying to use programming for and then copying and pasting code to use which you do not understand so there is no probability that you can correct issues with it since you do not know any of it.
La vida loca
Thursday, February 9, 2017 6:07 PM
This "intOpacy * 244" can only be 0 To 255 so what is 2 * 244?
La vida loca
i have much more than that error :(
Yes but that is really due to not learning vb.net for the areas you are trying to use programming for and then copying and pasting code to use which you do not understand so there is no probability that you can correct issues with it since you do not know any of it.
La vida loca
theres is another easy way, but i did it on VB6: Color Matrix.
and continuing using the VB2010, with errors, isn't helping too
Thursday, February 9, 2017 6:15 PM
This "intOpacy * 244" can only be 0 To 255 so what is 2 * 244?
La vida loca
i have much more than that error :(
Yes but that is really due to not learning vb.net for the areas you are trying to use programming for and then copying and pasting code to use which you do not understand so there is no probability that you can correct issues with it since you do not know any of it.
La vida loca
theres is another easy way, but i did it on VB6: Color Matrix.
and continuing using the VB2010, with errors, isn't helping too
Yes but Visual Studio 2010 would not have errors if you corrected the errors. You can not correct errors if you do not understand code the errors pertain to without researching and learning how the code works.
It's simple to come here and get corrected code or other code but then since you still may not know how the code works then you can't maintain it if something occurs.
La vida loca
Thursday, February 9, 2017 6:22 PM
to be honest i had learned more here, about the errors than the book.
on some cases, i don't need recreate the entire project. i think is a good learn when we can fix more errors.
Thursday, February 9, 2017 7:23 PM
theres is another easy way, but i did it on VB6: Color Matrix.
and continuing using the VB2010, with errors, isn't helping too
A ColorMatrix is available in .net too.
Your intOpacity is actually a double? So the multiplication should be intOpacity * 255.0
Instead of :
Dim s As Bitmap = New Bitmap(Me.BackgroundImage.Width, Me.BackgroundImage.Height)
Dim gra As Graphics = Graphics.FromImage(s)
gra.DrawImage(Me.BackgroundImage, 0, 0)
just create a new bitmap with the orig as parameter as IronRazorz and I suggested in multiple cases... :-)
Dim s As Bitmap = New Bitmap(Me.BackgroundImage)
and re-setting the BackgroundImage *in* the loop doesnt make sense to me...
Regards,
Thorsten