0

3Gネットワ​​ークに接続しているときに画像をダウンロードする際の画像圧縮の必要性を理解していますが、画像の見栄えが非常に悪くなっています...ダウンロードした画像をキャッシュしていて、画像の品質はアクティブな接続に依存していることに気付きました。私のコード:

        KTMember *member = [[DataManager sharedManager] getMemberWithId:memberId];
    if (member) {
        NSLog(@"caching member %d locally",member.memberId);
        memberImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:member.imageUrl]]];
        [[DataManager sharedManager] saveImageToDocuments:memberImg withId:memberId];
        return memberImg;
    } else {
        return nil;
    }

したがって、問題は、アクティブなネットワークが3Gであっても、画像圧縮をオーバーライドする方法はありますか?

ありがとう

4

2 に答える 2

1

低速接続の画像圧縮を適応的に増加させるグローバルメカニズムはありません。説明する内容はサーバー上にカスタムコードを必要とし、サーバーごとに異なります。

これらの画像を提供しているサービスは何ですか?

于 2012-05-06T01:58:51.340 に答える
0

編集:私の答えを修正していただきありがとうございます、ベライゾンネットワーク最適化による画像圧縮のいくつかのメカニズムがあります。

バイトストリームの観点から見た画像の品質は、圧縮の有無をサーバーが提供するかどうかに依存すると思います。

しかし、いくつかの解決策があります。NSURLConnectionDataDelegateスレッドプログラミングを使用して、URLリクエストからのデータを処理するように実装することもできます。面白い方法があります:

/** connection:didReceiveResponse: is called when
 *               enough data has been read to construct an
 *               NSURLResponse object. In the event of a protocol
 *               which may return multiple responses (such as HTTP
 *               multipart/x-mixed-replace) the delegate should be
 *               prepared to inspect the new response and make
 *               itself ready for data callbacks as appropriate.
 **/

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

/** connection:didReceiveData: is called with a single
  *              immutable NSData object to the delegate,
  *              representing the next portion of the data loaded
  *              from the connection.  This is the only guaranteed
  *              for the delegate to receive the data from the
  *              resource load
  **/

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

/** connection:willCacheResponse: gives the delegate
  *              an opportunity to inspect and modify the
  *              NSCachedURLResponse which will be cached by the
  *              loader if caching is enabled for the original
  *              NSURLRequest.  Returning nil from this delegate
  *              will prevent the resource from being cached.  Note
  *              that the -data method of the cached response may
  *              return an autoreleased in-memory copy of the true
  *              data, and should not be used as an alternative to
  *              receiving and accumulating the data through
  *              connection:didReceiveData
  **/

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse;

/** connectionDidFinishLoading: is called when all
  *              connection processing has completed successfully,
  *              before the delegate is released by the
  *              connection
  **/

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;

didReceiveDataまた、各受信データを蓄積してデータを管理することもできます。ダウンロードが完了connectionDidFinishLoadingすると、NSDataで、すべてを受信した画像を処理できます。

お役に立てば幸いです。

于 2012-05-06T02:20:49.817 に答える