This project is read-only.

Convert the Byte array into JPEG Image using Image tools

Mar 19, 2012 at 9:42 AM

Hi guys,

Please guide me how to convert the Byte array(from Data Base) into JPEG Image in silverlight.

string imagebyte = "0x89504E470D0A1A0A0000000D494844520000005A0000005A08030000000F76B1300000001974455874536F6674776172650041646F626520496D616765526561647971C9653C0000036669545874584D4C3A636F6D2E61646F62652E786D7000000000003C3F787061636B657420626567696E3D22EFBBBF222069643D2257354D304D7043656869487A7265537A4E54637A6B633964223F3E203C783A786D706D65746120786D6C6E733A783D2261646F62653A6E733A6D6574612F2220783A786D70746B3D2241646F626520584D5020436F726520352E302D633036312036342E3134303934392C20323031302F31322F30372D31303A35373A30312020202020202020223E203C7264663A52444620786D6C6E733A7264663D22687474703A2F2F7777772E77332E6F72672F313939392F30322F32322D7264662D73796E7461782D6E7323223E203C7264663A4465736372697074696F6E207264663A61626F75743D222220786D6C6E733A786D704D4D3D22687474703A2F2F6E732E61646F62652E636F6D2F7861702F312E302F6D6D2F2220786D6C6E733A73745265663D22687474703A2F2F6E732E61646F62652E636F6D2F7861702F312E302F73547970652F5265736F75726365526566232220786D6C6E733A786D703D22687474703A2F2F6E732E61646F62652E636F6D2F7861702F312E302F2220786D704D4D3A4F726967696E616C446F63756D656E7449443D22786D702E6469643A30434343463638343234353445313131383141374244453646383346313930322220786D704D4D3A446F63756D656E7449443D22786D702E6469643A42323636443141363534324431314531393944464635433238453134463137352220786D704D4D3A496E7374616E636549443D22786D702E6969643A42323636443141353534324431314531393944464635433238453134463137352220786D703A43726561746F72546F6F6C3D2241646F62652050686F746F73686F70204353352E312057696E646F7773223E203C786D704D4D3A4465726976656446726F6D2073745265663A696E7374616E636549443D22786D702E6969643A3043434346363834323435344531313138314137424445364638334631393032222073745265663A646F63756D656E7449443D22786D702E6469643A3043434346363834323435344531313138314137424445364638334631393032222F3E203C2F7264663A4465736372697074696F6E3E203C2F7264663A5244463E203C2F783A786D706D6574613E203C3F787061636B657420656E643D2272223F3ED801F85E00000300504C5445008E58F6F8F60081568EC0AB43927437997700895DA8D4C300945E007C52A4C7B6C4D9CEBBCEC33E886AD7E4DD008C54BCCFC44A9D7F00925C00794E2E977361A48B2A926E00744A009064008D5600704692C1AD006D4400916189BAA684AE99D2EAE3005C30E5EBE567B298589175FEFDFD00865061A187F5F7F5178D650084499FC2B10A6C4561AE930591662D836298B9A80071482E65442858362D805F00885A72B59D46997A007E4C499C7D127952007C4BF7F9F8CBE3DA006B42008C5CE1EEE900895600824E00603300694000864BF9FCFB009059009560007B5043A38400683F00865B86B19D00925A008F6400855311734C1B977000875B4EA686008E620090587AB9A200764C8BBDA861A98F008357A9D5C348AE92C8DBD133A78900643C007F539DBFAE116E48FBF6F55DB2980083505DAD91ABCABA028A5E65AF8E2D8D6A128059408C6E86B4A00D8B626B9E840C835A0084580098634FA889006538006A404CA183008B53EFF6F300966483BBA400884E008C6000683C008C5853AA8B00794B287E5B009866218D67058D6300945D00855A009462008952EBF6F252A38500744644A88A97C5B2008A5100663DA6CEBE00915E008F6000704396B8A63A9F7E006A42B9DBCE028C61FEF8F79ABCAA008D54F2F7F4469677028F6306865C5F977C60A88C006337008F5C98B8A74DA384009060EFF5F289B8A465B08F006D3F4A9F81006A3E0785590087550083492D8866006A3C008C6202875C0B9B7800996500673F00976201673E009864009763009A66009761ECF6F2ECF7F300966101663E01673F009964009662009660009865ECF7F200966300663F4FA788008F5762AB8F02845902855A008145026B420067400168405EAA8700976057A78AFBFDFCF2EFED058358F2F2EE00653D7CA993E9F3EF08885E7FC1AD00784795B7A6516449B6D3C4C0D3C7BCDCD09CBEAC258060418F7102683F00915A07885DA5D3C0F3F2F0F2F4F29ACCBBAECFC064A78864AC8B88C2AF067B4F326F4FA5D3BFB2C9BD00673A00633B139169088B61016A4100663E008A5200673EFFFFFF3FC8E15900000BAA4944415478DAB4990D7C13F519C7632621F1A5D1A46B4848DD7CA103A7DB32562C8209AD9126A4964A6C898B3A321587539989D4CCF1BAB93451B48CB22AAEC2804E9CA8750E7BA16969DE5AC0F88A2FDB3A9DDB982F716FEE15D0EBDD9EE7F9DFA529427B6AF7DCDDFFFE2FCFF3FDFFEEB9FF5DEED3AA66A6537B527B604FA553A934947BF6A461838E348D48C370A0A552E489BD92A55369168E05B960271CEFAA660A022778388F641C9867C438DCB0C0F34B92071B60070D8D44C85541E0F7A86672BC53E79D32A1B6AAC5240869D54CDEE35D38E136C588AA05D394850BBF34A106EC460FA816740B173E3DF5331368539F06B62D05B9D66D9DB2569C505B0B79B0E16DD42DDC7ABB38FFCF93275F7D351EAC80929DB0298DC8A7C992DB64D995DCE4C8FFCC176FDFCAD0BC1BD1FD4D7D49D8D058D937524F16BA92C56360037D1FB5A67E4037125A60E84877772F5A3733ACF44A95DEEEA20A0D60B5B75B762757A9DADB1B21742325C4DDB8F519B15F4B63050E9E0707077B0607137482CA200BED2D76EA2D400B936BFBC567108D2B04D05732B42C150183779637FEF287A36C7363F9200DCA4A8B4E144D13C96849F595949022FB41B471F3D145DF78F4C622BB70C1A2A39B7726BA4F6083D299A157D1E273AFDA3C82CE6432E856AE5974CDA9D38E5D547F3D65C1F255D1022C537460C9CE90EB2B37AF22346F64E80C1BEF8132D1B6ACFD5A40CD7DE891EF16EC9187A0E7C17F2E5A8659C914D1BB333D9922F512DA428B8FD0869E9E4C2694E909F584807CCD83A2B8F792FB666D7FB660DB67FD69DE7C513CB57D777926D383DE7882900C15D4C8847A32C5AA0B68B4101CE5489E5FB256DD5049E6850D4D7D74EAEBA27849696534130A49CEA19E11C366A8C780680DA9168C9A029A065DBBDB7F23BEF6A3BB1A1AA3FBA3FB13FBB1BC138AE8144DD58279A2F8B7E58EFD32361492A9500BD144064935432F7B18D189040C2442773A8EFE517CED81272ACBE11213E09D800D8B44667F5BE05E60CF7AA23CC39C99411035B187D00F2FD3682C45E8783C11C723BAFB5E715A4959301AC20EDC13F20E7761CE0DF35EFFFBA2CA68D4154D66E3F1103881C5E372743C5E2FA1698510BA3E4E96C83A669C2A3E746EA02D140A159878C4E3D96874A766F9EC7BCA3EF0D679351A475B349A95C9E4170F414546C3D3C819BD844E3076F4F976B855B739B2724042521E8DB669EABCDE3A7FB0054E1AA8D7B5685695BB242FC92F1E8784DC21A9E67C9ADD7788FDF96C369105879DCBAF12A77FAF6A673C9BC59E2C9C13F16CDC55AE41225A1D995CD7B445B3E485578C653DA2BD5E96102F430300AED931E39038AF34980C913749C24C385A5A0057170CAAD5DE37DE7BEF8D9FAAD50D41E483F48DD1789639E319D1BBBD75567C647C75844EE2DB3899AC2C3B47FCBCBA32D4174F2661A73E575B1D905B5A02C11965EDF7DEB078F1ACC5B36E6F2F9D11544372EA5A828E28F8C6FBFAE25810BAAE05D182AF05D14DC98181BE81A44B5D2A4E7B609DE39581A464037D5A47305857E7577F30E9C6534A46DE2825DFBA61D27235A4BEC5AF2947C7012A64740AD1C1E7110D232E10182C154F3AABAAB32F098E2E17EC596DA53F180C069E68FFDDAF8E7D5FFDE5BE050007B67723C4A2FF4032DF2F3EB63B184434EF0B3EF7182484382EADBF549C7B956EE32B5077217DC0A551FBFDEA40D9E2EB8FF70B7BFD7D93D430EEF76A075C28CEE5821FB0C79EF7FB2921263FA29B5C5AD85C114257750E68B55A179983C8175D7BA29FEF735EF5A38786DC212A07E8E7004D0921748E465C5A35A2E7B4B9D84CAE818D41B55FAD9B5D72E24F83EBCFFD35B23BB50876699B2434A956FBCF64AA618F107A5D67D2C554473401B55A37A964ACCF8E69AF0660FA20C5BB5CA0FA4CB55A4DAA193AA74573190284769004AD76A013BCDC775D3BF6274D496920A00E7432C22874405D406B25347303BE0362FE356BBCCFA5A9B7815B0B8B01F46C44E32303E8D962BF19BB2311449F7416A88606CED4A50B8C2B1A6E65991B746F448036B70FD08180840E201A7A6163E8371D11304077FA7501DF3DD3C7FDCA5BA00B04749D888898417580A105934E42A319026523E888B633A00BAC3F77FC0FC85B6F73EB106D886865347EE2D874818BC4FE0E8321623018F2BA3271EE596FAEC1BA21127104DCBAF5178E8F3EE566B7CEBD86423AFAC58B743A1DA9B6E87480360319789D6E54BD9EA10D115540A708FDC59B753A77F546201BF48876BB11CD59DC3AA61A599DC6D16870DAA4086D74BBAB294642DB096D74035A4FFDF95A44FF7C7D75244FED356EA35121DA682CA0B74014A2798BD1B845DC770C9A1A1F07BDCEE81B85B68EA0C3F97CBD215FAF92D1F579B07A423FAB4CB5AFBAB63E6FC8EBF715D082C507E8FE709E4CB5EEDB80DE546DA09641EFF6197729407FF3661FA029260C68A39C1044EF6B85DEDA62742DA2D7187DBE5D8A549B7CA6AE5A4243427C3E9F1DD7B5D5E4DB22EE8DD592997D84EECAB366B5D164DAF57525AA098D16DB3B0A7D32A8A6FEBCD904E85B377535E56A6B73B5F96A9FC9D4AC047D313836A880906BDD279EECF399ECA92274AE16780CBDAB0B5A3813A21F578436996C23689389D0BCD5643A59DCBB529553E572AA350CDD509B83862A57EDB399562B42DB100D31B9957B09ED24B44D4683852534CE034797C9665BBD5D395A25A16D3627FE65C16EB3219A4437E9D7FF02D08F37D4D2453421FAB002F45B175B6C96A505B48DA13940BF8368730E76BD05D14F35E4CC66ECE832592C2B94A12DD6A510623613DA62A184345B08AD32A3856D0CDD846873AE0B9C567C5609DA8A68B38AA12D0CCD355B2C80BECCCCD09B10BD7A296BA92A6CD68F83D633D5EF00DA8368BBD54A68E8D79B87AD80BEFCF052ACEBF56644EF5080FEC9159BACD61A24E82F43B4D5CA123282369BAB7731748E265255809332B4DD7A3FA1CD80BEC50A687C1A9D56EB2D840603F497C5E9971FAE319B3B40B6B9C2625788BE1FD16812DA836F3EA79DD0D4DF11B3237A458D591FD677E83B965A9BED972A423BED076BC232FA45BB1DD1BCA7F9C5227433A277101AE0155667F3A55F50846EF6D40C03214C6867334768A7FD744087C1F4FA0A447F6E47550790116DF77894A0BF7285C7C9550D831AFDF980FED0E924D582C709E8F3813C1C0E573CCED07A9C29DCB1D4EE712A430B88C618409F6E773AB914FDE1F3A0840EB7EA2B9E42F4A5A01A27EAA8697EC979B612F475828747F430A13FF478785CD7029F46F4F070EB706BB862F5D708AD8746EBB0BEA6991794A13708437362C360883E286C102821BC40E858AC35D65A7198A1C3B1586CB8555FE3191A52865EB26109A021E64940A736F08816042105E82763088B31D567836A9C495FE35CA208FDE3EB8E0C1D990311C33154CDF33CC7544B09412B24845A9090215E09FA67D70DF14B461292E6042921070BE8F047D01B14E67A0927E51A137290E3E8EFD79C3006DAA94C35DCC662D5072123A89AE7D263A095AA1E1ABD4204CC352C903113A234D75CB16A80E24B95172646F5A88448FF2B38B1EAB0F2DB786C42D80A19F3361EE014A26985C4A4C5870F0BE53AFDA9171FAEEB22D569A65A38E1E28B414214E77AD4E24BF382F4A08F9510FE93DCC6B440EF106EECC537A4143D7AF1C1DB835EAA9F7E5D1FFF91E10A09891DF7F5F4C972CD1EF431553B15AF10A1F8F5046B2335DE6D54BEF884D12B84FE07C6A1EABB5F584956B3E2FBF8533087B556566D38B24309FAF717EC38B2E3CD0A88A878E16EF6E64BC9AFA7E92FDF44F68F6DBF15E7FEF7BCF71FA5D6A3EF6FDBB6EDBCB7C6471FFA0E38BE7F1346BD3C9DD02C21A85A9C2FDB6BA2386D7EB1CD9DA6E0DF5E45FE22DD46FC58E0052EFDF6A13346ECB4D3CE38AEB1FED3CE904E27F63DF436AA668F0CFFEE05136AEF429231D73C3C33B0C279F821830A2B05EC109871B4F3E87380C741F08482A74E9E39D330FA4A517CE1CD876E1210C6709722F0CC21E50087308E1178E9CC494C9E6AD82F55C885161F4D454049090B12248DBC2C0C2A289C3B20B0EB24454C305E1A9B89AE5E10E4371FCF15AE8A97C204F94A694E1E54430841398E5DA77405C062B3F352AF2C6F8FEA0F5FFD3FD9BFFF27C00050E3AF77F2F54FFC0000000049454E44AE426082";
            //Decoders and Encoders
            ImageTools.IO.Decoders.AddDecoder<BmpDecoder>();
            ImageTools.IO.Encoders.AddEncoder<JpegEncoder>();
            //Creating Image
          ImageTools.ExtendedImage myimage = new ImageTools.ExtendedImage();
            //String ti Byte array
            byte [] imag=(new UnicodeEncoding()).GetBytes(imagebyte.ToString());
            MemoryStream ms=new MemoryStream (imag);         
            myimage.SetSource(ms);
  
            ImageTools.IO.Jpeg.JpegEncoder en = new JpegEncoder();
           ImageTools.IO.Bmp.BmpDecoder de=new BmpDecoder ();
           de.Decode(myimage, ms);
         
           BitmapImage bitmap = new BitmapImage();
           using (MemoryStream stream = new MemoryStream())
           {
               en.Encode(myimage, stream);
               bitmap.SetSource(stream);
           }

           sourceimage.Source = bitmap;

 

Regards,

Ramya

Mar 22, 2012 at 12:37 PM

Can you give me more details? Where is the problem?

Jun 26, 2013 at 3:24 AM
Take a look of following method and sample code on image to byte array conversion in c#.net

public static byte[] GetByteArrayFromImage(REImage image, BaseEncoder enc);

REImage reImage = REFile.OpenImageFile(fileName);

byte[] bytes = REFile.GetByteArrayFromImage(reImage, new PNGEncoder());

return bytes;