• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding byte arrays  RSS feed

 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a set of gif images in the form of byte arrays. I want to add them into a singe byte[]. I could make an animated gif image with this byte array, using a method that I have.
I would like to know how it could be done? could some body please post a sample code?

Thanks,
Samanth.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think that multiple GIFs in a single byte[] is a valid animated GIF; in fact, I'm sure it's not.

But to combine two arrays of any type, the recipe is the same: create a new array large enough to hold all the contents, then copy each component array into the new larger array.

byte[] b1 = ...
byte[] b2 = ...
byte[] all = new byte[b1.length + b2.length];
System.arraycopy(b1, 0, all, 0, b1.length);
System.arraycopy(b2, 0, all, b1.length, b2.length);
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Earnest,

Thanks for your help. I was just trying for a solution that way. Now that you said it is wrong could you suggest me a way to do it?

Thanks,
Samanth.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well now wait, you said "I could make an animated gif image with this byte array, using a method that I have." Is this true, or not? EFH is saying that the single big byte[] array is not a valid GIF format, and that's true. But if you've got a method that makes an animated GIF out of the format you describe, that's fine. The fact that the combined array is not a valid GIF in itself doesn't mean it can't be a useful step toward getting a valid animated GIF. But I don't know if your method really works, or not.
 
Sam Venkata
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jim,
I am using Jmagick package for that. It has a method called
blobToImage() that converts a byte[] into an image I was trying to see if I could get an animated image by sending the byte[].
I was just trying to do it. That is why I asked if what I was trying to do is correct or not?
Thanks,
Samanth.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!