[codenameone-discussions] Re: getBytesFromImage conversion always off by one byte (source is one byte greater)
On Thursday, June 27, 2019 at 5:03:51 PM UTC-4, shop.servi...@gmail.com wrote: > > If you are experiencing an issue please mention the full platform your > issue applies to: > IDE: NetBeans/Eclipse/IDEA NetBeans 8.2 > Desktop OS Windows 10 Pro > Simulator Latest > Device PC, Android & IOS > > I am creating an Image from bytes: > Image CustomerPicture = Image.createImage(vehiclepicture, 0, > vehiclepicture.length); > A3VehiclePhotoImageViewer = new ImageViewer(CustomerPicture) > Source bytes are 303981, getBytesFromImage returns 303980 > > > public byte[] getBytesFromImage(com.codename1.ui.Image image) { > ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); > byte[] BytesFromImage = new byte[0]; > try { > if (image != null) { > ImageIO.getImageIO().save(image, outputStream, > ImageIO.FORMAT_PNG, 1f); > BytesFromImage = outputStream.toByteArray(); > } > } catch (Exception e) { > e.printStackTrace(); > MyLog.e(e); > } > return BytesFromImage; > } > > Thoughts? > > Regards > > -- You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/codenameone-discussions. To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/1a1e0adb-a1ae-4a80-b768-866f16c1e573%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[codenameone-discussions] Re: getBytesFromImage conversion always off by one byte (source is one byte greater)
Thank you very much! On Thursday, June 27, 2019 at 11:38:46 PM UTC-4, Shai Almog wrote: > > That method re-encodes a PNG which can have a different byte count than > the one in your original image. If you use EncodedImage you can use use > getData() to get the original image file. > -- You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/codenameone-discussions. To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/ac55af98-18c9-4227-841c-a262a29df72a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[codenameone-discussions] Re: getBytesFromImage conversion always off by one byte (source is one byte greater)
That method re-encodes a PNG which can have a different byte count than the one in your original image. If you use EncodedImage you can use use getData() to get the original image file. -- You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group. To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/codenameone-discussions. To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/b3f5899c-f33d-4a99-b236-fc91a3cb092b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.