How to put image (byte) in Custom Wallpaper.

Answered
0
0

Hello everyone! I’m trying to return images from the database, but I don’t know how I can put the images (which are converted to bytes) in the CustomWallpaper control. Someone can help me? Thanks!

  • You must to post comments
Great Answer
0
1

So, i just found the solution. I will post it here for those who wants to retrieve an image from the database. Also thanks for the Staff that helped me with some code!

 

Dim imagem As Byte()
Sql = “SELECT image FROM imagens WHERE user='” & LkID & “‘”
dt = SqlDataTable(Sql, LerMy)
Dim imageListEntries As ImageListEntry() = New ImageListEntry(dt.Rows.Count – 1) {}
Dim count = 0
For Each imagens In dt.Rows
imagem = dt.Rows(count)(0)
Dim ms As MemoryStream = New MemoryStream(imagem)
imageListEntries(count) = New ImageListEntry(Image.FromStream(ms))
count = count + 1
Next
Me.CustomWallpaper1.Images = imageListEntries

  • You must to post comments
0
0

Here is the result of the attached sample with a bitmap changed to use new Bitmap(Image.FromStream()). This is a common .NET drawing issue, not a Wisej issue.

Attachment
    • Guest
    • Feb 18, 2021 - 5:35 pm
    I will send my project attached, if you guys could help me please!
  • Luca
    • Luca
    • Feb 18, 2021 - 5:38 pm
    Contact us directly at support [at] wisej.com with the attachment and your license information and we’ll be happy to help you.
    • Guest
    • Feb 19, 2021 - 10:34 am
    Found the solution Luca, thanks!
  • You must to post comments
0
0

Use New Bitmap(Image.FromStream(stream)) or don’t use the same stream twice.

    • Guest
    • Feb 18, 2021 - 5:24 pm
    Hello Sir, like this? https://prnt.sc/10025xd If yes, it’s not working… :(
  • Luca
    • Luca
    • Feb 18, 2021 - 5:25 pm
    Attach a test case with an image saved to a file. I can’t help you with a screen shot. The sample we attached runs perfectly.
  • Luca
    • Luca
    • Feb 18, 2021 - 5:27 pm
    In the screenshot you are not adding the image to the wallpaper component and you are again using the stream twice. Can you use the sample we attached?
    • Guest
    • Feb 18, 2021 - 5:56 pm
    I can’t use that function totally, because im not “uploading” it, i am retrieving from the database, also im uploading a PNG. I don’t understand what do you mean by “repeating twice”, can u be more specific? Am i doing it wrong? Im getting the image, then i convert to byte and stream it.. I really need help with this…
  • Luca
    • Luca
    • Feb 18, 2021 - 5:59 pm
    Send a small test case that doesn’t use the database with your license information to support [at] wisej.com and I can try to help you as this is not a Wisej issue and we do support for Wisej. For general .NET, C# and VB.NET issues we can also help you as a courtesy as this is not a generic coding blog or support forum.
  • You must to post comments
0
0

Hi Ruben,

the code you posted cannot work as is.

  • If you are using the stream twice you need to rewind it to position 0 before the 2nd call
  • If you do that, does the image show in the picturebox?
  • If it does not show you could try with a real image file first and see if that works
  • If it does work, please store your byte array to a file and see if that shows up

Best regards
Frank

 

    • Guest
    • Feb 18, 2021 - 4:31 pm
    I will send an image, please check this out, it’s the code that im using, and i only have one image, and the picturebox shows up the image. https://prnt.sc/1001549
    • Guest
    • Feb 18, 2021 - 4:35 pm
    Look, the black background is the CustomWallpaper Control wich doesn’t load correctly, and then u can see the picturebox that loads the image sucessfully… https://prnt.sc/10017qb
  • Luca
    • Luca
    • Feb 18, 2021 - 5:16 pm
    When you use a stream the Position changes. So the second time it’s invalid since it’s a the end of stream. Second if the image is a jpg in .NET it uses interlaced rendering (which is a jpeg thing) so if you create it from a stream it keeps the stream open and when you use the stream again it moves to the end invalidating the image (if you enable logging in web,config you see the exceptions). In that case you either keep leave the stream alone (use it only once) or use this instead new Bitmap(Image.FromStream(stream)). This is a common technique when loading jpegs from a stream, So, basically, the second time you use the stream breaks the first image. If it still fails for you attach a test case with an image file that show how it fails. I just tried the sample that Frank attached and it works without issues with pngs.
    • Guest
    • Feb 18, 2021 - 5:17 pm
    So, this one is using basically your code, and the picturebox works, but not the CustomWallpaper.. Check this out, it’s more organizated. https://prnt.sc/100218q
  • Luca
    • Luca
    • Feb 18, 2021 - 5:19 pm
    It works well unless it’s a jpeg because of the issue I explained above.
0
0

Hi Ruben,

I have created a small demo application where you can upload images to a Custom Wallpaper.
It should help you to transfer the logic to your requirement.

Please let me know if you have any further questions.

Best regards
Frank

    • Guest
    • Feb 18, 2021 - 12:18 pm
    Thansk! I will try that and say something later.
    • Guest
    • Feb 18, 2021 - 2:17 pm
    tried using your method, but I’m not getting it, I’m going to get the images from a database and convert to byte and then do the Stream. I tried to use your code, but I must be doing something wrong. Could you help me? Check the code: https://pastebin.pl/view/raw/0dc9b0c3
  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.