높이와 너비가 우세마크 크기 (바이트 길이) 를 얻을 수 없습니다.

39 m, 길이 '' 우세마크 i& 가려구. 그러나 이미지의 높이, 폭 또는 아닌 데이터 크기.

 UIImage *img = [UIImage imageNamed:@"sample.png"];
 NSData *imgData = UIImageJPEGRepresentation(img, 1.0); 
 NSLog(@"Size of Image(bytes):%d",[imgData length]);
해설 (7)
해결책

기본 데이터 '의' 우세마크 다를 수 있으므로 같은 &quot image"; 다양한 크기의 데이터를 중 하나를 가질 수 있다. 정말 '을 사용 할 수 있는' 한 '또는' 대한 '구조' 산드라타 avamer 이리마제프 그레프레센테이션 이리마게이페그레프레센테이션 내려받습니다 인컨텍스트 크기 확인 후 iqn.

해설 (2)

가이마지 속성을 사용하여 우세마크. 그럼 조합을 통해 가이마지제비츠페로 * 스이제로프 우세마크 가이마게게테이트, 여기에 몇 바이트입니다 실제 크기 있어야 합니다.

이 반환되므로 이미지 크기를, 비압축 사용하려는 경우 malloc 등의 목적으로 대비해 비드맵 조작 (알파) 와 1 픽셀 포맷을 3 바이트입니다 RGB 의 경우 4 바이트):

int height = image.size.height,
    width = image.size.width;
int bytesPerRow = 4*width;
if (bytesPerRow % 16)
    bytesPerRow = ((bytesPerRow / 16) + 1) * 16;
int dataSize = height*bytesPerRow;
해설 (1)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editInfo
{
   UIImage *image=[editInfo valueForKey:UIImagePickerControllerOriginalImage];
   NSURL *imageURL=[editInfo valueForKey:UIImagePickerControllerReferenceURL];
   __block long long realSize;

   ALAssetsLibraryAssetForURLResultBlock resultBlock=^(ALAsset *asset)
   {
      ALAssetRepresentation *representation=[asset defaultRepresentation];
      realSize=[representation size];
   };

   ALAssetsLibraryAccessFailureBlock failureBlock=^(NSError *error)
   {
      NSLog(@"%@", [error localizedDescription]);
   };

   if(imageURL)
   {
      ALAssetsLibrary *assetsLibrary=[[[ALAssetsLibrary alloc] init] autorelease];
      [assetsLibrary assetForURL:imageURL resultBlock:resultBlock failureBlock:failureBlock];
   }
}
해설 (4)

예에서는 스위프트 :

let img: UIImage? = UIImage(named: "yolo.png")
let imgData: NSData = UIImageJPEGRepresentation(img, 0)
println("Size of Image: \(imgData.length) bytes")
해설 (1)

이 중 가장 빠른 방법은 하나, 대부분의 일반 및 오류, 깨끗한 해답이야 Uiimage+memorysize 범주입니다 '에서':

#import 

- (size_t) memorySize
{
  CGImageRef image = self.CGImage;
  size_t instanceSize = class_getInstanceSize(self.class);
  size_t pixmapSize = CGImageGetHeight(image) * CGImageGetBytesPerRow(image);
  size_t totalSize = instanceSize + pixmapSize;
  return totalSize;
}

또는 그런 것이 아니라 실제 비트맵 다운로드하려는 경우에만 우세마크 인스턴스입니다 컨테이너인 다음과 같은 단순한 '는 정말

- (size_t) memorySize
{
  return CGImageGetHeight(self.CGImage) * CGImageGetBytesPerRow(self.CGImage);
}
해설 (0)

39 m, 자신의 상황에 i& 확실하지 않다. # 39, 필요한 경우 실제 바이트입니다 don& 크기, 내가 그렇게 할 것 같지는 않다. 산드라타 객체에는 이리마제프 그레프레센테이션 또는 이리마게이페그레프레센테이션 압축된 데이터를 얻기 위해 사용할 수 있는 이미지를 삭제합니다.

I think you want to get 실제 크기 압축되지 않은 이미지 (픽셀입니다 데이터). * 또는 가이마헤세 우세마크 기초형상 데이터를 로 변환해야 합니다. 이 예는 우세마크 이프리마거 로 변환 () 의 OpenCV). 방금 할당하십시오 반드시 충분한 메모리 포인터를 CGBitmapContextCreate& # 39 의 첫 번째 인수:

UIImage *image = //Your image
CGImageRef imageRef = image.CGImage;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
IplImage *iplimage = cvCreateImage(cvSize(image.size.width, image.size.height), IPL_DEPTH_8U, 4);
CGContextRef contextRef = CGBitmapContextCreate(iplimage->imageData, iplimage->width, iplimage->height,
                                                iplimage->depth, iplimage->widthStep,
                                                colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault);
CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
CGContextRelease(contextRef);
CGColorSpaceRelease(colorSpace);

IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);
cvCvtColor(iplimage, ret, CV_RGBA2BGR);
cvReleaseImage(&iplimage);
해설 (0)
  • 3:* 스위프트
let image = UIImage(named: "example.jpg")
if let data = UIImageJPEGRepresentation(image, 1.0) {
    print("Size: \(data.count) bytes")
}
해설 (0)

우리는 필요에 따라 사용할 수 있는 사람이 읽을 수 있는 형태로 [브리트카운트포매터] (https://developer.apple.com/documentation/foundation/bytecountformatter)

if let data = UIImageJPEGRepresentation(image, 1.0) {
   let fileSizeStr = ByteCountFormatter.string(fromByteCount: Int64(data.count), countStyle: ByteCountFormatter.CountStyle.memory)
   print(fileSizeStr)
}

여기서 'Int64 (데이타스카운트)' 가 필요한 어떤 숫자 형식.

해설 (0)
  • 4+* 스위프트
let imgData = image?.jpegData(compressionQuality: 1.0)
debugPrint("Size of Image: \(imgData!.count) bytes")

이미지 크기를 알아내기 위해 이 기법을 사용할 수 있습니다.

해설 (0)