Advertisement
Guest User

Untitled

a guest
Jul 25th, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. private class ConvertCMYK extends AsyncTask<Void, Void, String>
  2.     {
  3.         private String url;
  4.         private Bitmap original;
  5.         private ImageInfo info;
  6.         private MagickImage imageCMYK;
  7.         private File imageFile;
  8.         private AQuery aq;
  9.        
  10.         public ConvertCMYK(String url, Bitmap original, AQuery aq)
  11.         {
  12.             this.url = url;
  13.             this.original = original;
  14.             this.aq = aq;
  15.         }
  16.        
  17.         @Override
  18.         protected void onPreExecute()
  19.         {
  20.             aq.id(R.id.progress).visible();
  21.         }
  22.        
  23.         @Override
  24.         protected String doInBackground(Void... params)
  25.         {
  26.             try
  27.             {
  28.                 imageFile = aq.getCachedFile(url);
  29.                
  30.                 info = new ImageInfo(imageFile.getAbsolutePath());
  31.                 imageCMYK = new MagickImage(info);
  32.                
  33.                 if(imageCMYK.getColorspace() == ColorspaceType.CMYKColorspace)
  34.                 {
  35.                     boolean imgConvertStatus = imageCMYK.transformRgbImage(ColorspaceType.CMYKColorspace);                                 
  36.                        
  37.                     if(imgConvertStatus)
  38.                     {
  39.                         imageCMYK.setFileName(imageFile.getAbsolutePath());
  40.                         imageCMYK.writeImage(info);
  41.                     }
  42.                     else
  43.                     {
  44.                         throw new Exception();
  45.                     }      
  46.                 }
  47.                 else
  48.                 {
  49.                     return null;
  50.                 }
  51.             }
  52.             catch(Exception e)
  53.             {
  54.                 return null;
  55.             }
  56.            
  57.             return "Executed";
  58.         }
  59.        
  60.         @Override
  61.         protected void onPostExecute(String result)
  62.         {
  63.             if(result != null)
  64.                 aq.id(R.id.photo).image(new File(imageFile.getAbsolutePath()), 350);               
  65.             else
  66.                 aq.id(R.id.photo).image(original, 0);
  67.            
  68.             aq.id(R.id.progress).gone();
  69.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement