c# - When updating an image, binary data seams to be truncated -
i'm @ wit's end here trying figure out i'm doing wrong. goal rotate image 90 degrees , save changed total image file scheme , update thumbnail version in database. file scheme image changed appropriately when image saved database seams first 28 characters saved. sql reports no errors.
any ideas on i've done wrong here much appreciated. in advance.
image image = image.fromfile(image_path); image.rotateflip(rotatefliptype.rotate90flipnone); image.save(image_path, system.drawing.imaging.imageformat.jpeg); byte[] thumbnail = null; system.drawing.image thumb = image.getthumbnailimage(72, 47, () => false, intptr.zero); thumbnail = imagetobytearray(thumb); image.dispose(); string conn = configurationmanager.connectionstrings["my_database"].connectionstring; sqlconnection sqlconn = new sqlconnection(conn); sqlcommand sqlcomm = new sqlcommand(); sqlcomm = sqlconn.createcommand(); sqlcomm.commandtext = @"update my_table set pic='@thumbnail' pic_id= cast(@pic_id int) "; sqlcomm.parameters.add("@thumbnail", sqldbtype.image, thumbnail.length).value = thumbnail; sqlcomm.parameters.add("@pic_id", sqldbtype.int); sqlcomm.parameters["@pic_id"].value = convert.toint32(pic_id); seek { sqlconn.open(); int32 rowsaffected = sqlcomm.executenonquery(); context.response.write("rowsaffected:" + rowsaffected + "<br/>"); } grab (exception ex) { context.response.write(ex.message); } //sqlconn.open(); //sqlcomm.executenonquery(); sqlconn.close(); context.response.binarywrite(thumbnail);
my_table set pic='@thumbnail'
looks suspicious, why quotes?
at guess, i'd overwriting header in bitmap, whatever bit pattern string "@thumbnail" equates corresponds setting length of "28" in header.
http://en.wikipedia.org/wiki/bmp_file_format
c# sql-server-2008-r2
No comments:
Post a Comment