It is currently Wed Jul 23, 2014 8:47 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: [VB.NET] MemoryStream to Image?
PostPosted: Mon Oct 26, 2009 1:57 am 
Offline
User avatar
.: Newbie :.

Joined: Tue Oct 20, 2009 9:20 am
Posts: 18
iTrader:
Gender: Female
Cash:18
Reputation point: 5
JenJen is on a distinguished road
Ok, I normally don't pester people with questions on programming, but I have been working for a week on an ABer, and It's darn near done. Only problem is it never buys (Doh!). Upon detailed interrogation, I determined there was one area that is causing an issue, and its, obviously pretty critical that it works, and thats the Captcha Picture section.

My problem, is that I cannot get the picture to properly go from a memorystream to Image format. It seems to do the byte conversion fine, but when I try to store it in a varible (Image) it gives me a "Parameter is not valid." Error. I'm thurally frustrated at this point, so I thought I'd see if any of you guys have thoughts or suggestions.

My unsuccessful trys so far:

#1
Code:
Public Function GetCaptcha(ByVal strURL As String) As System.Drawing.Image
    Dim msCaptcha As MemoryStream
    Dim msWebClient As WebClient
    msWebClient = New WebClient()
    msCaptcha = New MemoryStream(msWebClient.DownloadData(URL))
    GetCaptcha = Image.FromStream(msCaptcha)
End Function


#2
Code:
Public Function GetCaptcha(ByVal strURL As String) As System.Drawing.Image
    Dim memStream As New _
    MemoryStream(System.Text.Encoding.Default.GetBytes(Wrapper.StripHeaders(Wrapper.Request("GET", strURL, ""))))
    GetCaptcha = Image.FromStream(memStream)
    Return GetCaptcha
End Function


#3
Code:
Public Function GetCaptcha(ByVal strURL As String) As System.Drawing.Image
    Dim bytes() As Byte = System.Text.Encoding.Default.GetBytes(Wrapper.StripHeaders(Wrapper.Request("PIC", URL, "")))   
    Dim objMS As New System.IO.MemoryStream
    objMS.Write(bytes, 0, bytes.Length)
    GetCaptcha = System.Drawing.Image.FromStream(objMS)
End Function


I had a few other versions as well, but reguardless, ALL of them error at the last part, where its supposed to take the stream and store it in the GetCaptcha image varible.

EDIT - I just realized this is in the totally wrong section. ARg...been up for 24 hours...sleep deprived LOL

I also verified that method 1 works with some random hotlinked jpg on the interwebz, so the issue has to be what I had half thought before, and that is that there is no captcha being streamed for some reason, hence no data to make an image from. But why its not getting the captcha, IDK. It gets the right URL.


Top
 Profile  
 
 Post subject: Re: [VB.NET] MemoryStream to Image?
PostPosted: Mon Oct 26, 2009 3:53 am 
Offline
User avatar
.: Admin :.

Joined: Sun Mar 02, 2008 5:00 am
Posts: 3003
Location: Home sweet home
iTrader:
Gender: Male
Cash:3460
Reputation point: 519
Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!Zer0 has a reputation beyond repute!


Content Giveaway Donor Award Trader Winner Award

I ran into this strange problem as well quite a while ago (using Java). I haven't really been able to find the source of the problem, but there might be some work-arounds.

I noticed that the image is being sent to the program, but for some reason the program fails to interpret it correctly. Instead of converting the byte stream to an image, I saved the data to my hard drive and opened it up with an image processing program. And much to my surprise, the captcha image was there.

So as a workaround, try saving the byte stream to a file, reading the file, and then convert that to an image rather than converting the original byte stream to an image. (Note: I haven't tried this myself so I dunno if it'll work or not)

_________________
Programs
AB List Creator ~ Account Generator

Guides
Employment Agency ~ NeoAcademy HowTo ~ List of Guides ~ Game Score Review List ~ Starting up (again) After Getting Iced ~ Packrat Avatar List ~ Top Gamer Avatar Game List ~ Avatar Game List ~ Roodoku Guide ~ Altador Cup Player Avatar ~ GM Scripts ~ Autobuying Shop Guide ~ Ways of Making NP ~ Neoquest 3D ~ IP Addresses

Helpful Threads
Taking AB List Requests ~ AB Lists ~ Updated Igloo AB List

Code Snippets
[Java] HTTP Wrapper ~ [Java] Neopets Wrapper ~ [Java] Proxy Support ~ [Java] Smart Haggle


Top
 Profile  
 
 Post subject: Re: [VB.NET] MemoryStream to Image?
PostPosted: Mon Oct 26, 2009 3:22 pm 
Offline
User avatar
.: Admin :.

Joined: Fri Nov 10, 2006 4:48 pm
Posts: 1864
Location: Naples, Italy
iTrader:
Gender: Male
Cash:1504
Reputation point: 278
ricky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant futurericky92 has a brilliant future


Giveaway Donor Award Graphics Trader Winner Award

Method 1 should work, if you add the wrapper cookies to the WebClient object. Neopets captcha needs to know you're logged in :P

_________________
Image


Top
 Profile  
 
 Post subject: Re: [VB.NET] MemoryStream to Image?
PostPosted: Tue Oct 27, 2009 9:52 pm 
Offline
User avatar
.: Newbie :.

Joined: Tue Oct 20, 2009 9:20 am
Posts: 18
iTrader:
Gender: Female
Cash:18
Reputation point: 5
JenJen is on a distinguished road
Thanks guys :)

I haven't had time since I posted this to work on the project, I am overloaded at work, doing O.T. shifts as some other coworkers are sick...

Zero - That was one thing I had pondered. I know that as long as I can get the image to either the picturebox, or as a file on the computer, I can work with it. Its worth a shot if the other methods fail.

Ricky - I havent had time to get back on my computer, but the odd thing, is that when I use the HTML visualizer for the item page whilst debugging, the wrapper loads the haggle page, and all gifs, the only things that are not visible are the captcha, and the flash ads (naturally the flash ads wont display properly).

I am not sure if its a cookie issue (with method one, it would be, as webclient current isnt passed cookies), but with the wrapper loading the haggle page, I would want to think that using the HTML visualizer, the jpg captcha should display, considering that gif images display.

THe only thing I can conclude is that perhaps the type definitions for the wrapper are incorrect for jpgs.

None the less, I did not think about passing cookies to the webclient model I used in method one. THat is something I will try. As long as I dont have to log in it would work great, as obviously constantly logging in would perk TNTs eyes.

THanks again guys, I'll see what I can come up with when I have time, and if I am still stuck, I'll advice from there.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
* FAQ

Powered by phpBB © 2000- phpBB Group
NEOPETS, characters, logos, names and all related indicia are trademarks of Neopets, Inc., © 1999-. © denotes Reg. US Pat. & TM Office. All rights reserved.
Website © neofriends.net - this site is in no way affiliated with Neopets, Inc or Viacom International, Inc.

phpBB SEO