Hoton Grayscale

Maida Hoto zuwa Baki da Fari ta amfani da Java Cloud SDK

Ana samar da Hotunan Raster kullun ta hanyar wayoyin hannu, na’urorin daukar hoto da sauransu kuma sun ƙunshi tsarin launi na RGB. Yanzu tare da launi na RBG, girman hoton yana da girma kuma a gefe guda, hoton launin toka yana matsawa hoto a matsayin daya daga cikin nau’in da darajar kowane pixel shine samfurin guda ɗaya wanda ke wakiltar adadin haske ɗaya kawai; wato yana ɗaukar bayanai masu ƙarfi ne kawai. Bugu da ƙari kuma, hoton launin toka hoto ne mai launin baki-da-fari ko launin toka mai launin toka wanda ya ƙunshi gaba ɗaya na inuwar launin toka. Bambanci ya bambanta daga baki, mafi raunin ƙarfi, zuwa fari, mafi ƙarfi. Don haka a cikin wannan labarin, za mu haɓaka mai canza hoto mai launin toka don canza bayyanar hotunan ku zuwa inuwar launin toka. Daidaita girman sautin launin toka na hoton kamar yadda ake so tare da tace launin toka don kawar da abubuwan ban sha’awa da jaddada ma’anar ƙirar ku.

API ɗin Canjin Hoto Greyscale

Muna da tushen API na REST yana ba da damar sarrafa fayil ɗin hotuna a cikin Cloud. Hakanan yana goyan bayan fasalin don canza hoto zuwa baki da fari. Don haka don haɓaka mai canza hoton Grayscale ta amfani da Java, za mu yi amfani da Aspose.Imaging Cloud SDK for Java. Baya ga jujjuya zuwa hoto mai launin toka, kuna iya canza hoton tushe zuwa wasu nau’ikan nau’ikan tsara masu tallafi. Yanzu don farawa da ayyukan juyawa, mataki na farko shine ƙara bayaninsa a cikin aikin java ta haɗa da bin bayanai a cikin pom.xml (maven build type project).

<repositories> 
    <repository>
        <id>aspose-cloud</id>
        <name>artifact.aspose-cloud-releases</name>
        <url>https://artifact.aspose.cloud/repo</url>
    </repository>   
</repositories>

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-imaging-cloud</artifactId>
        <version>22.4</version>
    </dependency>
</dependencies>

Mataki na gaba shine samun takaddun shaidar abokin ciniki daga Cloud Dashboard kuma idan baku da asusu akan Aspose Cloud Dashboard, da fatan za a ƙirƙiri asusun kyauta ta hanyar adireshin imel mai inganci. Yanzu shiga ta amfani da sabon asusun da aka ƙirƙira kuma bincika/ƙirƙiri ID na abokin ciniki da Sirrin Abokin ciniki a Aspose Cloud Dashboard.

Hoton Grayscale ta amfani da Java

Wannan sashe yana bayani dalla-dalla kan yadda ake loda hoton da ke akwai kuma a canza zuwa hoto mai launin toka. Da fatan za a bi umarnin da aka ƙayyade a ƙasa don cika abin da ake bukata.

  • Mataki na farko shine ƙirƙirar misali na ImagingApi dangane da keɓaɓɓen shaidar abokin ciniki
  • Na biyu, karanta fayil ɗin JPG tsari na gida ta amfani da abu Fayil
  • Na uku, ƙirƙiri misalin byte[] don karanta fayil ta amfani da hanyar readAllBytes(…).
  • Mataki na gaba shine ƙirƙirar misali na CreateGrayscaledImageRequest wanda ke buƙatar tsararrun Byte da sakamakon sunan hoton launin toka.
  • A ƙarshe, kira hanyar ƙirƙirarGrayscaledImage(…) don samar da hoto mai launin toka kuma ana adana fayil ɗin sakamako akan ma’aunin girgije.
// Samu ClientID da ClientSecret daga https://dashboard.aspose.cloud/
String clientId = "7ef10407-c1b7-43bd-9603-5ea9c6db83cd";
String clientSecret = "ba7cc4dc0c0478d7b508dd8ffa029845";

// haifar da Hoto abu
ImagingApi imageApi = new ImagingApi(clientSecret, clientId);

// loda fayil daga rumbun gida
File f = new File("PinClipart.png");

// karanta abun ciki na hoton PNG zuwa tsararrun byte
byte[] bytes = Files.readAllBytes(f.toPath());
					    
// ƙirƙiri buƙatun jujjuyawar Grayscale inda muka saka sunan fayil ɗin sakamako
CreateGrayscaledImageRequest request = new CreateGrayscaledImageRequest(bytes,"grayscale.jpg",null);

// Maida Hoto zuwa Baki da Fari
imageApi.createGrayscaledImage(request);
hoto mai launin toka

Maida Hoto zuwa Baki da Fari

Hoton Grayscale

Sakamakon Hoto Grayscale

Ƙirƙirar Hoton Grayscale ta amfani da Umarnin CURL

Hakanan zamu iya canza Hoto zuwa Baƙar fata da fari ta amfani da umarnin cURL. Tunda APIs ɗin mu suna samun dama ga masu amfani masu izini kawai, don haka don samun damar APIs ta amfani da umarnin cURL akan tashar layin umarni, muna buƙatar fara samar da alamar samun damar JWT (dangane da takaddun shaidar abokin ciniki) ta amfani da umarni mai zuwa.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Yanzu da muke da alamar JWT, da fatan za a kira GreyscaleImage API don samar da hoto mai launin toka. Da zarar an ƙirƙiri hoton launin toka, za a dawo da sakamakon sakamakon a rafin martani.

curl -v -X GET "https://api.aspose.cloud/v3.0/imaging/image1.jpg/grayscale" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-o "grayscale.jpg"

Kammalawa

Wannan labarin ya ba da cikakkun bayanai kan yadda za mu iya juyar da Hoto zuwa Black and White ta amfani da Java Cloud SDK. Hakazalika, mun kuma bincika zaɓi don cika abin da ake buƙata don samar da hoto mai launin toka ta amfani da umarnin cURL. Baya ga waɗannan zaɓuɓɓuka, kuna iya bincika abubuwan API cikin sauri a cikin mai binciken gidan yanar gizon ta swagger API Reference. Muna ba da shawarar sosai don bincika Takardun Samfura don ƙarin koyo game da wasu abubuwan ban sha’awa waɗanda API ɗin ke bayarwa.

Bugu da ƙari, duk Cloud SDK ɗin mu an haɓaka su ƙarƙashin lasisin MIT don haka za a iya sauke cikakkiyar lambar tushe daga GitHub. A ƙarshe, idan kun gano kowace matsala yayin amfani da API, kuna iya yin la’akari da kusantar mu don ƙuduri mai sauri ta hanyar dandalin tallafi na kyauta 9.

Labarai masu alaka

Da fatan za a ziyarci hanyoyin haɗin yanar gizon don ƙarin koyo game da: