当存储在天蓝色斑点存储中时,如何获取图像尺寸?

时间:2019-02-06 09:11:57

标签: c# azure azure-storage-blobs

我在Blob中有图像,我想读取图像尺寸(宽度和高度)

这是我从blob中读取的功能:

package com.config;


@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.*"})
@EnableTransactionManagement
public class WebConfig implements TransactionManagementConfigurer {

@Bean
public InternalResourceViewResolver jspResolver() {
  InternalResourceViewResolver viewResolver = new 
  InternalResourceViewResolver();
  viewResolver.setPrefix("/");
  viewResolver.setSuffix(".jsp");
  viewResolver.setExposeContextBeansAsAttributes(true);
  return viewResolver;
}

@Bean
public MappingJackson2JsonView jsonView(){
    MappingJackson2JsonView jsonView=new MappingJackson2JsonView();
    jsonView.setContentType("application/json;charset=UTF-8");
    return jsonView;
}

@Bean
public PooledDataSource dataSource(){
    PooledDataSource dataSource=new PooledDataSource();
    dataSource.setDriver("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong");
    dataSource.setUsername("root");
    dataSource.setPassword("fuduhui123");
    dataSource.setPoolMaximumActiveConnections(5);
    dataSource.setPoolMaximumIdleConnections(3);
    return dataSource;

}




@Bean(name = "sqlSessionFactory")
public SqlSessionFactoryBean sessionFactoryBean(){
    try{
        SqlSessionFactoryBean sessionFactoryBean=new SqlSessionFactoryBean();
        sessionFactoryBean.setDataSource(dataSource());
        Resource[] mapperLocations=new PathMatchingResourcePatternResolver().getResources("classpath:mapper/testdb/*.xml");
        sessionFactoryBean.setMapperLocations(mapperLocations);
        return sessionFactoryBean;
    }catch (Exception e){
        e.printStackTrace();
    }

    return null;
}

@Bean
public DataSourceTransactionManager transactionManager(){
    DataSourceTransactionManager transactionManager=new DataSourceTransactionManager();
    transactionManager.setDataSource(dataSource());
    return transactionManager;

}

@Bean
public MapperScannerConfigurer scannerConfigurer(){
    MapperScannerConfigurer scannerConfigurer=new MapperScannerConfigurer();
    scannerConfigurer.setBasePackage("com.dao");
    scannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
    return scannerConfigurer;
}

@Override
public PlatformTransactionManager annotationDrivenTransactionManager() {
    return transactionManager();
}

我在CloudBlobContainer和CloudBlockBlob中都看不到任何有用的元数据。

有人知道如何从blob获取图像尺寸吗?

谢谢

1 个答案:

答案 0 :(得分:5)

您无法通过blob的属性和元数据直接获取Azure存储上存在的blob的图像尺寸。唯一的方法是下载图像Blob,然后通过方法System.Drawing.Image.FromFileSystem.Drawing.Image.FromStream将其转换为System.Drawing.Image,以获得Image.WidthImage.Height

否则,您需要在上传图像时首先添加Blob的元数据来存储图像尺寸数据。然后,您无需下载即可从Blob元数据获取图像的尺寸。我建议采用这种方式,以避免下载那些大图像。