c# - MVC Stream Picture rotated -


i want use rotated image in mvc application. purpose worte controller returns rotated image, cant working.

this command:

public actionresult picturestreamrotate(string filename) {     image image = image.fromfile(filename);     image.rotateflip(rotatefliptype.rotate90flipnone);      memorystream stream = new memorystream();     image.save(stream, imageformat.jpeg);     return file(stream, "image/jpeg"); } 

the image streamed invalid. dies have idea. input picture jpg file.

btw. if remove thw line image.rotateflip wont work.

this happens because stream's position after written data. toarray() get's in stream start. alternatively, set position 0 or seek start of image data.

try in linqpad:

var x = new memorystream(); x.writebyte(123); x.readbyte().dump(); 

it gives -1 result...

then x.position=0;and 123 back.

btw, toarray() copies data, not want, guess.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -