2012-09-16 11 views
1

이미지 선택 도구를 사용하고 서버에서 선택한 이미지를 다운로드하는 Windows 8 프로그램이 있습니다. 서버는 base64string에서 변환 할 이미지가 필요한 API를 제공합니다. 그리고 이미지는 7Mb보다 작아야합니다. 나는 아래의 코드를 사용하고Windows 8의 Base64String

:

FileOpenPicker openPicker = new FileOpenPicker(); 
openPicker.ViewMode = PickerViewMode.Thumbnail; 
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
openPicker.FileTypeFilter.Add(".jpg"); 
openPicker.FileTypeFilter.Add(".jpeg"); 
openPicker.FileTypeFilter.Add(".png"); 
StorageFile file = await openPicker.PickSingleFileAsync(); 
if (file != null) 
{ 
    // Application now has read/write access to the picked file 
    bitmap = new BitmapImage(); 
    byte[] buf; 
    using (var stream = await file.OpenStreamForReadAsync()) 
    { 
     buf = ReadToEnd(stream); 
    } 

    using (var stream = await file.OpenAsync(FileAccessMode.Read)) 
    { 
     base64String = Convert.ToBase64String(buf); 
     bitmap.SetSource(stream); 
    } 
} 

그리고 비트 맵 서버로 이동합니다. 하지만 문제가 있습니다. 예를 들어 비트 맵 크기가 jpg 크기보다 훨씬 큽니다. 비트 맵 버전이 7Mb보다 크기 때문에 작은 jpg는 서버로 보내지 않습니다.

이미지를 비트 맵으로 변환하지 않고 base64string으로 변환 할 수 있습니까?

답변

0

이 코드에서는 이미지 (jpeg로 인코딩 됨)를 읽고 기본 64 문자열로 변환합니다. 이미지의 크기를 줄이지 않고 밑면 64의 크기를 줄일 수 없습니다.

이렇게하려면 BitmapEncoder/Decoder를 사용하고 이미지의 크기를 더 작은 크기로 조정할 수 있습니다.

감사합니다.